'添加窗体Form1,文本框Text1,Text2,按钮Command1,然后添加如下代码:PrivateSubCommand1_Click()Text2.Text=strToPassword(Text1.Text,-2)'左移两位EndSub'函数名:strToPassword'功能:按要求将字符转化为“密码”'参数:strSource为要处理的字符,intMove为将字符中的每个字符移动多少位'返回值:strToPassword处理好的字符串PrivateFunctionstrToPassword(strSourceAsString,intMoveAsInteger)Dimi,intAscTemp,intAscTempMoveAsIntegerDimstrTempAsStringFori=1ToLen(strSource)strTemp=Mid(strSource,i,1)intAscTemp=Asc(strTemp)intAscTempMove=intAscTemp+intMoveIfstrTempLike"[a-zA-Z]"ThenIfintAscTemp>=97Then'是小写字母IfintAscTempMove122Then'超出尾端的情况strTemp=Chr(intAscTempMove-122+97-1)ElsestrTemp=Chr(intAscTempMove)EndIfElseIfintAscTemp>=65Then'是大写字母IfintAscTempMove90Then'超出尾端的情况strTemp=Chr(intAscTempMove-90+65-1)ElsestrTemp=Chr(intAscTempMove)EndIfEndIfEndIfstrToPassword=strToPassword&strTempNextEndFunction
|