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

求VB编程

编制一个帐号与密码的检验程序。要求:①帐号不要超过6个数字,密码4个字符(设密码为VB6),密码框中不显示实际输入字符。②帐号(如非数字)不正确时,提示有关信息并清除原内容,得到焦点再输入③密码不正确时,单击“重试”,密码狂框清空,得到焦点重新输入,若单击“取消”,停止运动
答案:答案一

 

Private Sub Command1_Click()
If Text1.Text <> "" And Text2.Text = "VB6" Then
MsgBox "恭喜你成功登入"
End If
End Sub

Private Sub Form_Load()
Text2.MaxLength = 4
Text2.PasswordChar = "*"
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Static j As Integer
Dim sum As String

j = 0
For i = 1 To Len(Text1.Text)
   
    sum = Mid(Text1.Text, i, 1)
    Select Case sum
   
    Case 1 To 9
       
        j = j + 1
        If j >= 6 Then
            MsgBox "你的数字已满6"
            Text1.MaxLength = i
        End If
       
    End Select
Next
End Sub


提示:输入太快可以看见超过6个数字

 

答案二

 

Private Sub Command1_Click()
If Not Text2.Text = "密码不正确时" Then
    Text2.Text = ""
    Text2.SetFocus
   
End If
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If Not IsNumeric(Text1.Text) Then
    MsgBox "你输入有误"
    Text1.Text = ""
    Text2.SetFocus
End If
End Sub


 

对不起我不知道你说停止运动 看在我做这么久份上给分吧!

Visual Basic.NET 是从 Visual Basic 语言演变而来的,是一种为高效地生成类型安全和面向对象的应用程序而设计的语言。Visual Basic 允许开发人员开发面向 Windows、Web 和移动设备的程序。与所有面向 Microsoft .NET Framework 的语言一样,使用 Visual Basic 编写的程序都具有安全性和语言互操作性方面的优点。  这一代 Visual Basic 延续了为您提供一种简单快捷的方法来创建基于 .NET Framework 的应用程序的传统。  VB.NET的简介  VB.net是微软最新平台技术,是.netframeworkSDK的一种语言。VB.net和VC#.net在功能上没有区别。编译以后生成的可执行文件被称为Assembly,即程序集。  VB.net的版本号是VisualBasic7.0,它的运行是建立在CLR(CommonLanguageRuntime)和MSIL(MicrosoftIntermediateLanguage)虚拟器上的。其实,它的机制和Java差不多。  VB.NET的特点   1.真正成为面向对象以及支持继承性的语言。  2.窗体设计器支持可视化继承,并且包含了许多新的特性,比如自动改变窗体大小、资源本地化支持、数据类工具内在支持XML数据。  3.直接建立在.NET的框架结构上,因此开发人员可以充分利用所有.NET平台特性,也可以与其他的.NET语言交互。  4.为Windows应用程序提供了XCOPY部署,开发者不再需要为DLL的版本问题担忧。  VB.net的语言特点:   1.代码托管。被托管的代码享受.netframework提供的安全保障和垃圾回收机制,但是这也同时表明,你的程序被框在Framework里面了。API变得不太方便。  2.强大的面向对象特性。现在VB7已经是一个完全的面向对象程序。  现在VB7已经支持类的各种特性:继承,函数的覆盖,重载,虚拟,隐藏……  3.功能强大,程序界面更标准。  4.程序代码结构化更强,开发环境舒适体贴。
..呵。网上找到的:

窗体添加一个Text1 和 Text2,分别是 账号与密码,一个确定按钮 command1  一个 重试按钮 command2,一个取消按钮 command3

窗体如下

 

 

 

添加以下代码

 

Option Explicit
Const user As String = "123456", pwd As String = "VB6" '定义用户名,默认为 123456 ,密码 VB6
Private Sub Command1_Click() '确定
If Not IsNumeric(Text1) Then
    MsgBox "账号错误"
    Text1 = ""
    Text1.SetFocus
    Exit Sub
End If
If Text2 <> pwd Then
    MsgBox "密码错误"
    Text2 = ""
    Text2.SetFocus
    Exit Sub
End If
MsgBox "登录成功"
End Sub

Private Sub Command2_Click()  '重试
Text2 = ""
Text2.SetFocus
End Sub

Private Sub Command3_Click() '取消
End
End Sub

Private Sub Form_Load()
Text1 = ""
Text2 = ""
Command1.Caption = "确定"
Command2.Caption = "重试"
Text1.MaxLength = 6
Text2.MaxLength = 4
Text2.PasswordChar = "*"
Command3.Caption = "取消"
Command1.Default = True
Command3.Cancel = True
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(Text1) = 6 Then Text2.SetFocus
End Sub

Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(Text2) = 4 Then Command1.SetFocus
End Sub

 

界面设计如下图:

代码如下:

Private Sub Command1_Click()
    If IsNumeric(Text1.Text) = False Then
        MsgBox "账号只能是数字", vbInformation, "提示"
        Text1.Text = ""
        Text1.SetFocus
    End If
    If Text2.Text <> "VB6" Then
        xz = MsgBox("密码不正确!", vbRetryCancel, "提示")
        If xz = vbRetry Then
            Text2.Text = ""
            Text2.SetFocus
        Else
        End If
    End If
End Sub

Private Sub Command2_Click()
    End
End Sub

Private Sub Form_Load()
    Text1.MaxLength = 6
    Text2.MaxLength = 4
    Text2.PasswordChar = "*"
End Sub

上一个:VB编程问题
下一个:vb编程解答

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