DECLARE SUB HextoDec(key AS BYTE)
DECLARE SUB BintoDec(key AS BYTE)
DECLARE SUB ExitNow
CREATE Arial10B AS QFONT
Name = "Arial"
Size = 10
COLOR = clBlack
AddStyles(fsBold)
END CREATE
CREATE Arial12B AS QFONT
Name = "Arial"
Size = 12
COLOR = &HEEFE
AddStyles(fsBold)
END CREATE
CREATE Form AS QFORM
CAPTION = "HexOrBin to Dec"
Width = 320
Height = 240
Center
OnClose = ExitNow
CREATE HexEdit AS QEDIT
Text = "Type hexadecimal number here"
Left = 35
Top = 66
Width = 240
Font = Arial10B
OnKeyPress = HextoDec
END CREATE
CREATE HexPanel AS QPANEL
Left = 34
Top = 35
Width = 240
Height = 25
TabOrder = 2
Font = Arial12B
END CREATE
CREATE BinPanel AS QPANEL
Left = 35
Top = 129
Width = 240
Height = 25
TabOrder = 4
Font = Arial12B
END CREATE
CREATE BinEdit AS QEDIT
Text = "Type binary number here"
Left = 35
Top = 159
Width = 240
TabOrder = 3
Font = Arial10B
OnKeyPress = BintoDec
END CREATE
END CREATE
Form.SHOWMODAL
SUB HextoDec
DEFINT numb, number
DEFBYTE x, length, y
number = 0
IF key = 13 THEN
key = 0
length = LEN(HexEdit.EditText)
FOR x = 1 TO length
y = length - x
digit$ = UCASE$(MID$(HexEdit.EditText,x,1))
SELECT CASE digit$
CASE "A"
numb = 10 * 16^y
CASE "B"
numb = 11 * 16^y
CASE "C"
numb = 12 * 16^y
CASE "D"
numb = 13 * 16^y
CASE "E"
numb = 14 * 16^y
CASE "F"
numb = 15 * 16^y
CASE ELSE
numb = VAL(LCASE$(digit$)) * 16^y
END SELECT
number = number + numb
NEXT
HexPanel.CAPTION = STR$(number)
END IF
END SUB
SUB BintoDec
DEFINT number
DEFBYTE x, length, y
number = 0
IF key = 13 THEN
key = 0
length = LEN(BinEdit.EditText)
FOR x = 1 TO length
y = length - x
digit$ = MID$(BinEdit.EditText,x,1)
number = number + VAL(LCASE$(digit$)) * 2^y
NEXT
BinPanel.CAPTION = STR$(number)
END IF
END SUB
SUB ExitNow
PLAYWAV "ding.wav",1
Application.Terminate
END SUB
Form.SHOWMODAL
|