当前位置:编程学习 > VB >>

帮我写这个vb的代码

系统登陆的。好简单的。呵呵。

text1、text2、command1。这些控件。

点击command1,如果text1空,提示“用户名不能为空”。如果text2空,提示“密码不能为空”。如果text1和text2都为空,提示“请输入用户名和密码!”。用户名和密码为admin时,提示“输入正确,欢迎使用本系统!”同时form2.show。谢谢!~

答案:   If Text1 = "" Then
      MsgBox "请输入用户名"
      Text1.SetFocus'获取焦点(光标)
      Exit Sub            '退出过程
   ElseIf Text2 = "" Then
      MsgBox "请输入密码"
      Text2.SetFocus
      Exit Sub
   ElseIf Text1 = "" And Text2 = "" Then
      MsgBox "请输入用户名和密码"
      Text1.SetFocus
      Exit Sub
   End If
  
   If Text1 <> "admin" Then
      MsgBox "用户名错误!"
      Text1 = "": Text1.SetFocus
      Exit Sub
   ElseIf Text2 <> "admin" Then
      MsgBox "密码错误!"
      Text2 = "": Text2.SetFocus
      Exit Sub
   Else
      MsgBox "还原使用本系统"
      Form2.Show
      Unload Me
   End If

 

 

Private Sub Command1_Click()
If Text1.Text = "" And Text2.Text = "" Then
    MsgBox "请输入用户名密码"
    Exit Sub
End If
    If Text1.Text = "" Then
        MsgBox "用户名不能空"
        Exit Sub
    End If
    If Text2.Text = "" Then
        MsgBox "密码不能为空"
        Exit Sub
    End If
If UCase(Text1.Text) = "ADMIN" And UCase(Text2.Text) = "ADMIN" Then
    form2.Show
End If
End Sub

Private Sub Form_Load()
Text2.PasswordChar = "*"
End Sub
---------------------------------要整体代码请留下邮箱----------------

If Text1.Text = "" And Text2.Text = "" Then
MsgBox "请输入用户名和密码!"
Else
If Text1.Text = "" Then
MsgBox "用户名不能为空"
Else
If Text2.Text = "" Then
MsgBox "请输入用密码"
Else
If Text1.Text = 123 And Text2.Text = 123 Then
MsgBox "输入正确,欢迎使用本系统!"
Form2.Show

End If
End If
End If
End If


Dim username As StringDim password As StringPrivate Sub Command1_Click()If Text1.Text = "" And Text2.Text = "" Then  MsgBox "请输入用户名和密码"ElseIf Text1.Text = "" Then   MsgBox "用户名不能为空"ElseIf Text2.Text = "" Then  MsgBox "密码不能为空"ElseIf Text1.Text = username And Text2.Text = password Then  Form2.ShowMsgBox "输入正确,欢迎使用本系统"ElseIf Text1.Text = username And Text2.Text <> passwor ThenMsgBox "密码错误,请重新输入"Text2.Text = ""ElseIf Text1.Text <> username ThenMsgBox "对不起,不存在该用户,请重新输入"Text1.Text = ""Text2.Text = ""End IfEnd Sub
Private Sub Form_Load()Text1.Text = ""Text2.Text = ""Text2.PasswordChar = "*"   '决定密码的显示方式password = "admin"username = "admin"End Sub
恩 就是这个样子了。具体的细节方面的,你可以自己再改改,发挥想象力。form1和form2是相互独立的 那么接下来你就可以在form2上编写你想要的其他的代码了比如说滚动字幕之类的。

上一个:VB里 for next 这个怎么用
下一个:vb程序,高手请进 急

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,