请帮我检查一下vb编码哪里有问题

来源:百度知道 编辑:UC知道 时间:2024/07/04 12:04:10
Private Sub Text1_Change()
Dim s As String, t As String
Dim l As Integer
s = Text1.Text
l = Len(s)
t = Left(s, l)
If t >= "A" And t <= "Z" Then
t = LCase(t)
ElseIf t >= "a" And t <= "z" Then
t = UCase(t)
ElseIf t = " " Then
t = " "
Else
t = "*"
End If
Text1.Text = t & Right(s, l - 1)
End Sub
输入字母时,大小写互转,输入空格时输出空格,输入其他东西时输出"*"

你不如说说你要的是什么效果,你现在的错误在于你把这段代码放到了text1_change()这个事件中,而你代码的最后Text1.Text = t & Right(s, l - 1) 这句,又会触发这个text1_change()事件,如此反复,直到溢出堆栈空间

If t >= "A" And t <= "Z" Then
t = LCase(t)
ElseIf t >= "a" And t <= "z" Then
t = UCase(t)
ElseIf t = " " Then
t = " "
Else
t = "*"
End If

语法错误吗?

t = Left(s, l) L 改成 1
t = Left(s, 1)

If t >= "A" And t <= "Z" Then
t = LCase(t)
ElseIf t >= "a" And t <= "z" Then
t = UCase(t)
ElseIf t = " " Then
t = " "
Else
t = "*"
End If

少 两个end if

你这段代码要放在一个按钮里才才能用,不然会溢出的