-1

I'm setting an array called aryRowOne() to {1, 6, 10, 15, 17, 22, 11} and when I try to use aryRowOne(1) it gives me back a NullReferenceException.

Firstly I tried having message boxes displaying values to show at what point it was broken and it made the problem make less sense. Right after the variable is given the value 6 it shows a message box that shows 6. Then it immediately crashes saying it has no value.

This is on the "Variables.vb" code file in the SetVars() sub

aryRowOne = {1, 6, 10, 15, 17, 22, 11}

which gives it a value.

Then it runs this

MessageBox.Show("aryRowOne(1) = " & aryRowOne(1))

Then on the "Debug.vb" form the CreateLog() sub is run when the user clicks a button. It shows a message box with this in it

MessageBox.Show("CreateLog() is running!")

to show it is running.

It Crashes when you reach this line

MessageBox.Show("aryRowOne(1) = " & VariablesTable.aryRowOne(1))

with...

System.NullReferenceException: 'Object reference not set to an instance of an object.'

VariablesTable.aryRowOne was Nothing.

It should have just not crashed. I'm writing it to a text file but it will not let me use the variable saying it is nothing.

Thanks to anyone who helps. This has stumped me for days.

David
  • 5,877
  • 3
  • 23
  • 40

1 Answers1

0

The error message tells you everything: VariablesTable.aryRowOne is not initialized. Maybe you have two variables with the same name in different scopes without realizing it? Do you have Option Explicit On? It also helps to step through with the debugger and have a look when this variable is set / cleared.

Christoph
  • 3,322
  • 2
  • 19
  • 28