programming-examples/asp/FilesMaths/CBit Function.asp

55 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2019-11-18 14:25:58 +01:00
<%
Private Function CBit(ByVal variantIn)
Dim re, bTest, bOut
bOut = Null
On Error Resume Next
Set re = New RegExp
With re
.Global = False
.IgnoreCase = True
.Pattern = "^([A-Z-_d]+)$"
bTest = .test(variantIn)
End With
Set re = Nothing
If Err Then bTest = False
On Error GoTo 0
If IsNull(bOut) And bTest Then
'alpha-numeric
Select Case CStr(LCase(Trim(variantIn)))
Case "on", "true", "y", "t"
bOut = 1
Case "off", "false", "n", "f", ""
bOut = 0
End Select
End If
If IsNull(bOut) And IsNumeric(variantIn) Then
On Error Resume Next
variantIn = CLng(variantIn)
If Err Then
bOut = 0
Else
If variantIn > 0 Then _
bOut = 1 Else bOut = 0
End If
On Error GoTo 0
End If
If IsNull(bOut) And (IsNull(variantIn) Or _
IsEmpty(variantIn) Or IsArray(variantIn)) Then bOut = 0
If IsNull(bOut) And IsObject(variantIn) Then
If variantIn Is Nothing Then _
bOut = 0 Else bOut = 1
End If
If IsNull(bOut) Then bOut = 0
CBit = bOut
End Function
%>