Guidance
指路人
g.yi.org
software / rapidq / Examples / String & Text / HexBinToDec.bas

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
'Hex to Dec and Bin to Dec Converter
'(Dec. 29, 2000)
'By Achilles Mina

'This utility is one of the modules of Calculait 3.0, a full-featured
'scientific calculator with a world clock. It will soon be available
'for downloading from ZDNet, Nonags, RocketDownload, CNet and other freeware
'sites. Version 2.0 is currently downloadable at these sites.

'You can do as you please with this code.

     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

掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2019-4-25  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2000-12-29 19:31:06