'添加窗体Form1,文本框Text1,Text2,按钮Command1,然后添加如下代码:
Private Sub Command1_Click()
Text2.Text = strToPassword(Text1.Text, -2)'左移两位
End Sub
'函数名:strToPassword
'功能:按要求将字符转化为“密码”
'参数:strSource为要处理的字符,intMove为将字符中的每个字符移动多少位
'返回值:strToPassword处理好的字符串
Private Function strToPassword(strSource As String, intMove As Integer)
Dim i, intAscTemp, intAscTempMove As Integer
Dim strTemp As String
For i = 1 To Len(strSource)
strTemp = Mid(strSource, i, 1)
intAscTemp = Asc(strTemp)
intAscTempMove = intAscTemp + intMove
If strTemp Like "[a-zA-Z]" Then
If intAscTemp >= 97 Then '是小写字母
If intAscTempMove < 97 Then '超出首段的情况
strTemp = Chr(intAscTempMove - 97 + 122 + 1)
ElseIf intAscTempMove > 122 Then '超出尾端的情况
strTemp = Chr(intAscTempMove - 122 + 97 - 1)
Else
strTemp = Chr(intAscTempMove)
End If
ElseIf intAscTemp >= 65 Then '是大写字母
If intAscTempMove < 65 Then '超出首段的情况
strTemp = Chr(intAscTempMove - 65 + 90 + 1)
ElseIf intAscTempMove > 90 Then '超出尾端的情况
strTemp = Chr(intAscTempMove - 90 + 65 - 1)
Else
strTemp = Chr(intAscTempMove)
End If
End If
End If
strToPassword = strToPassword & strTemp
Next
End Function
Private Sub Form_Load()
Const Bef = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Const Cod = "YZABCDEFGHIJKLMNOPQRSTUVWXyzabcdefghijklmnopqrstuvwx"
Dim a, b, c
'可以把a换成text1,把msgbox c换成text2=c
a = InputBox("input code", , "A")
For b = 1 To Len(a)
c = c & Mid(Cod, InStr(1, Bef, Mid(a, b, 1)), 1)
Next b
MsgBox c
End Sub
.........这么简单,自己看书去.