If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > I am really struggling with this!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-08-04, 13:08
peto813 peto813 is offline
Registered User
 
Join Date: Jun 2004
Posts: 31
I am really struggling with this!

I have the following code in VB express 2005:
Controls("giro" & i).Visible = False
It compiles ok, but whenever I try to execute the command I get the following error:

Nullreferenceexception was unhandled-object reference not set to an instance for an object. HELP!

Regards
Reply With Quote
  #2 (permalink)  
Old 08-11-04, 09:34
Marvels Marvels is offline
Registered User
 
Join Date: Jul 2003
Location: Amsterdam, Nederland
Posts: 449
Seems like you have a form with more text or labels that are named giro and a number stuck to it so : giro0;giro1;giro2;giro3;giro4 ect


so if the form is loaded it will set all the labels /text to hide (not visible)

Set a breakpoint where the code starts with F9 (this will set a redline in your code) if you now run your code it will stop at that line
now press F8 to navigate line for line through your code and you will see what it does

TIP : if its stop on the line where there is an i , put your mousepointer over it and you'll see its value
see where your error is generated
maybe label giro4 is deleted on the form and it will give you this error
Reply With Quote
  #3 (permalink)  
Old 08-23-04, 20:11
AceOmega AceOmega is offline
Registered User
 
Join Date: Apr 2004
Location: Arizona
Posts: 49
Look like you command is inside a loop

Look like you command is inside a loop which is counting for more times than you have objects for. Check you for loop, you may have to put a -1 on then end because counting functions are some times 0 based so if you have object0..object9 the count will return 10 and if you do for i = 0 to count then you will get an error because there is no object10.
Reply With Quote
  #4 (permalink)  
Old 08-23-04, 21:07
sundialsvcs sundialsvcs is offline
Registered User
 
Join Date: Oct 2003
Posts: 706
To put it another way, your code will only work if, for any 'i', there exists a control by the name generated by the expression, ("Giro" & i).

If this expression does not produce the string-value you expect, or no such object exists... then the statement has no choice but to raise a runtime exception and it may not be a terribly readable one. In this case it definitely isn't.

What I usually do in setting-up such code is to deliberately simplify the statement into several. I might deliberately set a temporary variable to the Controls() entry in the first statement, then use the variable to reference the control in the next statement. I deliberately use two statements to do the work of one. Why? Because it produces better error-messages.

The language is going to compile or at least semi-compile the statements into more-or-less the same executable code no matter how (within reason...) I write it. Computers are so darned fast that a little "inefficiency" won't be noticed. But it might make the program considerably easier to debug, or to extend in the future.
__________________
ChimneySweep(R): fast, automatic
table repair at a click of the
mouse! http://www.sundialservices.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On