vb编程 字母大小写转换
在窗体上建立两个文本框控件,当用户单击窗体时,对于第一个文本框中出现的所有在h之后的非元音字母(按照字母排列表顺序),程序能够将其转换成相应的大写字母,处理后的新字符串显...
在窗体上建立两个文本框控件,当用户单击窗体时,对于第一个文本框中出现的所有在h之后的非元音字母(按照字母排列表顺序),程序能够将其转换成相应的大写字母,处理后的新字符串显示正在第二个文本框中。要求程序实现中不能使用Ucase和Lcase函数
展开
5个回答
展开全部
不能使用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
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
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
标准答案
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
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
参考资料: http://zhidao.baidu.com/question/161492598.html?push=ql
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询