(view source code of dec2hex.vbs as plain text)
' Check command line parameters
Select Case WScript.Arguments.Count
Case 1
' Check if parameter is a valid number
On Error Resume Next
lngDec = CLng( WScript.Arguments(0) )
If Err Then Syntax
On Error GoTo 0
' Check if number is within range
If lngDec > 2147483647 Then Syntax
Case Else
Syntax
End Select
' Convert number to string representing hexadecimal value
strHex = CStr( Hex( lngDec ) )
' Add leading zeros if necessary
intLen = Len( strHex )
if intLen < 8 Then
Do Until intLen = 8
strHex = "0" & strHex
intLen = Len( strHex )
Loop
End If
' Display the result
WScript.Echo vbCrLf & lngDec & " = 0x" & strHex
' Done
WScript.Quit(0)
Sub Syntax
strMsg = vbCrLf & "Dec2Hex.vbs, Version 1.00" & vbCrLf _
& "Convert specified decimal number to 8 digit hexadecimal" _
& vbCrLf & vbCrLf _
& "Usage: CSCRIPT DEC2HEX.VBS number" _
& vbCrLf & vbCrLf _
& "Where: " & Chr(34) & "number" & Chr(34) _
& " is any decimal number ranging from 0..2147483647 (0x7FFFFFFF)" _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit(1)
End Sub
page last modified: 2024-04-16; loaded in 0.0057 seconds