VB设计对输入的字符进行转换的程序

2025-03-05 06:17:35
推荐回答(2个)
回答1:

严格的说来回车和Backspace键也不应该转换,转换了2个文本就跟不上进度了,只不过只有按照楼主的要求去做
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 65 To 90
Text2.Text = Text2.Text & LCase(Chr(KeyAscii))
Case 97 To 122
Text2.Text = Text2.Text & UCase(Chr(KeyAscii))
Case 32
Text2.Text = Text2.Text & Chr(KeyAscii)
Case Else
Text2.Text = Text2.Text & Chr(42)
End Select
End Sub

回答2:

Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Is < 32
KeyAscii = 42
Case Is = 32
Case Is < 65
KeyAscii = 42
Case Is < 91
KeyAscii = KeyAscii + 32
Case Is < 97
KeyAscii = 42
Case Is < 123
KeyAscii = KeyAscii - 32
Case Else
KeyAscii = 42
End Select
End Sub