mdsk.net
当前位置:首页 >> 请问vB编程高手,如何判断输入文本框中的数是否是英文字母? >>

请问vB编程高手,如何判断输入文本框中的数是否是英文字母?

strs="abcdefghijklmnopqrstuvwxyz"str_get=text1.textfor i=0 to len(str_get) c_str=mid(str_get,i,1)if instr(str_get,c_str)=-1 then msgbox "不全是字母"end ifnext关键就是用instr来判断是否字母了!

if text1.text = "" then '文本框中空白 else '文本框有内容 end if其实不用判断也可以的,直接用它生成word,如果有内容则生成的word也自然有内容,同样,空白的话则word里自然也是空白.

Private Sub Command1_Click() Dim a As Integer a = Asc(Text1.Text) Debug.Print a If a >= 49 And a = 65 And a = 97 And a 评论0 0 0

Private Sub Command1_Click() Dim s As String s = Text1.Text If Len(s) = 1 Then If Text1.Text Like "[A-Z]" Or Text1.Text Like "[a-z]" Then Text2.Text = "字母" ElseIf IsNumeric(Text1.Text) Then Text2.Text = "数字" Else Text2.Text = "其它" End If Else MsgBox "请只输入一个字符" End If End Sub

0<ascii<255 我来补充一下代码吧,在form中加入一个text1 private sub text1_change() if text1.text = "" then exit sub '如果是空字符串,就退出此过程 dim a a = asc(mid(text1.text, len(text1.text), 1)) if a > 255 or a < 0 then msgbox "刚才输入的是汉字" else msgbox "刚输入的是字符" end sub 这是靠ascii码来判断的,你根据你的程序需要进行修改吧,这是对输入框约束输入的比较常用的方法之一,你可以去搜索一下英文字符ascii码表.

根据输入字符的ASCII值判断.Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii >= 97 And KeyAscii <= 122 Then Text1 = Text1 Else KeyAscii = 0 End If End Sub

何不让文本框只接受数字呢?这样不是更合理一点. 实现方法如下: public function importnum(keyin as integer, validatestring as string, editable as boolean) as integer dim validatelist as string dim keyout as integer if editable = true then

用KeyPress可以轻松检验,0-9对应的ASCII值为48-57,用如下代码可以作测试Private Sub Text1_KeyPress(KeyAscii As Integer) if KeyAscii>=48 and KeyAscii<=57 then msgbox "输入的是数字" end ifEnd Sub

if isnumeric(text1.text) thenmsgbox "文本框中的是数字"elsemsgbox "文本框中的是字符串"end if

Dim a As Stringa = InputBox("输入一个字符,如果过位,系统将截取第一位,如果留空,系统取小写a")If Len(a) = 0 Then a = "a"ElseIf Len(a) > 1 Then a = Mid(a, 1, 1)End IfIf Asc(a) >= Asc("a") And Asc(a) <= Asc("z") Then MsgBox "字符 " & a & " 为小写字母"If Asc(a) >= Asc("A") And Asc(a) <= Asc("Z") Then MsgBox "字符 " & a & " 为大写字母"

网站首页 | 网站地图
All rights reserved Powered by www.mdsk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com