|
Option Compare Database
Option Explicit
'=====================================================
'本例作者:黄海 电子邮件:hhem@163.com QQ:42209810
'欢迎ACCESS的爱好者与我交流
'=====================================================
'函数功能:指定字符串长度,不足位前面补“0”,一般用于数长整型数值,为了达到保证格式整齐时使用。
'参数一(必需)为字符,用来输入要转化的字符串
'参数二(必需)为长整型数字,输入总长度
'-------------------------------------------------------------------------------------
'::::用法::::
't = insertzero (1,4) 返回"0001"
't = insertzero (10,4) 返回"0010"
Public Function insertZero(strWord As String, allLong As Integer)
On Error GoTo errDoing
Dim manyZero As String
Dim insertZeroLong As Integer
manyZero = "00000000000000000000" '(20位)留好足够多的零呀:)
insertZeroLong = allLong - Len(strWord)
If insertZeroLong >= 0 Then
insertZero = Left(manyZero, insertZeroLong) & strWord
Else
MsgBox "长度应大于字符长度!"
End If
Exit Function
errDoing:
MsgBox Err.Number & Err.Description
Exit Function
End Function |
|