我创建了一个表单,希望它能够控制课程注册过程。
所以我的代码如下
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim InpName As String
For i = 1 To 4
InpName = InputBox("What course do you want to register")
If InpName = "computer literacy" Then
TextBox1.Text = InpName
ElseIf InpName = "engineering" Then
TextBox1.Text = InpName
Else
MsgBox("We only offer computer literacy and engineering")
End If
Next i
我希望循环接受计算机知识或工程4次,并告诉用户计算机知识课程或工程课程已满。
答案 0 :(得分:0)
希望这有帮助
Dim i As Integer
Dim InpName As String
Dim engineering As Integer = 0
Dim compLit As Integer = 0
For i = 1 To 4
InpName = InputBox("What course do you want to register")
If InpName = "computer literacy" Then
compLit = compLit + 1
TextBox1.Text = InpName
ElseIf InpName = "engineering" Then
engineering = engineering + 1
TextBox1.Text = InpName
Else
MsgBox("We only offer computer literacy and engineering")
End If
If compLit = 4 Then
MsgBox("Computer Literacy is full!")
ElseIf engineering = 4 Then
MsgBox("Engineering is full!")
End If
Next
我想补充说明这里发生的事情。创建两个变量engineering和compLit,并在按钮单击时给出0值。循环发生,每次正确输入其中一个值时,这些变量递增1.在每个循环结束时,检查值是否为4,并显示相关消息。如果其中任何一个不是4,那么因为类未满而没有消息。