注册 登录
编程论坛 VB6论坛

求验证码如何在 Form 代码怎么写

admin73896 发布于 2014-05-15 16:33, 687 次点击
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
5 回复
#2
lowxiong2014-05-15 18:12
在登陆窗口里用一个全程变量存储验证码,在登陆按钮里除了做用户名和密码判断,还要做验证码判断。

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 编辑 ]
#3
admin738962014-05-16 11:18
回复 2 楼 lowxiong
Dim vCode As String  这个是放在哪~放在Form_Load里面吗
#4
admin738962014-05-16 11:44
回复 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
#5
lowxiong2014-05-16 17:28
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
#6
admin738962014-05-19 16:17
回复 5 楼 lowxiong
我试了还是不要验码就能进去`~~~我的意思是想在事件发生前就自动生成验证功能
1