Text2.Text = DateValue(Replace(Split(Text1.Text, "-")(0), ".", " "))
Text3.Text = DateValue(Replace(Split(Text1.Text, "-")(1), ".", " "))
怎么样可以实现  把 text1.text=2.1-2.21  格式化成2010-2-1 和 2010-2-21但是如果 text1.text 既包含 “-” 又包含其他不是2.1这个格式的字符时会出现“类型不匹配”的错误
要怎们修正这些错误?各位大哥们

解决方案 »

  1.   


    Dim strTmp() As StringstrTmp = Split("2.1-查询2.21", "查询")If Ubound(strTmp) Then 
        MsgBox strTmp(1)
    Else
        MsgBox "不包含“查询”这两个汉字"
    End If
      

  2.   

    像2.1 5.3  12.14 11.22 10.29  这种就把它格式化成日期 
    如果出现不是 像 2.1-5.3  就会报 类型不匹配  比如像“-省的啊。。”“-按时打算”随便什么字符  
    2.1   5.3 可以看成是 2月1号  5.3 可以看成是 5月3号   
    其实就是 除了这个可以被格式成日期型的数字  其他的都弹出窗口报错 MSGBOX“类型错误",,"报错"
      

  3.   

    那是程序不正常  不能执行下去了  我是要用  MSGBOX 弹出错误 可以达到吗
      

  4.   

    on error goto myerr
    .
    .
    exit sub
    myerr:
    msgbox "...","..."
    end sub
      

  5.   

    On Error Goto ErrorHandlerText2.Text = DateValue(Replace(Split(Text1.Text, "-")(0), ".", " "))
    Text3.Text = DateValue(Replace(Split(Text1.Text, "-")(1), ".", " "))Exit SubErrorHandler:MsgBox "运行时错误: " & Err.Number & vbCrLf & Err.Description, vbCritical, "错误"