Object reference not set to an instance of an object

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%

charlieb01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SanclerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
charlieb01Author Commented:
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
charlieb01Author Commented:
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
SanclerCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.