Solved

Object reference not set to an instance of an object

Posted on 2007-03-25
4
208 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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now