Vb.net 我的VB 2012代码有什么问题?
我正试图做一个代码,接受1登录,然后移动到Form2,但它不会让我!它说存在构建错误:Vb.net 我的VB 2012代码有什么问题?,vb.net,Vb.net,我正试图做一个代码,接受1登录,然后移动到Form2,但它不会让我!它说存在构建错误: Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If TextBox1.Text = "User" And TextBox2.Text = "Qf17yu" And TextBox3.Text = "QW56-7456-8UIP" The
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "User" And TextBox2.Text = "Qf17yu" And TextBox3.Text = "QW56-7456-8UIP" Then MsgBox("Correct login, welcome.", 0 + 64 + "Welcome")
Else
MsgBox("Username, password or Secret Key incorrect!", 0 + 64, "Try again")
End If
End Sub
结束类您的
MsgBox
与您的If
位于同一行。在之后添加一行,然后
VB允许您使用两种不同类型的If
语句,一种是单行语句,另一种是多行语句,但不允许您将它们混合使用
见:
你可以做:
If condition Then dostuff Else dootherstuff End If
If condition Then
Dostuff
Else
Dootherstuff
End If
或者你可以:
If condition Then dostuff Else dootherstuff End If
If condition Then
Dostuff
Else
Dootherstuff
End If
但是你不能用你尝试过的方式来混合它们。试试这个:-
If TextBox1.Text = "User" And TextBox2.Text = "Qf17yu" And TextBox3.Text = "QW56-7456-8UIP" Then
MsgBox("Correct login, welcome.", 0 + 64 + "Welcome")
Else
MsgBox("Username, password or Secret Key incorrect!", 0 + 64, "Try again")
End If
Else和End If用蓝色波浪线划线。另外,您的第一个
MsgBox
语句是错误的:MsgBox(“正确登录,欢迎!”,0+64,“欢迎”)
(加上应该是逗号)您不命名控件,只保留默认名称-恶心@DonA:+1,但这总比像其他新程序员那样给他们起随机名字要好(见其他问题)。从这段代码可以清楚地看出,TextBox1至少是一个TextBox.:)@USER 2804222:如果丹尼尔的答案是有用的,请考虑接受它。