函数原型:
IntegerVarType(varname As Variant)
vbEmpty 0 Empty(未初始化)
vbNull 1 Null(无有效数据)
vbInteger 2 整数
vbLong 3 长整数
vbSingle 4 单精度浮点数
vbDouble 5 双精度浮点数
vbCurrency 6 货币值
vbDate 7 日期
vbString 8 字符串
vbObject 9 对象
vbError 10 错误值
vbBoolean 11 布尔值
vbVariant 12 Variant (只与变体中的数组一起使用)
vbDataObject 13 数据访问对象
vbDecimal 14 十进制值
vbByte 17 位值
vbUserDefinedType 36 包含用户定义类型的变量
vbArray 8192 数组
vbArray类型需联合使用:
vbArray + vbInteger 表示整数数组,返回8194
函数应用:
把日期型和长整型或字符串的“类日期型”统一成"yyyy-mm-dd"格式,其他类型或不满足条件的(本例设为<"2001-01-01")返回 Fasle
Private Function Leap(ByVal Y As Integer) As Boolean Leap = (Y Mod 4 = 0 And Y Mod 100 <> 0) Or (Y Mod 400 = 0) End Function Public Function VtoD(ByVal vDate As Variant) As Variant Dim Y, M, D As Integer VtoD = True Select Case VarType(vDate) Case 0 To 2, Is = 6, Is > 8 VtoD = False Case 3 To 5 VtoD = VtoD(CStr(vDate)) Case 7: VtoD = Format(vDate, "yyyy-mm-dd") If VtoD < "2000-01-01" Then VtoD = False Case 8: If Len(vDate) <> 8 Then VtoD = False Exit Function End If For i = 1 To 8 If Asc(Mid(vDate, i, 1)) < 48 Or Asc(Mid(vDate, i, 1)) > 57 Then VtoD = False Exit Function End If Next Y = --Left(vDate, 4): M = --Mid(vDate, 5, 2): D = --Right(vDate, 2) If Y < 2000 Then VtoD = False If M > 12 Or M = 0 Then VtoD = False If D > 31 Or D = 0 Then VtoD = False If M = 2 And D > (28 + IIf(Leap(Y), 1, 0)) Then VtoD = False If VtoD = False Then Exit Function VtoD = Format(DateSerial(Y, M, D), "yyyy-mm-dd") End Select End Function