用vb做一个程序(100分)可追加50分

2024-12-27 00:01:28
推荐回答(6个)
回答1:

在text1里输入的字符有要求,可以自己搞定,用KeyPress事件就可以了。

Private Sub Command1_Click()
Dim str1() As String
Dim i As Long, su As Long
str1 = Split(Text1, " ") '把text1的内容赋给数组str1(),用空格做分割符
su = UBound(str1) '取得数组的维数
For i = 0 To su
If Len(str1(i)) > 1 Then MsgBox "字符格式不正确!": Exit Sub '如果有2个以上的字符连在一起就提示
Select Case str1(i)
Case "a" To "e"
str1(i) = Format(Asc(str1(i)) - 86)
Case "f" To "j"
str1(i) = Format(Asc(str1(i)) - 81)
Case "k" To "o"
str1(i) = Format(Asc(str1(i)) - 76)
Case "p" To "t"
str1(i) = Format(Asc(str1(i)) - 71)
Case "u" To "y"
str1(i) = Format(Asc(str1(i)) - 66)
Case "z"
str1(i) = "61"

Case "0" To "9"
str1(i) = "(" & str1(i) & ")"

'为简单起见,直接取得标点符号等等,不过大写的字母也进来了,你可以另外限定

End Select
Next

Dim a$
a = Join(str1, " ") '把数组用空格连为字符串,赋给text2
Text2 = a

End Sub

回答2:

可惜要求是VB,如果是VC我就会:(

回答3:

搞定了:
Private Sub Command1_Click()
Dim s As String, s1 As String, s2 As String
Dim sAsc As Integer
Dim i As Integer
s1 = Text1.Text
For i = 1 To Len(s1)
s = Mid(s1, i, 1)
If s <> " " Then
sAsc = Asc(s)
If sAsc >= 48 And sAsc <= 57 Then
s2 = s2 & "(" & s & ")"
ElseIf sAsc >= 97 And sAsc <= 122 Then
If sAsc <= 101 Then
s2 = s2 & sAsc - 86
ElseIf sAsc <= 106 Then
s2 = s2 & sAsc - 81
ElseIf sAsc <= 111 Then
s2 = s2 & sAsc - 76
ElseIf sAsc <= 116 Then
s2 = s2 & sAsc - 71
ElseIf sAsc <= 121 Then
s2 = s2 & sAsc - 66
Else
s2 = s2 & sAsc - 61
End If
Else
s2 = s2 & s
End If
Else
s2 = s2 & " "
End If
Next
Text2.Text = s2
End Sub

回答4:

为什么不是VC....要不100分我得了
这么简单....

回答5:

wo只会C++嗨

回答6:

我只回TP