VB求助,关于转换的
最近在玩莫尔斯电码
请问如何在TEXT中输入英文、数字、符号&空格
然后自动翻转换成图片中的样子
答案:这个很简单把先定义这些字符 添加command1 和label1 和 text1 控件
Private Sub Command1_Click()
One = "*----"
two = "**---"
three = "***--"
four = "****-"
five = "*****"
six = "-****"
seven = "--***"
eight = "---**"
nine = "----*"
zero = "-----"
A = "-*"
B = "-***"
C = "-*-*"
D = "-**"
E = "*"
F = "**-*"
G = "--*"
H = "****"
i = "**"
J = "*---"
K = "-*-"
L = "*-**"
M = "--"
N = "-*"
O = "---"
P = "*--*"
Q = "--*-"
R = "*-*"
s = "***"
T = "-"
U = "**-"
V = "***-"
W = "*--"
X = "-**-"
Y = "-*--"
Z = "--**"
dian = "*-*-*-"
douhao = "--**--"
maohao = "---***"
fenhao = "*----*"
wenhao = "**--**"
gang = "-****-"
kuohao = "-*--*-"
at = "*--*-*"
changgang = "-***-"
fenshu = "-**-*"
Dim final As String
UC = UCase(Text1.Text)
zong = Len(Text1.Text)
shu = zong - 1
Do
the = Mid(UC, zong - shu, 1)If the = "1" Then
final = final & One & "/"
Else
If the = "2" Then
final = final & two & "/"
Else
If the = "3" Then
final = final & three & "/"
Else
If the = "4" Then
final = final & four & "/"
Else
If the = "5" Then
final = final & five & "/"
Else
If the = "6" Then
final = final & six & "/"
Else
If the = "7" Then
final = final & seven & "/"
Else
If the = "8" Then
final = final & eight & "/"
Else
If the = "9" Then
final = final & nine & "/"
Else
If the = "0" Then
final = final & zero & "/"
Else
If the = "A" Then
final = final & A & "/"
Else
If the = "B" Then
final = final & B & "/"
Else
If the = "C" Then
final = final & C & "/"
Else
If the = "D" Then
final = final & D & "/"
Else
If the = "E" Then
final = final & E & "/"
Else
If the = "F" Then
final = final & F & "/"
Else
If the = "G" Then
final = final & G & "/"
Else
If the = "H" Then
final = final & H & "/"
Else
If the = "I" Then
final = final & i & "/"
Else
If the = "J" Then
final = final & J & "/"
Else
If the = "K" Then
final = final & K & "/"
Else
If the = "L" Then
final = final & L & "/"
Else
If the = "M" Then
final = final & M & "/"
Else
If the = "N" Then
final = final & N & "/"
Else
If the = "O" Then
final = final & O & "/"
Else
If the = "P" Then
final = final & P & "/"
Else
If the = "Q" Then
final = final & Q & "/"
Else
If the = "R" Then
final = final & R & "/"
Else
If the = "S" Then
final = final & s & "/"
Else
If the = "T" Then
final = final & T & "/"
Else
If the = "U" Then
final = final & U & "/"
Else
If the = "V" Then
final = final & V & "/"
Else
If the = "W" Then
final = final & W & "/"
Else
If the = "X" Then
final = final & X & "/"
Else
If the = "Y" Then
final = final & Y & "/"
Else
If the = "Z" Then
final = final & Z & "/"
Else
If the = "." Then
final = final & dian & "/"
Else
If the = "," Then
final = final & douhao & "/"
Else
If the = ":" Then
final = final & maohao & "/"
Else
If the = "'" Then
final = final & fenhao & "/"
Else
If the = "?" Then
final = final & wenhao & "/"
Else
If the = "-" Then
final = final & gang & "/"
Else
If the = "(" Or the = ")" Then
final = final & kuohao & "/"
Else
If the = "@" Then
final = final & at & "/"
Else
If the = "——" Then
final = final & changgang & "/"
Else
If the = "/" Or the = "\" Then
final = final & fenshu & "/"
End If
End If
End If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End IfEnd If
End If
shu = shu - 1
Loop Until shu = -1
Label1.Caption = final
End Sub
实验可行分数线、始信、终了、我不明白意思、所以没写、你可以自己参照的加进去、、、
使用方法:
第一步、把如下代码复制到窗体的通用部分:
Private Function ToPwd(ByVal Pas As String) As String
Dim Num(9) As String
Dim Char(1 To 26) As String
Dim Point(1 To 9) As String
Dim i As Long
Dim Results As String
Dim Tmp As StringFor i = 0 To 9 '为数字建立模型
If i <= 5 Then
Num(i) = String$(i Mod 6, "*") & String$(5 - (i Mod 6), "-")
'Print i, Num(i)
Else
Num(i) = String$(i Mod 5, "-") & String$(5 - (i Mod 5), "*")
'Print i, Num(i)
End IfNext
'建立字母模型
Char(1) = "-*": Char(2) = "-***": Char(3) = "-*-*": Char(4) = "-**": Char(5) = "*"
Char(6) = "**-*": Char(7) = "--*": Char(8) = "****": Char(9) = "**": Char(10) = "*---"
Char(11) = "-*-": Char(12) = "*-**": Char(13) = "--": Char(14) = "-*": Char(15) = "---"
Char(16) = "*--*": Char(17) = "--*-": Char(18) = "*-*": Char(19) = "***": Char(20) = "-"
Char(21) = "**-": Char(22) = "***-": Char(23) = "*--": Char(24) = "-**-": Char(25) = "-*--"
Char(26) = "--**"
'建立符号模型
Point(1) = "*-*-*-"
Point(2) = "--**--"
Point(3) = "---***"
Point(4) = "*----*"
Point(5) = "**--**"
Point(6) = "-****-"
Point(7) = "-*--*-"
Point(8) = "*--*-*"
Point(9) = "-***-"
For i = 1 To Len(Pas) '进行加密
Tmp = Mid$(Pas, i, 1)If IsNumeric(Tmp) Then '如果是数字
Results = Results & Num(Tmp) & "/" '从模型中取出
Else '若不是则判断是否为字母If Asc(LCase$(Tmp)) >= 97 And Asc(LCase$(Tmp)) <= 122 Then '为字母
Results = Results & Char(Asc(LCase$(Tmp)) - 96) & "/" '从模型中取出
&n