以文本方式查看主题

-  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=132037)

--  作者:w823087877
--  发布时间:2019/3/12 14:35:00
--  求助狐狸爸爸,如何设置固定位数限制
如题,我想统计身份证号码,电话号码,身份证固定18位,电话号码11位,多与少都会提示错误,并且错误后不保存。谢谢。
--  作者:有点甜
--  发布时间:2019/3/12 14:41:00
--  

datacolchanging事件,写代码限制,如

 

If e.datacol.name = "身份证" Then

    If e.newvalue <> nothing AndAlso e.newvalue.length <> 18 then

        msgbox("有错")

        e.cancel = true

    End If

End If

 

http://www.foxtable.com/webhelp/scr/0624.htm

 

或者,在保存的时候,检测

 

http://www.foxtable.com/webhelp/scr/0628.htm

 


--  作者:w823087877
--  发布时间:2019/3/12 15:02:00
--  
麻烦版猪大大给看看呗,我这玩意儿,
一、电话号会提示错误,但是位数多了他说自动截取,并且我希望是有错误就不保存,他现在把错误保存下来了。
二、身份证号码不提示位数错误,只提示调用错误。
三、我这三个语句的关系怎么修正?是不是要把后两个放在第一个语句的开头和结尾中间去啊?


Select Case e.DataCol.Name
    Case "身份证号"
        If e.DataRow.IsNull("身份证号") Then  \'身份证号码是否为空
            e.DataRow("出生日期") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("性别") = Nothing  \'如果为空,则清除出生日期
            e.DataRow("年龄") = Nothing \'如果为空,则清除年龄
        Else
            \'否则从身份证号码列中提取出生日期
            e.DataRow("出生日期") = ReadBirthday(e.DataRow("身份证号"))
            e.DataRow("性别") = ReadSex(e.DataRow("身份证号"))
            Dim d As Date = ReadBirthday(e.DataRow("身份证号"))
            Dim y As Integer = d.year
            If format(d, "MMdd") <= Format(Date.Today, "MMdd") Then
                e.DataRow("年龄") = Date.Today.Year - y
            Else
                e.DataRow("年龄") = Date.Today.Year - y -1
            End If
        End If
End Select
If e.DataCol.name = "身份证号" Then
  If e.newvalue<>Nothing AndAlso e.newvalue.length <> 18 Then
     msgbox("有错,请重新核对")
     e.cancel = True
   End If
  End If
If e.DataCol.name = "手机号码大号" Then
  If e.newvalue<>Nothing AndAlso e.newvalue.length <> 11 Then
     msgbox("有错,请重新核对")
     e.cancel = True
   End If
  End If
[此贴子已经被作者于2019/3/12 15:04:11编辑过]

--  作者:有点甜
--  发布时间:2019/3/12 15:08:00
--  

1、你可以把列的长度改成255;

 

也可以在validateEdit事件那里,写限制代码;

 

2、代码写在datacolchanging事件啊,是ing事件啊

 

If e.DataCol.name = "身份证号" Then
  If e.newvalue<>Nothing AndAlso e.newvalue.length <> 18 Then
     msgbox("有错,请重新核对")
     e.cancel = True
   End If
End If

--  作者:w823087877
--  发布时间:2019/3/12 15:14:00
--  
他是我写的代码不是那个事件成员啊。
--  作者:w823087877
--  发布时间:2019/3/12 15:15:00
--  
大大,您方便给我提供个即时通讯方式不?我现在想用你们这个免费版本的弄一个管理软件,后期肯定是要用付费版转换的,能提供给我吗?
--  作者:有点甜
--  发布时间:2019/3/12 15:24:00
--  

1、validateEdit,代码改成

 

If e.Col.name = "身份证号" Then
  If e.text<>Nothing AndAlso e.text.length <> 18 Then
     msgbox("有错,请重新核对")
     e.cancel = True
   End If
End If

 

2、代码写在datacolchanging事件啊,是ing事件啊

 

If e.DataCol.name = "身份证号" Then
  If e.newvalue<>Nothing AndAlso e.newvalue.length <> 18 Then
     msgbox("有错,请重新核对")
     e.cancel = True
   End If
End If

 

 


--  作者:w823087877
--  发布时间:2019/3/12 15:37:00
--  
谢谢大大。你们出的那本编程书有对每个事件的讲解吗?
--  作者:有点甜
--  发布时间:2019/3/12 16:31:00
--  

建议先看视频教程

 

http://foxtable.com/bbs/dispbbs.asp?boardid=2&Id=67187