Guidance
指路人
g.yi.org
software / rapidq / Examples / Algorithm & Maths / binary.rqb

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
     $OPTIMIZE ON
     $TYPECHECK ON
     $INCLUDE "rapidq.inc"
     $ESCAPECHARS ON
'--- Subs ---
     DECLARE SUB GoButton_onClick
     DECLARE SUB CheckBox_onClick
'--- Dims ---
     DIM CheckBox(6) AS QCHECKBOX
     DEFINT i% = 0, go% = True
'--- GUI --
     CREATE Form AS QFORM
      CAPTION = "Simple Binary Math"
      Width = 150
      Height = 230
      Center
      CREATE Edit AS QEDIT
       Text = "32"
       Left = 5
       Top = 15
       Width = 50
      END CREATE
      CREATE GoButton AS QBUTTON
       CAPTION = "&Go!"
       Left = 60
       Top = 15
       OnClick = GoButton_onClick
      END CREATE
     END CREATE

     CheckBox(0).PARENT = Form
     CheckBox(0).CAPTION = "1"
     CheckBox(0).Left = 5
     CheckBox(0).Top = 45
     CheckBox(0).OnClick = CheckBox_onClick
     CheckBox(1).PARENT = Form
     CheckBox(1).CAPTION = "2"
     CheckBox(1).Left = 5
     CheckBox(1).Top = 67
     CheckBox(1).OnClick = CheckBox_onClick
     CheckBox(2).PARENT = Form
     CheckBox(2).CAPTION = "4"
     CheckBox(2).Left = 5
     CheckBox(2).Top = 89
     CheckBox(2).OnClick = CheckBox_onClick
     CheckBox(3).PARENT = Form
     CheckBox(3).CAPTION = "8"
     CheckBox(3).Left = 5
     CheckBox(3).Top = 111
     CheckBox(3).OnClick = CheckBox_onClick
     CheckBox(4).PARENT = Form
     CheckBox(4).CAPTION = "16"
     CheckBox(4).Left = 5
     CheckBox(4).Top = 133
     CheckBox(4).OnClick = CheckBox_onClick
     CheckBox(5).PARENT = Form
     CheckBox(5).CAPTION = "32"
     CheckBox(5).Left = 5
     CheckBox(5).Top = 155
     CheckBox(5).OnClick = CheckBox_onClick
     CheckBox(6).PARENT = Form
     CheckBox(6).CAPTION = "64"
     CheckBox(6).Left = 5
     CheckBox(6).Top = 177
     CheckBox(6).OnClick = CheckBox_onClick

     Form.SHOWMODAL

'--- Subs ---
     SUB GoButton_onClick
      go% = False
      IF (VAL(Edit.Text) < 0) OR (VAL(Edit.Text) > 127) THEN
       MESSAGEDLG("Please enter a whole number less than 127.",mtError,mbOK,0)
      ELSE
       FOR i% = 0 TO 6
        IF (INT(VAL(Edit.Text)) AND 2^i%) = 2^i% THEN
         CheckBox(i%).Checked = True
        ELSE
         CheckBox(i%).Checked = False
        END IF
       NEXT i%
      END IF
      go% = True
     END SUB

     SUB CheckBox_onClick
      IF go% = True THEN
       Edit.Text = STR$(0)
       FOR i% = 0 TO 6
        IF CheckBox(i%).Checked = True THEN
         Edit.Text = STR$(VAL(Edit.Text) + 2^i%)
        END IF
       NEXT i%
      END IF
     END SUB
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sun 2022-9-25  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2009-07-25 17:30:54