循环数组中的NullReferenceException

时间:2014-05-14 01:20:46

标签: arrays vb.net nullreferenceexception

我使用循环数组得到Null Reference错误。我相信我需要创建一个新实例,但无法弄清楚语法。

这是公开声明:

Public fbInitial() As Double
Public bmInitial() As Double
Public dpInitial() As Double

以下是抛出Null错误的代码:

' Calculate initial values and write text file header
If x = 1 Then
    fbInitial(source) = FormatNumber(detPwrAvg / backMonAvg, 6)     'Sets initial SLD Front/Back ratio on first sample                    
    bmInitial(source) = FormatNumber(backMonAvg, 6)                 'Sets initial Back Monitor on first sample    
    dpInitial(source) = FormatNumber(detPwrAvg, 6)                  'Sets initial Detector Power on first sample    
    file.WriteLine("Sample;Intentionally Blank;Chamber Temp;Intentionally Blank;Back Monitor (uA);Laser Drive (mA);Intentionally Blank;Detector Power (uW);Fwd/Back Ratio;Normalized F/B Ratio;Normalized Back Monitor;Normalized Fwd Power")
End If

1 个答案:

答案 0 :(得分:0)

这意味着您需要指定变量数组的大小,如:

Public fbInitial(1000000) As Double
Public bmInitial(1000000) As Double
Public dpInitial(1000000) As Double