VB 大小寫互換!!!!!!!
- 2023-01-24
Private Sub Command1_Click()
Dim s As String, i As Integer, t, a As String
s = InputBox(“請輸入一個字串:”)
i = 1
Do While i <= Len(s)
t = Mid(s, i, 1)
If Asc(t) >= 65 And Asc(t) <= 90 Then
a = a & Chr(Asc(t) + 32)
ElseIf Asc(t) >= 97 And Asc(t) <= 122 Then
a = a & Chr(Asc(t) - 32)
Else
a = a & t
End If
i = i + 1
Loop
Print a
End Sub
private sub text1_keypress(keyascii as integer)
if keyascii < 91 and keyascii > 64 then
keyascii = keyascii + 32
elseif keyascii > 96 and keyascii < 123 then
keyascii = keyascii - 32
elseif keyascii <> 32 then
keyascii = 42
end if
end sub
建議用VB。NET 有 ToLower ToUpper
我在程式碼里加了非字母時的處理,如果不需要可以刪除
Private Sub Command2_Click()
Dim S1 As String, S2 As String, I As Long, N As Long
S1 = InputBox(“請輸入一個字串:”)
Do While Len(S1) > 0
N = Asc(S1)
If N > 64 And N < 90 Then
S2 = S2 & Chr(N + 32)
Else
If N > 96 And N < 123 Then
S2 = S2 & Chr(N - 32)
Else
S2 = S2 & Left(S1, 1)
End If
End If
S1 = Right(S1, Len(S1) - 1)
Loop
Debug。Print S2 ‘s2為變後的字串
End Sub
Private Sub Command1_Click()
For i = 0 To 128
Debug。Print Chr(i) & “ ” & i
Next i
s = “”
t = Text1。Text
For i = 0 To Len(Text1。Text) - 1
t = Mid(Text1。Text, i + 1, Len(Text1。Text) - 1)
a = Mid(t, 1, 1)
If Asc(a) >= 65 And Asc(a) <= 90 Then
s = s & LCase(a)
Else
s = s & UCase(a)
End If
Next i
Text1。Text = s
End Sub
下一篇:什麼是係數什麼是指數?