标题:求验证码如何在 Form 代码怎么写
只看楼主
admin73896
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2014-5-9
结帖率:81.82%
 问题点数:0 回复次数:5 
求验证码如何在 Form 代码怎么写
Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim connectionstring As String
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "D:\glxt.mdb;Persist Security Info=False"

End Sub

Private Sub Image1_Click()
Image1.ZOrder 0  ''0
End Sub

Private Sub Picture1_Click()
Dim vCode As String
Dim i, vc, px, py As Long
Dim r, g, b As Byte
Randomize
vc = CLng(8999 * Rnd + 1000)
vCode = vc
Picture1.Cls
Picture1.Print vc
For i = 0 To 2000
px = CLng(Picture1.Width * Rnd)
py = CLng(Picture1.Height * Rnd)
r = CByte(255 * Rnd)
g = CByte(255 * Rnd)
b = CByte(255 * Rnd)
Picture1.Line (px, py)-(px + 1, py + 1), RGB(r, g, b)
Next
End Sub
搜索更多相关主题的帖子: 验证码 False 如何 
2014-05-15 16:33
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:0 
在登陆窗口里用一个全程变量存储验证码,在登陆按钮里除了做用户名和密码判断,还要做验证码判断。

Dim vCode As String       '把这个函数内部变量提升为窗体全程变量,即可在登陆按钮里进行验证码判断

Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim connectionstring As String
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "D:\glxt.mdb;Persist Security Info=False"
Picture1_Click
End Sub

Private Sub Image1_Click()
Image1.ZOrder 0  ''0
End Sub

Private Sub Picture1_Click()
Dim i, vc, px, py As Long
Dim r, g, b As Byte
Randomize
vc = CLng(8999 * Rnd + 1000)
vCode = vc
Picture1.Cls
Picture1.Print vc
For i = 0 To 2000
px = CLng(Picture1.Width * Rnd)
py = CLng(Picture1.Height * Rnd)
r = CByte(255 * Rnd)
g = CByte(255 * Rnd)
b = CByte(255 * Rnd)
Picture1.Line (px, py)-(px + 1, py + 1), RGB(r, g, b)
Next
End Sub

[ 本帖最后由 lowxiong 于 2014-5-15 18:13 编辑 ]
2014-05-15 18:12
admin73896
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2014-5-9
得分:0 
回复 2 楼 lowxiong
Dim vCode As String  这个是放在哪~放在Form_Load里面吗
2014-05-16 11:18
admin73896
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2014-5-9
得分:0 
回复 2 楼 lowxiong
Private Sub Command1_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim connstr As String
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db1.mdb;Persist Security Info=False"
sql = "select * from [table] where uesrname='" & Text1.Text & "'"
conn.CursorLocation = adUseClient
conn.connectionstring = connstr
conn.Open
rs.Open sql, conn, adOpenStatic, adLockOptimistic, 1
'Set rs = conn.Execute(sql)
'rs.Open sql, conn, adOpenStatic, adLockOptimistic
If rs.RecordCount = 0 Then
MsgBox "用户不存在"
rs.Close
conn.Close
Exit Sub
End If
If Text2.Text <> rs("password") Then
MsgBox "密码错误"
rs.Close
conn.Close
Else
rs.Close
conn.Close
Unload Form1
MDIForm1.Show
Unload Me
End If
      
End Sub
2014-05-16 11:44
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:0 
Private Sub Command1_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim connstr As String
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db1.mdb;Persist Security Info=False"
sql = "select * from [table] where uesrname='" & Text1.Text & "'"
conn.CursorLocation = adUseClient
conn.connectionstring = connstr
conn.Open
rs.Open sql, conn, adOpenStatic, adLockOptimistic, 1
'Set rs = conn.Execute(sql)
'rs.Open sql, conn, adOpenStatic, adLockOptimistic
If rs.RecordCount = 0 Then
MsgBox "用户不存在"
rs.Close
conn.Close
Exit Sub
End If
If Text2.Text <> rs("password") Then
MsgBox "密码错误"
rs.Close
conn.Close
Else
if text3<>vcode then
  msgbox "验证码错误"
  exit sub
endif
rs.Close
conn.Close
Unload Form1
MDIForm1.Show
Unload Me
End If
      
End Sub
2014-05-16 17:28
admin73896
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2014-5-9
得分:0 
回复 5 楼 lowxiong
我试了还是不要验码就能进去`~~~我的意思是想在事件发生前就自动生成验证功能
2014-05-19 16:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-431584-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.146750 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved