您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



只允许输入汉字在提交的时候提醒


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


只允许输入汉字在提交的时候提醒[已结贴,结贴人:xuxugr]
发表于:2007-06-17 16:09:02 楼主
private   sub   text1_keypress(keyascii   as   integer)
    if   keyascii   >   0   and   keyascii   <>   13   and   keyascii   <>   8   then
        keyascii   =   0
        msgbox   "只允许输入汉字! ",   48,   "提示 "
    end   if
end   sub
这是输入时提醒,不太方便
      case   "ok "代表提交保存,之后要检验是否输入汉字按如何写代码,
发表于:2007-06-17 16:44:391楼 得分:0
private   sub   txtname_keypress(keyascii   as   integer)
        '只允许输入汉字
        if   chr(keyascii)   like   "[!一-龥] "   then
                if   keyascii   <>   8   and   keyascii   <>   9   and   keyascii   <>   13   then
                        keyascii   =   0
                end   if
        end   if
end   sub
发表于:2007-06-17 16:55:372楼 得分:0
我说过了,在要输入时提醒,我要提交确定按钮时才提醒呀
发表于:2007-06-17 17:39:063楼 得分:10
‘我说过了,在要输入时提醒,我要提交确定按钮时才提醒呀'

无言。你自己改一点嘛,脑在你脖子上。

不过还是给你怎样判断是非是chinese   characters

public   function   ischinese(byval   asciiv   as   integer)   as   boolean
if   len(hex$(asciiv))   >   2   then
ischinese   =   true
else
ischinese   =   false
end   if
end   function

发表于:2007-06-17 18:21:354楼 得分:0
无语了,你只能输入汉字,   不是比你确定的时候更好吗?你不能输入!你还确定的时候提醒什么呢?
真不懂?
发表于:2007-06-18 08:42:195楼 得分:0
private   sub   cmdok_click()
    dim   i   aa   integer

    for   i   =   0   to   len(text1)
        if   asc(mid(text1,   i,   1))   >   0   then
            text1.selstart   =   0
            text1.sellength   =   len(text1)
            msgbox   "只允许输入汉字! "
            text1.setfocus
            exit   sub
        end   if
    next   i

'原有正常执行的代码
'......
end   sub
发表于:2007-06-18 13:57:066楼 得分:0
of123()提示无效的过程调用参数,
回复,输入是马上提醒很不方便,有时输错了回一它又提醒错了,输都输不进去
发表于:2007-06-18 15:40:187楼 得分:0
在keypress中加個
            keyascii   =   0
隻要是輸入漢字,自動刪除就可以了.
发表于:2007-06-18 16:26:228楼 得分:0
vbadvisor(sunlight)   已写出来了啊~
发表于:2007-06-18 17:36:119楼 得分:0
如果是不允许输入数字呢
发表于:2007-06-19 13:15:2410楼 得分:0
private   sub   text1_keypress(index   as   integer,   keyascii   as   integer)

        if   keyascii   =   27   then
                unload   me
        else
              if   (keyascii   <=   47   or   keyascii   > =   58)   and   keyascii   <>   13   and   keyascii   <>   8   then                 '13回車鍵,8刪除鍵,27esc鍵,用keyascii判斷輸入字符是什麼東西
              msgbox   "請輸入數字,謝謝 ",   vbokonly,   "提示 "
              keyascii   =   0   '不是數字自動刪除
        end   if
        end   if
       
end   sub
发表于:2007-06-19 15:44:2311楼 得分:40
把判断的代码放在validate事件中去执行:

private   sub   text1_validate(cancel   as   boolean)
        if   len(text1.text)   *   2   <>   lenb(strconv(text1.text,   vbfromunicode))   then
                msgbox   "输入的内容必须全部是汉字 "
                cancel   =   true
        end   if
end   sub
发表于:2007-06-20 00:11:4512楼 得分:0
private   sub   text1_keydown(index   as   integer,   keycode   as   integer,   shift   as   integer)
       
    dim   strpos   as   string
    if   keycode   >   0   and   keycode   <>   13   and   keycode   <>   8   then
              keyascii   =   0
             
              msgbox   "输入字符必须为中文! ",   48,   "提示 "
              end   if
    if   keycode   =   vbkeyreturn   and   index   =   2   then
       
   

          if   blnadd   =   false   then
              if   text1(3)   <>   " "   then   text1(3)   =   left(text1(3),   len(text1(3))   -   lngol)   &   "( "   &   text1(1)   &   ") "   &   text1(2)
          else
              if   blntj   =   true   then
                    if   treeview1.nodes.count   >   0   then
                        strpos   =   instr(1,   treeview1.selecteditem.key,   "\ ",   1)
                        if   strpos   =   0   then
                            text1(3)   =   text1(2)
                        else
                            text1(3)   =   treeview1.selecteditem.parent.fullpath   &   "\ "   &   text1(2)
                        end   if
                    else
                        text1(3)   =   text1(2)
                    end   if
              else
                    text1(3)   =   treeview1.selecteditem.fullpath   &   "\ "   &   text1(2)
              end   if
          end   if
         
      end   if
     
      if   keycode   =   vbkeyreturn   and   index   >   3   and   index   <   6   then   text1(index   +   1).setfocus


end   sub

这就是完整的代码,当我切换输入法时它就要提醒输入中文,怎么改呢
发表于:2007-06-20 00:26:3913楼 得分:0
jadeluo(秀峰)说的不错,我用他的方法解决了,高人


快速检索

最新资讯
热门点击