我需要帮助将值关联到记录结构内的数组

时间:2019-04-06 20:28:29

标签: arrays vb.net structure record

我需要帮助为agent(x).operation_cost(I)分配值。

当我尝试使用一个代理进行任意数量的以下代码时,代码将运行并且值存储在agent(1).operation_cost(i)中,但是如果尝试使用多个代理,则当我输入代码时,代码将停止运行第一代理和第一操作的费用。

Private Agent() As operationData
Private nAgents As Integer
Private nOperations As Integer


Private Structure operationData
    Public codename As String
    Public Operation_cost() As Integer
End Structure


Private Sub BtnInitialize_Click(sender As Object, e As EventArgs) Handles BtnInitialize.Click

    nAgents = CInt(InputBox("Enter Number Of Agents"))
    ReDim Agent(nAgents)

    Dim x As Integer
    Dim i As Integer

    For x = 1 To nAgents

        nOperations = CInt(InputBox("How many operations were assigned to agent " & x " ? "))

    Next x

   For x = 1 To nAgents

        For i = 1 To nOperations
            Agent(x).Operation_cost(i) = CInt(InputBox("cost"))
        Next i
    Next x

End Sub

如果我输入一个代理,则msgbox将显示操作费用, 但是如果我输入多个代理,则会出现

错误
  

System.NullReferenceException:'对象引用未设置为对象的实例。'

0 个答案:

没有答案