home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / sbl / sbleval / gcd.sbl < prev    next >
Encoding:
Text File  |  1993-04-08  |  1.6 KB  |  60 lines

  1. REM    **********************************************************************
  2. REM    **************** Exclusive Property of Softbridge ********************
  3. REM    **********************************************************************
  4.  
  5. dim msg$     'Module-level variable, visible to all functions below
  6.  
  7. function gcd% ( u%, v% )
  8.     dim t%
  9.     
  10.     if ( u < v ) then t=u  else t=v
  11.     while ( (u mod t) <> 0) OR ( (v mod t) <> 0) 
  12.        t=t-1
  13.     wend
  14.  
  15.     gcd = t
  16. end function
  17.  
  18. function showdlg% (a%, b%)
  19.   
  20.     begin dialog enter2num 10,10,150,90
  21.         caption " ** G C D **"
  22.         
  23.         text     3,  4, 40,  10,   "first number"
  24.         textbox 60, 2, 25,   12,   .num1$
  25.         text     3, 18, 70,  10,   "second number"
  26.         textbox 60, 18, 25,  12,   .num2$
  27.         text     5, 35, 130, 10,    msg$
  28.         
  29.         ButtonGroup .but
  30.         Button 100,50,40,15,   "OK"
  31.         Button 100,70,40,15,   "Cancel"
  32.     end dialog
  33.     
  34.     dim InputDlg as enter2num
  35.     InputDlg.num1$=str$(a)
  36.     InputDlg.num2$=str$(b)
  37.     Dialog InputDlg
  38.  
  39.     a = val(InputDlg.num1$)
  40.     b = val(InputDlg.num2$)
  41.     showdlg = InputDlg.but
  42. end function
  43.  
  44. SUB Main
  45.  Const  TRUE=1
  46.  dim a%, b%, sa%, sb%, r%
  47.  
  48.  do     
  49.     do 
  50.        r = showdlg(a,b)
  51.        if (r=1) then exit sub           ' CANCEL
  52.        msg$="BAD NUMBER(S), PLEASE RE-ENTER" 
  53.     loop while (a<=0 or b<=0)           
  54.     
  55.     if (sa=a) and (sb=b) then exit sub  ' no change, EXIT
  56.     sa=a : sb = b                       ' save last numbers
  57.     msg$= "answer= "+str$(gcd(a,b))
  58.  loop while TRUE
  59. end sub
  60.