-2

我被困在关于简单航空公司预订的问题上。

  • 10个文本框被添加到表单上
  • 1-5 文本框仅适用于吸烟区
  • 6-10 文本框仅限非吸烟区。

扭曲是通过使用输入框输入用户输入 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 
4

1 回答 1

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

祝项目顺利。

于 2013-10-06T10:09:42.753 回答