您好,我使用的是 Visual Basic,错误提示为“从字符串 "Integer is not valid." 到类型 'Integer' 的转换无效。”

Hi, I am using visual basic and the error says 'Conversion from string "Integer is not valid." to type 'Integer' is not valid.'

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MsgBox()
        Input("Are you an employee or a customer: ")
        If Name = "employee" Then
            Name = Input("first 2 letters of first name:")
            Dim number As Object
            number = input(str("Year enter of company exc 20: "))
        ElIf Name = "customer" Then
            Name = Input("Enter email: ")
            Dim password As Object
            password = Input("Enter password: ")
            Dim username As String
            username = Name
        Else
            Print("Incorrect. Try again.")
        End If
    End Sub

此代码是使用按钮工具在 visual basic 上进行登录,以便它可以转到另一个页面

为什么要创建桌面应用程序而不利用任何控件?您最好创建一个具有以下内容的表单:

  1. 两个单选按钮来区分登录类型
  2. 两个 TextBox 控件
  3. 一个 NumericUpDown 控件

当用户更改他们的登录类型选择时,它会动态地 hide/show TextBox 控件和 NumericUpDown 控件之一。看看这个截图:

现在,在 RadioButton 的 CheckedChanged 事件中,您可以更改标签的文本并切换控件的可见性:

Private Sub RadioButton_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged
    Label1.Text = If(RadioButton1.Checked, "Email", "First 2 letters of first name")
    TextBox1.Text = String.Empty
    TextBox2.MaxLength = If(RadioButton1.Checked, Integer.MaxValue, 2)
    TextBox2.Text = String.Empty
    TextBox2.Visible = RadioButton1.Checked
    Label2.Visible = RadioButton1.Checked
    NumericUpDown1.Visible = RadioButton2.Checked
    Label3.Visible = RadioButton2.Checked
End Sub

最后,当用户点击登录时,您可以根据登录类型使用 NumericUpDown 获取数值:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If (RadioButton1.Checked) Then
        ' customer login
        Dim customerName = TextBox1.Text
        Dim password = TextBox2.Text

    Else
        ' employee login
        Dim employeeName = TextBox1.Text
        Dim number = Decimal.ToInt32(NumericUpDown1.Value)

    End If
End Sub