【发布时间】:2014-03-04 13:05:24
【问题描述】:
请问如何从动态创建的文本框中检索值?
这是我的程序应该如何工作的。
程序会询问用户应该创建多少个文本框。创建后,用户将向这些文本框(突发时间文本框)输入值。然后,当单击按钮时,将从这些文本框中获取值,这些值将用于计算等待时间和周转时间,分别显示在文本框的等待时间和周转时间文本框中。
我正在使用先到先服务算法。请帮帮我。
这是我的代码: 公共类Form6
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
提前致谢!
【问题讨论】:
-
使用文本框名检索值
-
在 Process 方法之外尝试
Dim burstbox(15) As TextBox,而不是Private burstbox() As TextBox。如果您为每个文本框数组执行此操作,您将能够从其他方法访问它们。 -
怎么样?请进一步解释。 :(
标签: vb.net