home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form frmNumber
- Caption = "Number System"
- ClientHeight = 3390
- ClientLeft = 2160
- ClientTop = 1950
- ClientWidth = 4515
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 1
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 3795
- Left = 2100
- LinkTopic = "Form5"
- ScaleHeight = 3390
- ScaleWidth = 4515
- Top = 1605
- Width = 4635
- Begin VB.CommandButton cmdClose
- Caption = "&Close"
- Height = 495
- Left = 2760
- TabIndex = 4
- Top = 1920
- Width = 1215
- End
- Begin VB.OptionButton optHexButton
- Caption = "Use &hexadecimal"
- Height = 495
- Left = 588
- TabIndex = 3
- Top = 2520
- Width = 1815
- End
- Begin VB.OptionButton optDecButton
- Caption = "Use &decimal"
- Height = 495
- Left = 600
- TabIndex = 2
- Top = 1920
- Value = -1 'True
- Width = 1815
- End
- Begin VB.OptionButton optOctButton
- Caption = "Use &octal"
- Height = 495
- Left = 600
- TabIndex = 1
- Top = 1332
- Width = 1815
- End
- Begin VB.TextBox txtNumber
- Height = 375
- Left = 600
- TabIndex = 0
- Top = 600
- Width = 3375
- End
- Begin VB.Label lblNumber
- Caption = "Enter a number:"
- Height = 255
- Left = 600
- TabIndex = 5
- Top = 240
- Width = 2175
- End
- Attribute VB_Name = "frmNumber"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Dim CurrentNum As Variant
- Private Sub cmdClose_Click()
- Unload Me ' Unload this form.
- End Sub
- Private Sub optDecButton_Click()
- txtNumber.Text = Format(CurrentNum)
- End Sub
- Private Sub optHexButton_Click()
- txtNumber.Text = Hex(CurrentNum)
- End Sub
- Private Sub optOctButton_Click()
- txtNumber.Text = Oct(CurrentNum)
- End Sub
- Private Sub txtNumber_Change()
- ' Val function interprets numbers beginning with &O as octal, and
- ' numbers beginning with &H as hexidecimal.
- If optOctButton.Value = True Then
- CurrentNum = Val("&O" & LTrim(txtNumber.Text) & "&")
- ElseIf optDecButton.Value = True Then
- CurrentNum = Val(LTrim(txtNumber.Text) & "&")
- Else
- CurrentNum = Val("&H" & LTrim(txtNumber.Text) & "&")
- End If
- End Sub
- Private Sub txtNumber_KeyPress(KeyAscii As Integer)
- ' This code prevents the user from entering
- ' a negative number or a decimal point.
- If KeyAscii < 48 Then ' Rejects all ascii < 0.
- KeyAscii = 0
- ' Octal: digits between 0 and 7.
- ' Decimal: digits between 0 and 9.
- ' Hexidecimal: digits between 0 and 9, A and F, and a and f.
- ElseIf optOctButton.Value And KeyAscii > 55 Then KeyAscii = 0
- ElseIf optDecButton.Value And KeyAscii > 57 Then KeyAscii = 0
- ElseIf optHexButton.Value And (KeyAscii > 57 And (KeyAscii < 65 Or KeyAscii > 70) And (KeyAscii < 97 Or KeyAscii > 102)) Then KeyAscii = 0
- End If
- End Sub
-