?
Solved

Object reference not set to an instance of an object

Posted on 2007-03-25
4
Medium Priority
?
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 2 hours left to enroll

764 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