home *** CD-ROM | disk | FTP | other *** search
/ The Best of Select: Windows 95 Special 2 / WIN95_2.bin / utils / envelop / envelop.6 / Tools / Bootcamp / basic / opbutton / opbutton.eto < prev    next >
Encoding:
Text File  |  1996-07-08  |  4.1 KB  |  138 lines

  1. Type OptionButtonMasterForm From SampleMasterForm
  2.   Dim Label1 As New Label
  3.   Dim txtValueBox As New TextBox
  4.   Dim optOctal As New OptionButton
  5.   Dim optDecimal As New OptionButton
  6.   Dim optHex As New OptionButton
  7.   Dim FontValueBox As New Font
  8.   Dim CurrentNumber As String
  9.  
  10.   ' METHODS for object: OptionButtonMasterForm
  11.   Sub optDecimal_Click()
  12.     If txtValueBox.Text <> "" Then 
  13.       txtValueBox.Text = CurrentNumber
  14.     End If
  15.   End Sub
  16.  
  17.   Sub optHex_Click()
  18.     If txtValueBox.Text <> "" Then 
  19.       txtValueBox.Text = Hex(CurrentNumber)
  20.     End If
  21.   End Sub
  22.  
  23.   Sub optOctal_Click()
  24.     If txtValueBox.Text <> "" Then 
  25.       txtValueBox.Text = Oct(CurrentNumber)
  26.     End If
  27.   End Sub
  28.  
  29.   Sub ResetApplication_Click ()
  30.     ' If the form is not loaded yet, then get it loaded and pop out of here.
  31.     If hWnd = 0 Then 
  32.       LoadForm
  33.       Exit Sub
  34.     End If
  35.   
  36.     ' Setup the option buttons
  37.     optOctal.Value = False
  38.     optDecimal.Value = True
  39.     optHex.Value = False
  40.   
  41.     txtValueBox.Text = ""
  42.     txtValueBox.SetFocus
  43.   End Sub
  44.  
  45.   Sub txtValueBox_Change()
  46.     If txtValueBox.Text <> "" Then 
  47.       ' Val function interprets numbers beginning with &O as octal;
  48.       ' numbers beginning with &H as hexidecimal.
  49.       If optOctal.Value = True Then 
  50.         CurrentNumber = Val("&O" & LTrim(txtValueBox.Text) & "&")
  51.       ElseIf optHex.Value = True Then 
  52.         CurrentNumber = Val("&H" & LTrim(txtValueBox.Text) & "&")
  53.       Else 
  54.         CurrentNumber = Val(LTrim(txtValueBox.Text) & "&")
  55.       End If
  56.     Else 
  57.       CurrentNumber = ""
  58.     End If
  59.   End Sub
  60.  
  61.   Sub txtValueBox_KeyPress(KeyAscii As Integer)
  62.     ' This code prevents the user from entering characters that are
  63.     ' invalid for given radix (also no negatives or floating decimal points).
  64.     Dim maxDigit, isDigit, isHexDig As Long
  65.   
  66.     ' Allow backspace straight through...
  67.     If KeyAscii = 8 Then Exit Sub
  68.   
  69.     ' Restrict digits to 0-7 if chosen radix is octal...
  70.     If optOctal.Value Then maxDigit = Asc("7") Else maxDigit = Asc("9")
  71.     isDigit = KeyAscii >= Asc("0") && KeyAscii <= maxDigit
  72.   
  73.     ' Only do extra checking if key pressed isn't a valid digit...
  74.     If Not isDigit Then 
  75.       If optHex.Value = 0 Then 
  76.         KeyAscii = 0
  77.       Else 
  78.         isHexDig = KeyAscii >= Asc("a") && KeyAscii <= Asc("f")
  79.         isHexDig = isHexDig || (KeyAscii >= Asc("A") && KeyAscii <= Asc("F"))
  80.         If Not isHexDig Then KeyAscii = 0
  81.       End If
  82.     End If
  83.   
  84.   End Sub
  85.  
  86. End Type
  87.  
  88. Begin Code
  89. ' Reconstruction commands for object: OptionButtonMasterForm
  90. '
  91.   With OptionButtonMasterForm
  92.     .Caption := "OptionButton Demonstration"
  93.     .Move(3180, 2130, 6420, 4200)
  94.     .SampleDir := "C:\ENVELOP\bootcamp\basic\opbutton\"
  95.     .SampleName := "OPBUTTON"
  96.     .CurrentNumber := ""
  97.     With .Label1
  98.       .Caption := "1. Please enter a number."
  99.       .ForeColor := 13107200
  100.       .ZOrder := 1
  101.       .Move(300, 300, 2850, 300)
  102.     End With  'OptionButtonMasterForm.Label1
  103.     With .txtValueBox
  104.       .Font := OptionButtonMasterForm.FontValueBox
  105.       .ZOrder := 2
  106.       .Move(600, 750, 4950, 600)
  107.     End With  'OptionButtonMasterForm.txtValueBox
  108.     With .optOctal
  109.       .Caption := " Use &Octal number."
  110.       .ZOrder := 3
  111.       .Move(1200, 1800, 3450, 300)
  112.       .TabGroup := True
  113.     End With  'OptionButtonMasterForm.optOctal
  114.     With .optDecimal
  115.       .Caption := " Use &Decimal number."
  116.       .ZOrder := 4
  117.       .Move(1200, 2250, 3450, 300)
  118.       .TabStop := True
  119.       .Value := True
  120.     End With  'OptionButtonMasterForm.optDecimal
  121.     With .optHex
  122.       .Caption := " Use He&xadecimal number."
  123.       .ZOrder := 5
  124.       .Move(1200, 2700, 4200, 300)
  125.     End With  'OptionButtonMasterForm.optHex
  126.     With .FontValueBox
  127.       .FaceName := "Arial"
  128.       .Size := 24.000000
  129.       .Bold := True
  130.       .Italic := False
  131.       .Strikethru := False
  132.     End With  'OptionButtonMasterForm.FontValueBox
  133.     With .helpfile
  134.       .FileName := "C:\ENVELOP\bootcamp\basic\opbutton\OPBUTTON.hlp"
  135.     End With  'OptionButtonMasterForm.helpfile
  136.   End With  'OptionButtonMasterForm
  137. End Code
  138.