想用VB做个登陆窗口,要请求有验证码,验证码怎么做??

说的明白些。。说好了给加分哦~~
2025-02-24 12:07:56
推荐回答(2个)
回答1:

Dim vCode As String
Private Sub Command1_Click()
drawvc
Me.Text1.Text = ""
End Sub
Private Sub drawvc() '显示校验码
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 1900
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
Private Sub Command2_Click()
If Text1.Text = vCode Then
MsgBox "Login successfully!", vbInformation, "Login"
Unload Me
ElseIf Text1.Text = "" Then
MsgBox "Please enter the number you saw on the screen!", vbExclamation, "Attention"
drawvc
Else
MsgBox "Entering Error! Please enter again!", vbCritical, "Error"
Text1.Text = ""
drawvc
End If
End Sub
Private Sub Form_Load()
Picture1.FontSize = 12
Picture1.FontBold = True
Picture1.AutoRedraw = True
drawvc
End Sub

回答2:

Dim b, i, num As Integer, a As String
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
i = Int(Rnd * 51) + 1
b = Mid(a, i, 2)
num = Int(Rnd * 99)
If num < 10 Then
Print b & num & 0
Else
Print b & num
End If
给你做个参考,实际验证码比这个要复杂,把字母和数字的顺序打乱就行了(这只是个4位验证码,前两位是字母,后两位是数字)