您的位置:程序门 -> vb -> 基础类



判断输入的文本是否日期格式~急在线等


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


判断输入的文本是否日期格式~急在线等
发表于:2007-06-20 10:47:22 楼主
各位大侠
我想判断输入在textbox文本中的数据是不是yyyymmdd的日期格式应该怎么作啊~
发表于:2007-06-20 11:18:081楼 得分:0
如果允许输入的日期带有时间:
private   sub   text1_validate(cancel   as   boolean)
        if   not   isdate(text1.text)   then
                msgbox   "请输入正确的日期 "
                cancel   =   true
        end   if
end   sub


如果输入的日期中不允许带有时间:
private   sub   text1_validate(cancel   as   boolean)
        if   instr(text1.text,   ": ")   <>   0   or   not   isdate(text1.text)   then
                msgbox   "请输入正确的日期 "
                cancel   =   true
        end   if
end   sub
发表于:2007-06-20 13:40:222楼 得分:0
^^^^^^
发表于:2007-06-20 15:29:553楼 得分:0
isdate   函数:返回   boolean   值,指出一个表达式是否可以转换成日期。
发表于:2007-06-20 15:35:014楼 得分:0
public   function   chkdate(byval   strpara   as   string,   _
    optional   byval   strmsg   as   string)   as   boolean
   
    if   strpara   =   " "   then
        if   strmsg   =   " "   then   strmsg   =   "请输入日期,格式8位[yyyymmdd]   例如:   "   &   format(date,   "yyyymmdd ")
        msgbox   strmsg,   vbinformation   +   vbokonly,   "系统提示 "
        goto   chk_false
    end   if
    if   not   (isdate(format(strpara,   "####-##-## "))   _
            and   len(strpara)   =   8)   then
        strmsg   =   "日期格式应为8位[yyyymmdd]   例如:   "   &   format(date,   "yyyymmdd ")
        msgbox   strmsg,   vbinformation   +   vbokonly,   "系统提示 "
        goto   chk_false
    end   if
   
    chkdate   =   true:     exit   function
   
chk_false:
    chkdate   =   false
end   function
发表于:2007-06-20 15:48:325楼 得分:0
楼上正解,一个函数就可了


快速检索

最新资讯
热门点击