$INCLUDE "rapidq.inc"
DECLARE SUB hexvert
DECLARE SUB decvert
DECLARE SUB checkit
DECLARE SUB clearall
DECLARE SUB checkenter (key AS WORD, shift AS INTEGER)
CREATE form AS QFORM
height=79
width=160
center
borderstyle=bsdialog
CAPTION="hex 2 dec"
CREATE hexval AS QEDIT
top=5
left=5
width=70
height=26
onkeypress=checkenter
END CREATE
CREATE decval AS QEDIT
top=5
left=80
width=70
height=26
onkeypress=checkenter
END CREATE
CREATE conv AS QBUTTON
CAPTION="convert"
top=30
left=80
width=70
height=22
onclick=checkit
END CREATE
CREATE clear AS QBUTTON
CAPTION="clear"
top=30
left=5
width=70
height=22
onclick=clearall
END CREATE
SHOWMODAL
END CREATE
SUB clearall
hexval.text=""
decval.text=""
END SUB
SUB checkit
IF hexval.text<>"" AND decval.text<>"" THEN SHOWMESSAGE "please clear one field"
IF hexval.text="" THEN decvert
IF decval.text="" THEN hexvert
END SUB
SUB checkenter (key AS WORD, shift AS INTEGER)
SELECT CASE key
CASE 13
checkit
END SELECT
END SUB
SUB decvert
hexval.text=HEX$(VAL(decval.text))
END SUB
SUB hexvert
DIM total AS LONG
DIM workval AS LONG
latch=0
total=0
work$=""
FOR t=1 TO LEN(hexval.text)
value=16
place=LEN(hexval.text)-t
workval=0
work$=LEFT$((MID$(hexval.text, t,t)),1)
SELECT CASE work$
CASE "0"
workval=0
CASE "1"
workval=1
CASE "2"
workval=2
CASE "3"
workval=3
CASE "4"
workval=4
CASE "5"
workval=5
CASE "6"
workval=6
CASE "7"
workval=7
CASE "8"
workval=8
CASE "9"
workval=9
CASE "a"
workval=10
CASE "b"
workval=11
CASE "c"
workval=12
CASE "d"
workval=13
CASE "e"
workval=14
CASE "f"
workval=15
CASE "A"
workval=10
CASE "B"
workval=11
CASE "C"
workval=12
CASE "D"
workval=13
CASE "E"
workval=14
CASE "F"
workval=15
CASE ELSE
SHOWMESSAGE "improper calculation due to non-hex value"
latch=1
END SELECT
value=16^place
total=total+(workval*value)
NEXT t
decval.text=STR$(total)
IF latch=1 THEN decval.text=""
END SUB
|