VB在文本框中输入一些字符和数字,有什么办法让字符中的大小写同时转换并且其他字符保留???
1个回答
展开全部
转换小写为大写:LCase函数,例如XX = LCase("abcd"),返回值:XX = "ABCD"
转换大写为小写:UCase函数,例如XX = UCase("ABCD"),返回值:XX = "abcd"
可以:XX = LCase(Text1.Text) 或 XX = UCase(Text1.Text),全部转换为大写或小写;如果 Text1.Text 中的大写转换为小写,小写转换为大写,需要逐字符检测并转换。
代码如下:
Private Sub Command1_Click()
Dim XX As String, YY As String, ZZ As String, AA As Integer, I As Integer
XX = Text1.Text
AA = Len(XX)
For I = 1 To AA
ZZ = Mid(XX, I, 1)
If Asc(ZZ) >= 65 And Asc(ZZ) <= 90 Then
ZZ = LCase(ZZ)
ElseIf Asc(ZZ) >= 97 And Asc(ZZ) <= 122 Then
ZZ = UCase(ZZ)
End If
YY = YY & ZZ
Next I
Text1.Text = YY
End Sub
转换大写为小写:UCase函数,例如XX = UCase("ABCD"),返回值:XX = "abcd"
可以:XX = LCase(Text1.Text) 或 XX = UCase(Text1.Text),全部转换为大写或小写;如果 Text1.Text 中的大写转换为小写,小写转换为大写,需要逐字符检测并转换。
代码如下:
Private Sub Command1_Click()
Dim XX As String, YY As String, ZZ As String, AA As Integer, I As Integer
XX = Text1.Text
AA = Len(XX)
For I = 1 To AA
ZZ = Mid(XX, I, 1)
If Asc(ZZ) >= 65 And Asc(ZZ) <= 90 Then
ZZ = LCase(ZZ)
ElseIf Asc(ZZ) >= 97 And Asc(ZZ) <= 122 Then
ZZ = UCase(ZZ)
End If
YY = YY & ZZ
Next I
Text1.Text = YY
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询