如何从inputbox添加数字?

时间:2015-05-16 01:10:27

标签: vb.net winforms for-loop textbox

这是我的代码:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    InputBox("Enter Amount Of Courses")
    InputBox("Enter Course Name")
    InputBox("Enter Course Price")
End Sub

我怎么能重复

InputBox("Enter Course Name")   
InputBox("Enter Course Price")

代码的次数

InputBox("Enter Amount Of Courses")

告诉我?然后我想一起添加课程价格以获得总金额,然后在文本框中显示总数?我还想在另一个文本框中显示课程名称和课程价格。

2 个答案:

答案 0 :(得分:0)

Dim num As Integer = InputBox("Enter Amount Of Courses")

    Do While num > 0
        InputBox("Enter Course Name")
        InputBox("Enter Course Price")
        num = num - 1
    Loop

这应该这样做。 :)

答案 1 :(得分:0)

在变量中保存多少次,并使用For Next循环询问其他值

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim amountValue As String = InputBox("Enter Amount Of Courses")
    Dim amountOfCources As Int32
    If Int32.TryParse(amountValue, amountOfCources) = True Then
        For i As Int32 = 1 to amountOfCources
            InputBox("Enter Course Name")
            InputBox("Enter Course Price")
        Next
    End

End Sub