我在简单航空公司预订方面遇到了问题。
扭曲是使用输入框输入用户输入1作为吸烟者,2输入非吸烟者。
如果用户输入1,则座位文本框必须由计算机随机放置而不是由用户设置(文本框1-5),同样适用于非吸烟者。
我们的老师给出了关于文本框制作数组的提示,但看起来对于该工作的方式真的毫无头绪。
基本上是座位储备。
在此代码中不确定我需要添加什么。
Dim reserve() As TextBox = {smokingtxt1, smokingtxt2, smokingtxt3, smokingtxt4, smokingtxt5}
Dim reserve1() As TextBox = {nonsmokingtxt1, nonsmokingtxt2, nonsmokingtxt3, nonsmokingtxt4, nonsmokingtxt5}
Dim notification As Integer
notification = InputBox("Enter 1 or 2")
If notification = 1 Then
For Each i As TextBox In reserve
i.Text = "Reserve"
Next
ElseIf notification = 2 Then
For Each j As TextBox In reserve1
Randomize()
Next
Else
MessageBox.Show("Invalid operation")
End If
答案 0 :(得分:0)
在VB6中,您曾经能够在表单上创建一组控件。这在VB.NET中是不可能的(例如Visual Studio 2010。)
您可以通过向表单添加10个文本框然后使用以下代码来实现您的工作:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim notification As Integer
notification = InputBox("Enter 1 or 2")
Dim RandomInt As Integer
If notification = 1 Then
If Textbox1.Text = "RESERVED" And Textbox2.Text = "RESERVED" Then
Msgbox "All seats are reserved"
Exit Sub
End If
TryAgain:
RandomInt = GetRandomInt(1, 5)
Select Case RandomInt
Case 1
'Check if the current textbox is already reserved
If TextBox1.Text = "RESERVED" Then
'Get a new number
Goto TryAgain
End If
TextBox1.Text = "RESERVED"
Case 2
TextBox2.Text = "RESERVED"
'etc
End Select
ElseIf notification = 2 Then
RandomInt = GetRandomInt(6, 10)
Select RandomInt
Case 5
TextBox5.Text = "RESERVED"
Case 6
TextBox6.Text = "RESERVED"
'etc
End Select
Else
MsgBox("You entered an invalid number")
End If
End Sub
Public Function GetRandomInt(ByVal StartNum As Integer, ByVal EndNum As Integer) As Integer
Dim RandomClass As New Random()
Dim RandomNumber As Integer
RandomNumber = RandomClass.Next(StartNum, EndNum)
GetRandomInt = RandomNumber
End Function
祝你好运。