Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Avoid common pitfalls of incorporating spreadsheets into Java apps. Read about it in the free white paper: “Five Biggest Blunders when Building Spreadsheet Applications in JavaDownload Now!
  #1  
Old June 17th, 2003, 02:53 PM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 4 m 10 sec
Reputation Power: 75
subroutine causes unexpected delection of fields

Hi all,
Here's the situaiton: I am writing a program that uses an adodc connection to a database to fill the fields in a form. these fields can then be edited, with the changes of course being saved automatically when you advance to the next record. This works fine. The problem lies in one of the subroutines I wrote to trim the whitespace off the fields when they are brought in from the ms sql database (which is why the whitespace is there). Since you can't use "Trim" on a null field, I wrote the following code:
Quote:
Private Sub loadTrim()
Adodc2.Recordset.Fields("comments") = varComments
Adodc2.Recordset.Fields("location") = varLocation
If IsNull(varComments) Then
Text14.Text = Adodc2.Recordset.Fields("comments")
Else: Text14.Text = Trim(Adodc2.Recordset.Fields("comments"))
End If

If IsNull(varLocation) Then
Text13.Text = Adodc2.Recordset.Fields("location")
Else: Text13.Text = Trim(Adodc2.Recordset.Fields("location"))
End If
End Sub

The object is to trim whitespace from fields that have it, and just leave the blank fields for those that are empty. However, when this runs, it clears the entries from the location and comments fields as it goes. There are no syntax errors or anything that gives me a messge, and (sadly), I'm the best there is at this place, so I can't ask anyone for help. Can someone please tell me why this is happening? Thanks in advance

Edit:
I changed the code to
Quote:
Private Sub loadTrim()
Dim varComments
Dim varLocation

varComments = Adodc2.Recordset.Fields("comments")
varLocation = Adodc2.Recordset.Fields("location")
If IsNull(varComments) Then
Text14.Text = Adodc2.Recordset.Fields("comments")
Else: Text14.Text = Trim(Adodc2.Recordset.Fields("comments"))
End If

If IsNull(varLocation) Then
Text13.Text = Adodc2.Recordset.Fields("location")
Else: Text13.Text = Trim(Adodc2.Recordset.Fields("location"))
End If
End Sub

which might keep the location field from being deleted, but it now gives me 'Runtime Error 94, Invalid Use of 'Null' ', which is the message I was trying to avoid in the first place, and which I did not get with the old code. I do not get the error when I progress forward through the previously deleted records, but I do get it when I get to the next null field, or if I try to go back once I reach the field just before the null field with causes the error also. (does that make sense)?
I'm now probably more confused, so I'm going to wait to hear a suggestion before continuing, if possible

Last edited by karsh44 : June 17th, 2003 at 03:12 PM.

Reply With Quote
  #2  
Old June 17th, 2003, 08:08 PM
mohecan mohecan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Melbourne, Australia
Posts: 212 mohecan User rank is Private First Class (20 - 50 Reputation Level)mohecan User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Rather than using NULL, you could try using IsEmpty, or testing the String length.
If the string length is 0 or the field is empty, then you have a null field.
I've struck problems with the null value.

HTH
__________________
How can I soar like an eagle when
I'm flying with turkey's?

Reply With Quote
  #3  
Old June 18th, 2003, 09:31 AM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 4 m 10 sec
Reputation Power: 75
I tried changing "isNull" to "isEmpty" in both versions of my original code, with the same results as before. Version 1 gives no errors but deletes the fields, version 2 deletes the fields that have already been deleted if additions are made to them (that is, strings that are empty, no null), but gives the "Invalid use of null" error message when it encountes the first null field.
I also tried doing "LenB(varComments)=0" instead of isNull or isEmpty, in both versions of the code, with the same results as before. Any other ideas?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > subroutine causes unexpected delection of fields


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway