Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Programming Exercises Calculator: Codes
Programming Exercises Calculator: Codes
Calculator
FORM
CODES
VERSION 5.00
Begin VB.Form frmCalculator
BorderStyle = 1 'Fixed Single
Caption = "Calculator"
ClientHeight = 3615
ClientLeft = 7935
ClientTop = 3270
ClientWidth = 5130
ForeColor = &H00000000&
Icon = "frmCalculator.frx":0000
KeyPreview = -1 'True
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3615
ScaleWidth = 5130
Begin VB.CommandButton cmdCalc
Caption = "="
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 22
Left = 4020
TabIndex = 23
Top = 2940
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "+"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 21
Left = 3060
TabIndex = 22
Top = 2940
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "."
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 20
Left = 2100
TabIndex = 21
Top = 2940
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "+/-"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 19
Left = 1140
TabIndex = 20
Top = 2940
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "0"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 18
Left = 180
TabIndex = 19
Top = 2940
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "1/x"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 17
Left = 4020
TabIndex = 18
Top = 2400
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "-"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 16
Left = 3060
TabIndex = 17
Top = 2400
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "3"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 15
Left = 2100
TabIndex = 16
Top = 2400
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "2"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 14
Left = 1140
TabIndex = 15
Top = 2400
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "1"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 13
Left = 180
TabIndex = 14
Top = 2400
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "%"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 12
Left = 4020
TabIndex = 13
Top = 1860
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "X"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 11
Left = 3060
TabIndex = 12
Top = 1860
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "6"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 10
Left = 2100
TabIndex = 11
Top = 1860
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "5"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 9
Left = 1140
TabIndex = 10
Top = 1860
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "4"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 8
Left = 180
TabIndex = 9
Top = 1860
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "sqrt"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 7
Left = 4020
TabIndex = 8
Top = 1320
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "/"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 6
Left = 3060
TabIndex = 7
Top = 1320
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "9"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 5
Left = 2100
TabIndex = 6
Top = 1320
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "8"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 4
Left = 1140
TabIndex = 5
Top = 1320
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "7"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 3
Left = 180
TabIndex = 4
Top = 1320
Width = 915
End
Begin VB.CommandButton cmdCalc
Caption = "C"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 2
Left = 3480
TabIndex = 3
Top = 720
Width = 1455
End
Begin VB.CommandButton cmdCalc
Caption = "CE"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 1
Left = 1860
TabIndex = 2
Top = 720
Width = 1515
End
Begin VB.CommandButton cmdCalc
Caption = "Backspace"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 0
Left = 180
TabIndex = 1
Top = 720
Width = 1515
End
Begin VB.Label lblDisplay
Alignment = 1 'Right Justify
BackColor = &H00000000&
BorderStyle = 1 'Fixed Single
Caption = "0."
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 375
Left = 180
TabIndex = 0
Top = 180
Width = 4755
End
End
Attribute VB_Name = "frmCalculator"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
cmdCalc(intIndex).SetFocus
cmdCalc_Click intIndex
End Sub
cmdCalc(intIndex).SetFocus
cmdCalc_Click intIndex
End Sub
mintCurrKeyIndex = Index
End Sub
TEMPERATURE CONVERTER
FORM
CODES
Private Sub cmdClear_Click()
'Clear the option buttons, txtTemp and lblResults
optC.Value = False
optF.Value = False
txtTemp.Text = ""
lblResults.Caption = ""
lblWhat.Caption = “”
End Sub
Private Sub cmdConvert_Click()
Dim sngTemp As Single
Dim sngF As Single
Dim sngC As Single
If txtTemp.Text <> "" Then
If optC.Value = True And IsNumeric(txtTemp.Text) Then
sngTemp = Val(txtTemp.Text)
sngF = sngTemp * 9 / 5 + 32
lblResults.Caption = " " & sngTemp & " degrees Centigrade is equal to " &
vbCrLf & _ “” & sngF & " degrees Fahrenheit."
ElseIf optF.Value = True And IsNumeric(txtTemp.Text) Then
sngTemp = Val(txtTemp.Text)
sngC = (sngTemp - 32) * (5 / 9)
lblResults.Caption = " " & sngTemp & " degrees Fahrenheit is equal to " &
sngC & " degrees Centigrade."
End If
ElseIf Not IsNumeric(txtTemp.Text) Or txtTemp.Text = "" Then
MsgBox "Enter a numeric value for the temperature conversion", , "Invalid Data"
txtTemp.SetFocus
Exit Sub
End If
End Sub
Private Sub cmdExit_Click()
'Exit the program
Unload Me
End
End Sub
Private Sub Form_Activate()
optC.Value = False
optF.Value = False
txtTemp.SetFocus
End Sub
Private Sub mnuFileExit_Click()
'Exit the program
Unload Me
End
End Sub
Private Sub mnuHelpAbout_Click()
MsgBox "Temperature Conversion Program" & vbCrLf & _
"Version 1.00.00" & vbCrLf & _
"Date: 07 June 2001" & vbCrLf & _
"by Cheryl Gribble" & vbCrLf & _
"", , "About this program..."
End Sub
Private Sub mnuHelpDirections_Click()
MsgBox "Select an option button to specify & vbCrLf & _
“whether you will be entering either" & vbCrLf & _
"Centigrade or Fahrenheit values." & vbCrLf & _
"Enter the number in the text box & vbCrLf & _
“that you wish to convert." & vbCrLf & _
"Only one decimal is allowed." & vbCrLf & _
"Only numeric characters are allowed." & vbCrLf & _
"The Convert Temperature button will display & vbCrLf & _
“results inside the frame." & vbCrLf & _
"Use the Clear button if you want to enter additional values." & vbCrLf & _
"The Exit button will close the program." & vbCrLf & _
"",vbInformation, "Temperature Conversion Program Instructions..."
End Sub
Private Sub optC_Click()
lblWhat.Caption = "and convert to Fahrenheit."
txtTemp.SetFocus
End Sub
Private Sub optF_Click()
lblWhat.Caption = "and convert to Centigrade."
txtTemp.SetFocus
End Sub
‘The following sub limits user input to certain specific ‘characters.
Private Sub txtTemp_KeyPress(KeyAscii As Integer)
'Allow numbers, backspace,decimal
Select Case KeyAscii
Case vbKeyBack
'backspace ok, needed to change errors
Case 46
'decimal is ok
Case 48 To 57
'numbers ok
Case Else
Beep
KeyAscii = vbEmpty
End Select
End Sub