'********************************************************************
'*
'* Function Bin2Dec
'*
'* Author: NetworkAdminKB.com
'* Created: 2005-10-04
'* Modified: 2005-10-04
'*
'* Purpose: Converts a binary string to a decimal number.
'*
'* Input: strBin = Any Binary (0,1) string.
'*
'* Output: Returns the decimal number represented by the binary
'* string.
'* Returns Empty if the sting is not Binary (0,1)
'********************************************************************
Function Bin2Dec(ByVal strBin)
'Version 1.0 2005-10-04
Dim intLen, intPos, intValue, strTemp, strValue
'Wscript.Echo "strBin: " & strBin
intLen = Len(strBin)
intPos = 1
intValue = 0
strTemp = strReverse(strBin)
Do While intPos <= intLen
strValue = Mid(strTemp, intPos, 1)
Select Case strValue
Case "0"
Case "1"
If intPos = 1 Then
intValue = intValue + 1
Else
intValue = intValue + (2 ^ (intPos - 1))
End If 'intPos = 1
Case Else
intValue = Empty
Exit Do
End Select 'strValue
intPos = intPos + 1
Loop 'intPos <= intLen
Bin2Dec = intValue
End Function 'Bin2Dec
Article ID: 355, Created On: 9/19/2011, Modified: 9/19/2011