?
Solved

Object reference not set to an instance of an object

Posted on 2007-03-25
4
Medium Priority
?
217 Views
Last Modified: 2010-04-23
Hi,
Can anyone help me with this? I am getting this error in the line indicated below.  (this is VB.NET 2003)
If I step through the code (using F11 key) the value of IsItSensor is TRUE when I enter the Sub. Also, the variable AinIsSensor(ix%) is Public Dim AinIsSensor() as Boolean. If I comment out this line I don't get the error and the rest of the code executes correctly. (I have only pasted a portion of this sub to save space).

Any Ideas?

Thanks,
Charlie


 Sub AinDefXX(ByVal ix%, ByVal ScanOrder%, ByVal ChassisNum%, ByVal SlotNum%, ByVal chan%, ByVal UnB%, _
    ByVal PhyTyp%, ByVal RngeTyp%, ByVal id$, ByVal aNam$, ByVal LimLo!, ByVal LimHi!, ByVal Group%, _
    ByVal loMeas!, ByVal loReal!, ByVal medMeas!, ByVal medReal!, ByVal hiMeas!, ByVal hiReal!, _
    ByVal OrderNum%, ByVal Nameshort$, ByVal IsItSensor As Boolean)

        Dim j%, K%, msg$, x%
        AinChanNum(ix%) = chan%
        AinSlotNum(ix%) = SlotNum%
        AinChassisNum(ix%) = ChassisNum%
        AinScanOrder(ix%) = ScanOrder%
        AinIsSensor(ix%) = IsItSensor     ' <- The Error Occurs When Executing this Line
        AinUnitBase%(ix%) = UnB%
        AinPhysTyp%(ix%) = PhyTyp%
        AinRngeTyp%(ix%) = RngeTyp%

0
Comment
Question by:charlieb01
  • 2
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 18789805
This line

   Public Dim AinIsSensor() as Boolean

DECLARES a Boolean array, but it does not DIMENSION it.  So when you refer to a specific element - element iX% - in that array with the line

        AinIsSensor(ix%) = IsItSensor     ' <- The Error Occurs When Executing this Line

there is no element at that position to which the IsItSensor value can be ascribed.  The array is empty.

How and where do you dimension the other arrays this code is using?  I ask because, as none of the earlier ones are throwing errors, I assume you must have given those dimensions.  Can you use the same approach for this one?

Roger
0
 

Author Comment

by:charlieb01
ID: 18789846
Roger,

This is the way it was:
Public AinScanOrder%()
Public AinIsSensor() As Boolean

I changed it to this:
Public AinScanOrder%()
Public AinIsSensor(200) As Boolean  ' CRB - TRY USING A DIM OF 200 HERE (INSTEAD OF NOTHING)

That solved the problem but I don't understand why this error only occur with the Boolean and not the other variables. For example, AinScanOrder% is declared just as shown above and I don't get this error. I stepped through this until the value of ix% was 12 and still no error.

I would like to understand this better so if you could provide some insight it would be helpful.

Thanks,
Charlie
0
 

Author Comment

by:charlieb01
ID: 18790483
Roger,

I found it. I am trying to rebuild a program with several thousand pages of code that was written by about 10 other people. After some searching I discovered that the Vars are being Redimensioned elsewhere in the code based upon a recordset count.

Thanks for the help.
Charlie
0
 
LVL 34

Expert Comment

by:Sancler
ID: 18791315
Charlie

Thanks for the points.  And for letting me know of the redimensioning.  I must admit, on reading your earlier reply, that I was wondering whether there was a quirk about array declarations with type-suffixes that had escaped me.

Roger
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question