vb大小写转换
发布网友
发布时间:2022-04-21 06:08
我来回答
共15个回答
热心网友
时间:2022-04-27 17:15
大小写转换所用到的函数有Ucase函数和Lcase函数。其中 Ucase("字符串")______将字符串中所有小写字母转换成大写,最终字符串全部是大写字母;
Lcase("字符串")______将字符串中所有大写字母转换成小写,最终字符串全部是小写字母。
下面是应用Lcase函数 进行大小写转换:
Private Sub Command1_Click()
Dim X As String Dim I As Long Dim S As String Dim CH As String //定义输入输出量
X = Text1.Text For I = 1 To Len(X) CH = Mid(X, I, 1)
If CH >= "a " And CH <= "z" Then S = S + UCase(CH) //将 Text1 的文本全换成小写 Text3
ElseIf CH >= "A" And CH <= "Z" Then S = S + LCase(CH) //将 Text1 的文本全换成大写
EndSub
End If Next I Text2.Text = S End Sub
扩展资料:
(1)Lcase(string)将大写字母转换成小写字母,若String本身为小写字母或非字母函数,函数的返回值不变;若String为NULL,则函数的返回值为null:
<%
MyChar = "COMPUTER" '给变量赋值
MyChar = Lcase(MyChar) '将变量所有字母转换为小写
Response.write (MyChar) '输出变量
%>
(2)UCase 函数返回 Variant(String),其中包含转成大写的字符串。
语法:UCase(string)
必要的 string参数为任何有效的字符串表达式。如果 string 包含 Null,将返回Null。
说明:只有小写的字母会转成大写;原本大写或非字母之字符保持不变。
下面的示例利用 UCase函数返回字符串的大写形式:
Dim MyWord= UCase("Hello World")' 返回"HELLO WORLD"。
参考资料:lcase_百度百科
UCase_百度百科
热心网友
时间:2022-04-27 18:33
Private Sub Text1_Change()
'变量声明时注意定义变量类型
Dim X As String
Dim I As Long
Dim S As String '把后面代码中的S1改为S
Dim CH As String
X = Text1.Text '赋值语句应该把变量放在前面
For I = 1 To Len(X)
CH = Mid(X, I, 1)
If CH >= "a " And CH <= "z" Then '此处的“a ”多了一个空格,虽然程序运行时没有出错……
S = S + UCase(CH)
ElseIf CH >= "A" And CH <= "Z" Then
S = S + LCase(CH)
End If
Next I
Text2.Text = S
End Sub
热心网友
时间:2022-04-27 20:08
不能使用Ucase和Lcase函数,你可以将字母字符转化成为数值,小写字母的值域是97-122,大写字母是65-90,用Chr()和Asc()这两个函数也可以实现大小写的转化的。
Private Sub Form_Click()
x = Text1.Text
n = Len(Trim(x))
For i = 1 To n
l = Mid(x, i, 1)
If l > "h" Then
l = Chr(Asc(l) - 32)
Text2.Text = Text2.Text & l
End If
Next i
End Sub
热心网友
时间:2022-04-27 21:59
Private Sub Text1_Change()
Dim X As String
Dim I As Long
Dim S1 As String
Dim CH As String
S1 = ""
X = Text1.Text
For I = 1 To Len(X)
CH = Mid(X, I, 1)
If CH >= "a" And CH <= "z" Then
S1 = S1 + UCase(CH)
ElseIf CH >= "A" And CH <= "Z" Then
S1 = S1 + LCase(CH)
End If
Next I
Text2.Text = S1
End Sub
'-----------------
'错了几处,
'其中一处是 "a "中多了个空格,其他的自己对比吧
'还有,建议下次运行先编译
热心网友
时间:2022-04-28 00:07
p=Split(text1,"")
For i=0 to Ubound(p)
b$=b$ & m_Str(p(i))
Next i
text1=b$
写一个自定义函数m_Str(Str)判断和转化大小写:
Function m_Str(Byval Str As String)As String
if Ucase(Str)=Str Then’如果本身为大写
m_Str=Lcase(Str)'转为小写
Else
m_Str=Ucase(Str)'转为小写
End If
End Function
热心网友
时间:2022-04-28 02:32
Private Sub Form_Click()
If Text1.Text <> "" Then
For i = 1 To Len(Text1.Text)
Dim AscStr As Integer
Dim tmpstr As String
tmpstr = Mid(Text1.Text, i, 1)
Select Case tmpstr
Case "a", "e", "i", "o", "u"
'对元音字母什么也不做,直接输出
Text2 = Text2 & tmpstr
Case Else
AscStr = Asc(tmpstr)
If AscStr > 104 And AscStr <= 122 Then
'开始把h之后的小写字母转换成大写
Dim resStr As String
resStr = Chr(AscStr - 32)
Text2 = Text2 & resStr
Else
Text2 = Text2 & tmpstr
End If
End Select
Next i
End If
End Sub
热心网友
时间:2022-04-28 05:13
dim a1&,a2&,a3&,a4$
a1=len(text1.text)
for a2=1 to a1
a3=asc(mid(text1.text,a2,1))
if a3>64 and a3<91 then
a4=a4 & chr(a3 + 32)
end if
else
a4=a4 & chr(a3-32)
end if
exit sub
text1.text=a4
如果你的text1的内容里只有大小写英文,以上就可以。
热心网友
时间:2022-04-28 08:11
标准答案
Private Sub form_Click()
Dim s As String
Dim t As String
s = Text1.Text
Dim i As Long
Dim char As Long
Text2.Text = ""
For i = 1 To Len(s)
char = Asc(Mid(s, i, 1))
If char >= 104 And char <= 122 Then
'说明是小写字母 h-z
Select Case char
Case Asc("i")
Case Asc("o")
Case Asc("u")
Case Else
'小写字母转换大写字母
Text2.Text = Text2.Text & Chr(char - 32)
End Select
Else
End If
Next
End Sub
热心网友
时间:2022-04-28 11:26
Private Sub Command1_Click()
Text2.Text = UCase(Text1.Text) '转换成大写的函数
End Sub追问那小写呢是不是lcase
追答是的。Lcase
热心网友
时间:2022-04-28 14:57
不知道你是说转换数字大小写还是字母大小写,还是金额大小写,这是我做的金额大小的程序
代码如下:
Private Function setdata(num As Integer) As String '数字转换
Select Case num
Case 0
setdata = "零"
Case 1
setdata = "壹"
Case 2
setdata = "贰"
Case 3
setdata = "叁"
Case 4
setdata = "肆"
Case 5
setdata = "伍"
Case 6
setdata = "陆"
Case 7
setdata = "柒"
Case 8
setdata = "捌"
Case 9
setdata = "玖"
End Select
End Function
Private Function chang(aaa As Integer) As String '位数转换
Select Case aaa
Case 1
chang = ""
Case 2
chang = "十"
Case 3
chang = "百"
Case 4
chang = "千"
Case 5
chang = "万"
Case 6
chang = "十"
Case 7
chang = "百"
Case 8
chang = "千"
Case 9
chang = "亿"
Case 10
chang = "十"
End Select
End Function
Private Sub Form_Activate() '设定文本长度
Text2.MaxLength = 10
Text2.SetFocus
End Sub
Private Sub Text2_Change() '小写转大写
Dim i As Integer
Dim j As Integer
Dim myint As Integer
Dim myint1 As Integer
Dim mydoub As Double
Dim mystr As String
Dim mystr1 As String
Dim mystr2 As String
Dim mystr3 As String
Dim mystr4 As String
Dim money As Long
Dim money1 As Integer
Dim money2 As Long
mystr = Text2.Text
myint = InStr(mystr, ".")
If myint = 0 Then
mystr = Text2.Text
Else
mystr3 = Right(Text2.Text, Len(Text2.Text) - myint)
If mystr3 <> "" Then '转换小数位
mystr4 = Left(mystr3, 1)
mystr3 = Right(mystr3, Len(mystr3) - 1)
If mystr4 <> "0" Then
mystr2 = mystr2 + setdata(Val(mystr4)) + "角"
End If
If mystr3 <> "" Then
mystr4 = Left(mystr3, 1)
mystr2 = mystr2 + setdata(Val(mystr4)) + "分"
End If
End If
mystr = Left(Text2.Text, myint - 1)
End If
j = Len(mystr)
For i = 1 To Len(mystr) '转换整数位
money2 = Left(mystr, i)
money1 = Right(money2, 1)
If money1 = 0 Then
If j = 5 Then
If Right(mystr1, 1) <> "万" Then mystr1 = mystr1 & "万"
Else
If Right(mystr1, 1) <> "零" And Right(money, j) > 0 Then mystr1 = mystr1 & "零"
End If
Else
mystr1 = mystr1 & setdata(money1) + chang(j)
End If
j = j - 1
Next i
Text1.Text = mystr1 & "元" & mystr2 '显示大写
End Sub
Private Sub Command1_Click()
End
End Sub追问我们只是做个作业 上楼这哥儿们给的就行 谢谢你了 但是太深了
热心网友
时间:2022-04-28 18:45
Private Sub Command1_Click()
Dim C As String
Dim S As String
Dim I As Integer
Text13.Text = ""
For I = 1 To Len(Text12.Text)
C = Mid(Text12.Text, I, 1)
If C <> " " Then
Select Case C
Case "0"
S = "零"
Case "1"
S = "壹"
Case "2"
S = "贰"
Case "3"
S = "叁"
Case "4"
S = "肆"
Case "5"
S = "伍"
Case "6"
S = "陆"
Case "7"
S = "柒"
Case "8"
S = "捌"
Case "9"
S = "玖"
Case Else
S = " "
End Select
Text13.Text = Text13.Text & S & " "
Else
S = " "
End If
Next I
End Sub
热心网友
时间:2022-04-28 22:50
form1_click
dim s as string
for i=1 to len(text1.text)
if asc(mid(text1.text,i,1))>104 and asc(mid(text1.text,i,1))<123 then
s=s+str(asc(mid(text1.text,i,1))-32)
else
s=s+mid(text1.text,i,1)
end if
next i
text2.text=s
热心网友
时间:2022-04-29 03:11
Private Sub Command1_Click()
For i = 1 To Len(Text1.Text)
ss = Asc(Mid(Text1.Text, i, 1))
If ss > 96 And ss < 123 Then
ss = ss - 32
ElseIf ss > 65 And ss < 93 Then ss = ss + 32
End If
a = a & Chr(ss)
Next i
Text1.Text = a
End Sub
热心网友
时间:2022-04-29 07:49
Private Sub Command1_Click()
Dim str1 As String, t As String
For i = 1 To Len(Text1)
t = Mid(Text1, i, 1)
Select Case t
Case "i", "o", "u", "I", "O", "U"
Case "h" To "z"
str1 = str1 & Chr(Asc(t) - 32)
Case "H" To "Z"
str1 = str1 & t
End Select
Next
Text2 = str1
End Sub
热心网友
时间:2022-04-29 12:44
Dim X As Double
Dim I As Double
Dim S As Double
类型定义不对吧.