韶关浈江区法院官网:vb小问题,会的请帮帮忙

来源:百度文库 编辑:高考问答 时间:2024/04/28 04:07:56
编程设计一个"字母数字分离"演示程序,要求功能如下:
1.在"输入"框中输入字母与数字的混合内容(无其它字符)
2.按回车后,在"字母"框中显示字母,在"数字"框中显示数字
麻烦写一下过程

Private Sub Form_Load()
Text1.Text = ""
'text1:混合输入
Text2.Text = ""
'text2:存放数字
Text3.Text = ""
'text3:存放字母
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
' Asc("0") = 48
'Asc ("9")=57
'Asc("a")=97
'Asc("z")=122
'Asc("A")=65
'Asc("Z")=90

Dim s As String
Dim l As Integer
Dim i As Integer
If KeyCode = 13 Then
l = Len(Text1.Text)
For i = 1 To l
s = Mid(Text1.Text, i, 1)
If Asc(s) >= 48 And Asc(s) <= 57 Then
Text2.SelText = s
End If
If (Asc(s) >= 65 And Asc(s) <= 90) Or (Asc(s) >= 97 And Asc(s) <= 122) Then
Text3.SelText = s
End If

Next i
End If

End Sub

应该不难,我讲讲思路:
首先确定len输入的字符长度;
然后用mid逐个字符判断是字母还是数字,长度为1;
确定是字母,放于字母处,是数字,就放于数字处,
下一个,+1