这是我用VB.NET2005编的一个关于用户登录的简单程序,
public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Long, b As Integer
a = CLng("liyu")
b = 123
If TextBox1.Text = a And TextBox2.Text = b Then
MsgBox("输入正确", 0, "提示")
Else
MsgBox("输入错误", 0, "提示")
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End If
End Sub
End Class
它提示:在System.InvalidCastException 中第一次偶然出现的“Microsoft.VisualBasic.dll”类型的异常
是怎么回事?各位老大,帮帮忙。
public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Long, b As Integer
a = CLng("liyu")
b = 123
If TextBox1.Text = a And TextBox2.Text = b Then
MsgBox("输入正确", 0, "提示")
Else
MsgBox("输入错误", 0, "提示")
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End If
End Sub
End Class
它提示:在System.InvalidCastException 中第一次偶然出现的“Microsoft.VisualBasic.dll”类型的异常
是怎么回事?各位老大,帮帮忙。
Dim a As String, b As Integer
a = "liyu"
b = 123
If TextBox1.Text = a And TextBox2.Text = b Then
MsgBox("输入正确", 0, "提示")
Else
MsgBox("输入错误", 0, "提示")
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End If End Sub
End Class
我改了,是上面就对了,谢谢
Dim a As String, b As Integer
a = "liyu"
b = 123
If TextBox1.Text = a And TextBox2.Text = b Then
MsgBox("输入正确", 0, "提示")
Else
MsgBox("输入错误", 0, "提示")
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End If End Sub
End Class
我改了,是上面就对了,谢谢
a=clng("liyu")
clng去对一个字母串转化为long当然错了。而你改为 a 为string ,赋个字母串,当然是正确的了。