我在Visual Basic中编写了一个代码。它有效,但我希望能够选择DOS命令运行的次数。
{{1}}
所以我有一个名为" TextBox3"的TextBox。我希望能够从1-100中选择,命令将运行多少次。
答案 0 :(得分:2)
通过这种方式,您可以在Textbox3
中输入一个数字,命令将运行那么长时间
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim command As String
For i=0 To CInt(Me.Textbox3.Text)
command = "ping " + "-l " + TextBox2.Text + " /t " + TextBox1.Text
Shell("cmd.exe /k" & command, 0)
Next
End Sub
答案 1 :(得分:0)
在子外部声明一个变量: -
Dim cmdRunCount As Integer =0
然后编辑你的子看起来像这样。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim command As String
command = "ping " + "-l " + TextBox2.Text + " /t " + TextBox1.Text
If cmdRunCount < 10 Then
Shell("cmd.exe /k" & command, 0)
cmdRuncount += 1
End If
End Sub