将值传递给另一种在第二时间不起作用的表格

时间:2019-04-29 15:32:21

标签: vb.net winforms

我正在使用Login_Form开发Visual Basic。我想将值从Login_Form传递到TableSelection。它第一次起作用,但是当我注销并再次登录时。 TableSelection的值与我第一次通过时相同。

这是我的代码: idNumberTableSelection

中的公共变量
Private Sub LoginButton_Click(sender As Object, e As EventArgs) Handles LoginButton.Click
   Select Case EmployeeIDTextBox.Text.Substring(0, 1)
      Case 1
          MainScreen.Show()
      'Number starts with 2 takes user to waiter screen
      Case 2
          TableSelection.idNumber = EmployeeIDTextBox.Text.Substring(1, 1)
          TableSelection.Show()
   End Select
   Me.Hide()
End Sub

登录名可以使用不同的EmployeeID,但TableSelection不会更新ID

1 个答案:

答案 0 :(得分:1)

一种方法是将整数从Form1传递到Form2中,如下所示:

Public Class Form1
  Dim IntFromForm1 As Integer = 2

  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Using Form2 As New Form2(IntFromForm1)
      Form2.ShowDialog()
    End Using
  End Sub
End Class

Public Class Form2
  Dim MyForm2Int As Integer

  Public Sub New(ByVal MyIntFromForm1 As Integer)
    InitializeComponent()
    MyForm2Int = MyIntFromForm1
  End Sub

  Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    MsgBox(MyForm2Int)
  End Sub
End Class