There's an old Southern expression: going around your ass to get to your elbow

Found on an ASP message board

A routine for converting hex to decimal in VBScript:



Function Hex2Dec(HexString)
Dim Dvalue
Dim q,a,p

If Ucase(Left(HexString,2))="&H" or Ucase(Left(HexString,2))="0X" then
q = mid(HexString,3)
Dvalue=0

While q <> ""
a=left(q,1)
q=mid(q,2)
select case a
case "0"
p=0
case "1"
p=1
case "2"
p=2
case "3"
p=3
case "4"
p=4
case "5"
p=5
case "6"
p=6
case "7"
p=7
case "8"
p=8
case "9"
p=9
case "A","a"
p=10
case "B","b"
p=11
case "C","c"
p=12
case "D","d"
p=13
case "E","e"
p=14
case "F","f"
p=15
case else
p=0
end select
Dvalue=Dvalue+p*16^len(q)

Wend
end if

Hex2Dec = Dvalue

End Function


Meanwhile, back at the elbow…

Um, yeah. You could also try:

CInt("&H" & HexValue)

Writing your own base converter can be a valuable educational experience, but not if you do it like that.

Heh. I can’t laugh too hard, because I’ve done the same sort of back-ass stuff in my own coding, when I didn’t have any training and didn’t have the resources to make a more elegant solution.

Worst was when I was coding for the animal shelter, some report telling which animals required review of their veterinary records that day. The database contained a first treatment date and a number of days the treatment should last but no review date.

A simple function would be something like

Select * (Where Day([TreatmentDate])+ [Number_Days]-1)=Day([Today])

This would work for treatments on December 5 that lasted for 7 days, selecting that record on December 11 for review. But treatments beginning on November 29 and lasting for 7 days would only be selected on November 35–not an acceptable solution.

So I ended up plugging in the whole “Thirty days hath September” business, accounting for leap years for Februaries, in an if-then statement that was referenced whenever today’s date minus the number of treatment days was less than 1. It was a nightmare.

About a year later – two or three weeks ago, actually–I found out about the “SerialDate” function, which converts a date to a string of numbers, making that whole thing unnecessary.

:smack:
Daniel