大大们帮我看下!

chuans 2009-04-22 11:16:01
初学VB编程1星期。 我想把登陆次数弄上去。怎么弄啊? 还有就是登陆次数到了一定的数量就不能登陆了。怎么弄啊??

Private Sub Command1_Click()
Dim cs As String
cs = 0 to logintimes do
Const a = "chuans"
Const b = "5088047"
If Text1.Text = a And Text2.Text = b Then
MsgBox "登陆成功!!!^-^", 64
Else
cs = 1
MsgBox "密码错误!!!" & "登陆次数"& cs, 16
End If
End Sub
...全文
63 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dengnansky 2009-04-22
  • 打赏
  • 举报
回复
Option Explicit
Dim counter As Integer

Private Sub Command1_Click()
If txtPassword <> "123456" Then
MsgBox "密码错误!!!" & "登陆次数" & counter + 1, 16
counter = counter + 1
End If
If counter = 3 Then
Unload Me
End If
End Sub

Private Sub Form_Load()
counter = 0
End Sub
SYSSZ 2009-04-22
  • 打赏
  • 举报
回复
1楼的代码写得不错,这样更精炼些:
Option Explicit 
Private Sub Command1_Click()
Static counter As Integer
If txtPassword.Text <> "123456" Then
MsgBox "密码错误!!!" & "登陆次数" & counter + 1, 16
counter = counter + 1
End If
If counter = 3 Then
Unload Me
End If
End Sub

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧