关于VB6.0专业版的简单程序编写问题

来源:百度知道 编辑:UC知道 时间:2024/06/08 15:39:23
设置了两个本文框控件,名字为“text1”和“text2”
和一个commandbotton 名字是“cmdlogin” 想设计一个登录窗口
程序编写如下:

Dim strusername As String
Dim strpassword As String
Const username As String = "admin"
Const password As String = "000000"

Private Sub Form_Load()
strusername = ""
strpassword = ""
txttext1.Text = ""
txttext2.Text = ""
txttext2.MaxLength = 10

End Sub

Private Sub cmdlogin_Click()
If txttext1.Text = "" Then
MsgBox "用户名不能为空!"
txttext1.SetFocus
Exit Sub
Else
strusername = Trim(txttext1.Text)
strpassword = Trim(txttext2.Text)
If (strusername = username) And (strpassword = password) Then
MsgBox "登录成功!当前用户为:" & strusername
Else
MsgBox "登录失败,用户名不存在或密码错误"

txttext1.SetFocus

txttext1 <> text1
txttext2 <> text2
控件名字与你程序中的不一样啊?
当然没法定位对象。

通用部分代码:
Dim strusername As String
Dim strpassword As String
Const username As String = "admin"
Const password As String = "000000"
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "用户名不能为空!"
Text1.SetFocus
Exit Sub
Else
strusername = Trim(Text1.Text)
strpassword = Trim(Text2.Text)
If (strusername = username) And (strpassword = password) Then
MsgBox "登录成功!当前用户为:" & strusername
Else
MsgBox "登录失败,用户名不存在或密码错误"

Text1.SetFocus
End If
End If
End Sub

Private Sub Form_Load()
strusername = ""
strpassword = ""
Text1.Text = ""
Text2.Text = ""
Text2.MaxLength = 10

End S