Vb.net 如何从VB中动态创建的文本框中检索值?

Vb.net 如何从VB中动态创建的文本框中检索值?,vb.net,Vb.net,请问如何从动态创建的文本框中检索值 下面是我的程序应该如何工作 程序将询问用户应该创建多少个文本框。创建后,用户将向这些文本框(突发时间文本框)输入值。然后,当单击按钮时,将从这些文本框中获取值,这些值将用于计算等待时间和周转时间,这将分别显示在文本框等待时间和周转时间文本框中 我正在使用先到先得算法。请帮帮我 这是我的代码: 公开课表格6 Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventA

请问如何从动态创建的文本框中检索值

下面是我的程序应该如何工作

程序将询问用户应该创建多少个文本框。创建后,用户将向这些文本框(突发时间文本框)输入值。然后,当单击按钮时,将从这些文本框中获取值,这些值将用于计算等待时间和周转时间,这将分别显示在文本框等待时间和周转时间文本框中

我正在使用先到先得算法。请帮帮我

这是我的代码: 公开课表格6

Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Public Sub Process_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    'creates burst time textboxes

    GroupBox3.Visible = True
    Button1.Visible = True
    Dim cnt As Integer
    Dim burstbox(15) As TextBox
    For cnt = 0 To Val(TextBox1.Text) - 1

        burstbox(cnt) = New TextBox
        With burstbox(cnt)
            .Parent = Me
            .Left = 0
            .Height = 13
            .Width = 80
            .Top = .Height * cnt + 50
            .Visible = True
            .Tag = cnt
            .Text = ""
            .Name = "burst" & cnt
            .Location = New Point(90, 170 + (cnt * 25))

        End With
    Next cnt

    'creates waiting time textboxes
    Dim cnt2 As Integer
    Dim waitbox(15) As TextBox
    For cnt2 = 0 To Val(TextBox1.Text) - 1

        waitbox(cnt2) = New TextBox
        With waitbox(cnt2)
            .Parent = Me
            .Left = 0
            .Height = 13
            .Width = 80
            .Top = .Height * cnt2 + 50
            .Visible = True
            .Tag = cnt2
            .Text = ""
            .Name = "wait" & cnt2
            .Location = New Point(200, 170 + (cnt2 * 25))
            .ReadOnly = True
        End With
    Next cnt2

    'creates turnaround time textboxes
    Dim cnt3 As Integer
    Dim turnaroundbox(15) As TextBox
    For cnt3 = 0 To Val(TextBox1.Text) - 1

        turnaroundbox(cnt3) = New TextBox
        With turnaroundbox(cnt3)
            .Parent = Me
            .Left = 0
            .Height = 13
            .Width = 80
            .Top = .Height * cnt3 + 50
            .Visible = True
            .Tag = cnt3
            .Text = ""
            .Name = "turn" & cnt3
            .Location = New Point(310, 170 + (cnt3 * 25))
            .ReadOnly = True
        End With
    Next cnt3

    'process labels here
    Dim cnt4 As Integer
    Dim processlabel(15) As Label
    For cnt4 = 0 To Val(TextBox1.Text) - 1

        processlabel(cnt4) = New Label
        With processlabel(cnt4)
            .Parent = Me
            .Left = 0
            .Height = 13
            .Width = 80
            .Top = .Height * cnt4 + 50
            .Visible = True
            .Tag = cnt4
            .Text = "P" & cnt4 + 1
            .Name = "label" & cnt4
            .Location = New Point(30, 170 + (cnt4 * 25))
            .ForeColor = Color.DodgerBlue

        End With
    Next cnt4

End Sub

提前谢谢

如果创建这些控件并将其分配给本地数组,则只能(稍后)通过form.controls访问它们。最好将它们存储在模块化(表单级全局)变量中。请尝试以下代码:

Private burstbox As New List(of TextBox)

Public Sub Process_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
   'creates burst time textboxes

   GroupBox3.Visible = True
   Button1.Visible = True
   Dim cnt As Integer
   For cnt = 0 To Val(TextBox1.Text) - 1

       burstbox.add(New TextBox)
       With burstbox(cnt)
          .Parent = Me
          .Left = 0
          .Height = 13
          .Width = 80
          .Top = .Height * cnt + 50
          .Visible = True
          .Tag = cnt
          .Text = ""
          .Name = "burst" & cnt
          .Location = New Point(90, 170 + (cnt * 25))
       End With
   Next cnt

  'etc

结束Sub

使用textboxname作为检索值,而不是使用
Dim burstbox(15)作为TextBox
,尝试在处理方法之外使用
Private burstbox()作为TextBox
。如果对每个文本框数组执行此操作,则可以从其他方法访问它们。如何访问?请进一步解释(先生!还有一件事。现在我可以访问文本框的值了,我很难给其他文本框赋值。基本上,代码应该是这样的:BurstTime P1:1P2:2P3:3P4:4P5:5 | WaitingTime:P1:0P2:1P3:3P4:6P5:10..等待时间(P1)应该从0开始,下一个将是waitingtime(P2)=waitingtime(P1)+burstime(P1)…等等。请帮助我,先生。