0
Public Enum eSourceMode
    AUS = 0 
    EIN = 1 
End Enum


Public Structure tSourceChannel

    Dim OnOff() As eSourceMode
    Dim chan_nr As Short 

End Structure

我正在尝试将值设置为

        For i = gSources.GetLowerBound(0) To gSources.GetUpperBound(0) Step 1
        gSources(i).chan_nr = i
        'gSources is 0 based ?
        If gSources.GetLowerBound(0) = 0 Then
            k = i + 1
        Else
            k = i
        End If

        Dim hehe As Integer = gSources.Count

        For j = gNoiseBands.GetLowerBound(0) To gNoiseBands.GetUpperBound(0) Step 1
            'ab 17.1.2012: gNrSources sets nr of available outputs
            If k <= gNrSources Then
                gSources(i).OnOff(j) = eSourceMode.EIN
            Else
                gSources(i).OnOff(j) = eSourceMode.AUS
            End If
        Next j
    Next i

结果是异常

System.NullReferenceException 发生

你调用的对象是空的。

我需要这个,因为我有 .ini 文件和这些值:

"gSources0",1,0,1,1,1,1,1
"gSources1",1,1,1,1,1,1,1
"gSources2",1,1,1,1,1,1,1
"gSources3",1,1,1,1,1,1,1

的结果应该是一个例子:

 gSources(0).OnOff(0) = 1 , gSources(0).OnOff(1) = 0
4

1 回答 1

0

在这里你声明这OnOff是一个数组

Dim OnOff() As eSourceMode

但是您永远不会定义数组的大小或为数组分配内存。

'...
Dim hehe As Integer = gSources.Count
'Specify array size
Redim gSources(i).OnOff(gNoiseBands.GetUpperBound(0) -  gNoiseBands.GetLowerBound(0))
For j = gNoiseBands.GetLowerBound(0) To gNoiseBands.GetUpperBound(0) Step 1
    '...
Next j
于 2013-09-25T16:51:00.640 回答