以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]关于字符转换日期(已解决)  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=25798)

--  作者:yyzlxc
--  发布时间:2012/11/16 22:16:00
--  [求助]关于字符转换日期(已解决)
一段代码,跨表将8位字符转换为日期,由于zzrq列有空行,加了空值的判断代码还是出错,如何修改代码,请各位老师指教,谢谢!!

For Each dr As DataRow In DataTables("名册").DataRows
    Dim pr As DataRow
    If dr.IsNull("编号")  Then
        dr("终止日期") = Nothing
    Else
        pr = DataTables("XB").Find("[bh] = \'" & dr("编号") & "\'And [zzrq] Is Not Null")
        If pr IsNot Nothing Then
            dr("终止日期") = new Date(pr("zzrq").Substring(0,4),pr("zzrq").Substring(4,2),pr("zzrq").Substring(6,2))
        Else
            dr("终止日期") = Nothing
        End If
    End If
Next


图片点击可在新窗口打开查看此主题相关图片如下:s.jpg
图片点击可在新窗口打开查看

[此贴子已经被作者于2012-11-17 11:02:17编辑过]

--  作者:明丰
--  发布时间:2012/11/17 8:17:00
--  

“zzrq”列输入的值长度必须是8位,下面的代码:

 

If pr IsNot Nothing Then

 

改为:

If pr IsNot Nothing And pr("zzrq").length = 8 Then

 

试一下。


--  作者:yyzlxc
--  发布时间:2012/11/17 11:02:00
--  
谢谢明丰和muhua两位老师的指教,代码调整后,问题解决。再次感谢两位老师的帮助。

For Each dr As DataRow In DataTables("名册").DataRows
    Dim pr As DataRow
    If dr.IsNull("编号")  Then
        dr("终止日期") = Nothing
    Else
        pr = DataTables("XB").Find("[bh] = \'" & dr("编号") & "\'","zzrq Desc")
        If pr IsNot Nothing Then
            If pr("zzrq").length = 8 Then
                dr("终止日期") = new Date(pr("zzrq").Substring(0,4),pr("zzrq").Substring(4,2),pr("zzrq").Substring(6,2))
            Else
                dr("终止日期") = Nothing
            End If
        Else
            dr("终止日期") = Nothing
        End If
    End If
Next