在窗体上建立两个文本框控件,当用户单击窗体时,对于第一个文本框中出现的所有在h之后的非元音字母(按照字母排列表顺序),程序能够将其转换成相应的大写字母,处理后的新字符串显示正在第二个文本框中。要求程序实现中不能使用Ucase和Lcase函数
-----------------
我做了这三个都不对,题目给的最终样例答案是输入的house,单击后第二个文本框里,是大写HS
求高手帮忙看看哪出问题了
-----
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
--------
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
-----------------
我做了这三个都不对,题目给的最终样例答案是输入的house,单击后第二个文本框里,是大写HS
求高手帮忙看看哪出问题了
-----
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
--------
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
Console.WriteLine(Foo("house"))
End Sub Function Foo(source As String)
Dim AfterH As Boolean = False
Dim Ignore As String = "aeiou"
Dim r = source.ToList().Select(Function(x) As Char
Dim x1 As Char = x
If AfterH Then
If Not Ignore.Contains(x) Then
x1 = IIf(x <= "Z", x1, Chr(Asc(x1) - 32))
End If
End If
If x = "H" Or x = "h" Then AfterH = True
Return x1
End Function)
Dim result As String = ""
For Each i In r.ToList()
result += i
Next
Return result
End Function
End ModulehouSe
x = Text1.Text
N = Len(Trim(x))
For i = 1 To N
l = Mid(x, i, 1)
If l > "h" And l <> "o" And l <> "u" Then
l = Chr(Asc(l) - 32)
End If
Text2.Text = Text2.Text & l
Next i
End Sub
Private Sub Text1_Change()
Dim i As Integer
Text1.Text = Trim$(Text1.Text)
If Text1.Text <> "" Then
If Len(Text1.Text) = 1 Then
If CheckString(Text1.Text) = True Then
Text2.Text = Chr(Asc(Text1.Text) - 32)
Else
Text1.Text = ""
End If
Else
Text2.Text = ""
For i = 1 To Len(Text1.Text)
If CheckString(Mid(Text1.Text, i, 1)) = True Then
Text2.Text = Text2.Text & Chr(Asc(Mid(Text1.Text, i, 1)) - 32)
Else
Text1.Text = Mid$(Text1.Text, 1, Len(Text1.Text) - 1)
End If
Next i
End If
Else
Text2.Text = ""
End If
End SubPrivate Function CheckString(Code As String) As Boolean
CheckString = IIf(Asc(Code) > 96 And Asc(Code) < 123, True, False)
End Function