home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / number.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  3.7 KB  |  113 lines

  1. VERSION 4.00
  2. Begin VB.Form frmNumber 
  3.    Caption         =   "Number System"
  4.    ClientHeight    =   3390
  5.    ClientLeft      =   2160
  6.    ClientTop       =   1950
  7.    ClientWidth     =   4515
  8.    BeginProperty Font 
  9.       name            =   "MS Sans Serif"
  10.       charset         =   1
  11.       weight          =   700
  12.       size            =   8.25
  13.       underline       =   0   'False
  14.       italic          =   0   'False
  15.       strikethrough   =   0   'False
  16.    EndProperty
  17.    Height          =   3795
  18.    Left            =   2100
  19.    LinkTopic       =   "Form5"
  20.    ScaleHeight     =   3390
  21.    ScaleWidth      =   4515
  22.    Top             =   1605
  23.    Width           =   4635
  24.    Begin VB.CommandButton cmdClose 
  25.       Caption         =   "&Close"
  26.       Height          =   495
  27.       Left            =   2760
  28.       TabIndex        =   4
  29.       Top             =   1920
  30.       Width           =   1215
  31.    End
  32.    Begin VB.OptionButton optHexButton 
  33.       Caption         =   "Use &hexadecimal"
  34.       Height          =   495
  35.       Left            =   588
  36.       TabIndex        =   3
  37.       Top             =   2520
  38.       Width           =   1815
  39.    End
  40.    Begin VB.OptionButton optDecButton 
  41.       Caption         =   "Use &decimal"
  42.       Height          =   495
  43.       Left            =   600
  44.       TabIndex        =   2
  45.       Top             =   1920
  46.       Value           =   -1  'True
  47.       Width           =   1815
  48.    End
  49.    Begin VB.OptionButton optOctButton 
  50.       Caption         =   "Use &octal"
  51.       Height          =   495
  52.       Left            =   600
  53.       TabIndex        =   1
  54.       Top             =   1332
  55.       Width           =   1815
  56.    End
  57.    Begin VB.TextBox txtNumber 
  58.       Height          =   375
  59.       Left            =   600
  60.       TabIndex        =   0
  61.       Top             =   600
  62.       Width           =   3375
  63.    End
  64.    Begin VB.Label lblNumber 
  65.       Caption         =   "Enter a number:"
  66.       Height          =   255
  67.       Left            =   600
  68.       TabIndex        =   5
  69.       Top             =   240
  70.       Width           =   2175
  71.    End
  72. Attribute VB_Name = "frmNumber"
  73. Attribute VB_Creatable = False
  74. Attribute VB_Exposed = False
  75. Option Explicit
  76. Dim CurrentNum As Variant
  77. Private Sub cmdClose_Click()
  78.    Unload Me    ' Unload this form.
  79. End Sub
  80. Private Sub optDecButton_Click()
  81.     txtNumber.Text = Format(CurrentNum)
  82. End Sub
  83. Private Sub optHexButton_Click()
  84.     txtNumber.Text = Hex(CurrentNum)
  85. End Sub
  86. Private Sub optOctButton_Click()
  87.     txtNumber.Text = Oct(CurrentNum)
  88. End Sub
  89. Private Sub txtNumber_Change()
  90.     ' Val function interprets numbers beginning with &O as octal, and
  91.     ' numbers beginning with &H as hexidecimal.
  92.     If optOctButton.Value = True Then
  93.         CurrentNum = Val("&O" & LTrim(txtNumber.Text) & "&")
  94.     ElseIf optDecButton.Value = True Then
  95.         CurrentNum = Val(LTrim(txtNumber.Text) & "&")
  96.     Else
  97.         CurrentNum = Val("&H" & LTrim(txtNumber.Text) & "&")
  98.     End If
  99. End Sub
  100. Private Sub txtNumber_KeyPress(KeyAscii As Integer)
  101.      ' This code prevents the user from entering
  102.      ' a negative number or a decimal point.
  103.     If KeyAscii < 48 Then   ' Rejects all ascii < 0.
  104.         KeyAscii = 0
  105.         ' Octal: digits between 0 and 7.
  106.         ' Decimal: digits between 0 and 9.
  107.         ' Hexidecimal: digits between 0 and 9, A and F, and a and f.
  108.         ElseIf optOctButton.Value And KeyAscii > 55 Then KeyAscii = 0
  109.         ElseIf optDecButton.Value And KeyAscii > 57 Then KeyAscii = 0
  110.         ElseIf optHexButton.Value And (KeyAscii > 57 And (KeyAscii < 65 Or KeyAscii > 70) And (KeyAscii < 97 Or KeyAscii > 102)) Then KeyAscii = 0
  111.     End If
  112. End Sub
  113.