TexRedneck
asked on
old time calculator
I am tring to get a calculator to output to a tape like an old time calculator that dosent have an equal key, when you enter a number key and then an operator =,-,*,/ it moves the number and the operator from the input box to the tape and then you input the secomd number and hit the operator again and it totals the numbers and puts it in the tape lbl.
ASKER
I tried it but it diden't work maby you can look at my code and tell where I went wrong?
Option Explicit On
Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuI tem
Friend WithEvents lblCurrNum As System.Windows.Forms.Label
Friend WithEvents mmuMain As System.Windows.Forms.MainM enu
Friend WithEvents fdSelectFont As System.Windows.Forms.FontD ialog
Friend WithEvents cdSelectFontColor As System.Windows.Forms.Color Dialog
Friend WithEvents btn7 As System.Windows.Forms.Butto n
Friend WithEvents btn8 As System.Windows.Forms.Butto n
Friend WithEvents btn9 As System.Windows.Forms.Butto n
Friend WithEvents btnDivide As System.Windows.Forms.Butto n
Friend WithEvents btn4 As System.Windows.Forms.Butto n
Friend WithEvents btn5 As System.Windows.Forms.Butto n
Friend WithEvents btn6 As System.Windows.Forms.Butto n
Friend WithEvents btnMultiply As System.Windows.Forms.Butto n
Friend WithEvents btn1 As System.Windows.Forms.Butto n
Friend WithEvents btn2 As System.Windows.Forms.Butto n
Friend WithEvents btn3 As System.Windows.Forms.Butto n
Friend WithEvents btnSubtract As System.Windows.Forms.Butto n
Friend WithEvents btn0 As System.Windows.Forms.Butto n
Friend WithEvents btnDecimalPlace As System.Windows.Forms.Butto n
Friend WithEvents btnClear As System.Windows.Forms.Butto n
Friend WithEvents btnAdd As System.Windows.Forms.Butto n
Friend WithEvents mmuFormatColors As System.Windows.Forms.MenuI tem
Friend WithEvents mmuFormatFontColors As System.Windows.Forms.MenuI tem
Friend WithEvents mmuFormatFonts As System.Windows.Forms.MenuI tem
Friend WithEvents cdSelectColors As System.Windows.Forms.Color Dialog
Friend WithEvents ListBox1 As System.Windows.Forms.ListB ox
Friend WithEvents lblTape As System.Windows.Forms.Label
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.lblCurrNum = New System.Windows.Forms.Label
Me.mmuMain = New System.Windows.Forms.MainM enu
Me.MenuItem1 = New System.Windows.Forms.MenuI tem
Me.mmuFormatColors = New System.Windows.Forms.MenuI tem
Me.mmuFormatFontColors = New System.Windows.Forms.MenuI tem
Me.mmuFormatFonts = New System.Windows.Forms.MenuI tem
Me.fdSelectFont = New System.Windows.Forms.FontD ialog
Me.cdSelectColors = New System.Windows.Forms.Color Dialog
Me.cdSelectFontColor = New System.Windows.Forms.Color Dialog
Me.btn7 = New System.Windows.Forms.Butto n
Me.btn8 = New System.Windows.Forms.Butto n
Me.btn9 = New System.Windows.Forms.Butto n
Me.btnDivide = New System.Windows.Forms.Butto n
Me.btn4 = New System.Windows.Forms.Butto n
Me.btn5 = New System.Windows.Forms.Butto n
Me.btn6 = New System.Windows.Forms.Butto n
Me.btnMultiply = New System.Windows.Forms.Butto n
Me.btn1 = New System.Windows.Forms.Butto n
Me.btn2 = New System.Windows.Forms.Butto n
Me.btn3 = New System.Windows.Forms.Butto n
Me.btnSubtract = New System.Windows.Forms.Butto n
Me.btn0 = New System.Windows.Forms.Butto n
Me.btnDecimalPlace = New System.Windows.Forms.Butto n
Me.btnClear = New System.Windows.Forms.Butto n
Me.btnAdd = New System.Windows.Forms.Butto n
Me.ListBox1 = New System.Windows.Forms.ListB ox
Me.lblTape = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'lblCurrNum
'
Me.lblCurrNum.BackColor = System.Drawing.Color.White
Me.lblCurrNum.BorderStyle = System.Windows.Forms.Borde rStyle.Fix ed3D
Me.lblCurrNum.Location = New System.Drawing.Point(0, 0)
Me.lblCurrNum.Name = "lblCurrNum"
Me.lblCurrNum.Size = New System.Drawing.Size(468, 23)
Me.lblCurrNum.TabIndex = 0
Me.lblCurrNum.TextAlign = System.Drawing.ContentAlig nment.Midd leLeft
'
'mmuMain
'
Me.mmuMain.MenuItems.AddRa nge(New System.Windows.Forms.MenuI tem() {Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.Add Range(New System.Windows.Forms.MenuI tem() {Me.mmuFormatColors, Me.mmuFormatFontColors, Me.mmuFormatFonts})
Me.MenuItem1.Text = "Format"
'
'mmuFormatColors
'
Me.mmuFormatColors.Index = 0
Me.mmuFormatColors.Text = "Background Colors"
'
'mmuFormatFontColors
'
Me.mmuFormatFontColors.Ind ex = 1
Me.mmuFormatFontColors.Tex t = "Text Colors"
'
'mmuFormatFonts
'
Me.mmuFormatFonts.Index = 2
Me.mmuFormatFonts.Text = "Fonts"
'
'fdSelectFont
'
Me.fdSelectFont.ShowApply = True
'
'cdSelectColors
'
Me.cdSelectColors.FullOpen = True
'
'btn7
'
Me.btn7.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn7.Location = New System.Drawing.Point(30, 66)
Me.btn7.Name = "btn7"
Me.btn7.Size = New System.Drawing.Size(36, 36)
Me.btn7.TabIndex = 2
Me.btn7.Text = "7"
'
'btn8
'
Me.btn8.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn8.Location = New System.Drawing.Point(72, 66)
Me.btn8.Name = "btn8"
Me.btn8.Size = New System.Drawing.Size(36, 36)
Me.btn8.TabIndex = 3
Me.btn8.Text = "8"
'
'btn9
'
Me.btn9.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn9.Location = New System.Drawing.Point(114, 66)
Me.btn9.Name = "btn9"
Me.btn9.Size = New System.Drawing.Size(36, 36)
Me.btn9.TabIndex = 4
Me.btn9.Text = "9"
'
'btnDivide
'
Me.btnDivide.BackColor = System.Drawing.Color.Navaj oWhite
Me.btnDivide.DialogResult = System.Windows.Forms.Dialo gResult.OK
Me.btnDivide.Location = New System.Drawing.Point(156, 66)
Me.btnDivide.Name = "btnDivide"
Me.btnDivide.Size = New System.Drawing.Size(36, 36)
Me.btnDivide.TabIndex = 5
Me.btnDivide.Text = "/"
'
'btn4
'
Me.btn4.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn4.Location = New System.Drawing.Point(30, 108)
Me.btn4.Name = "btn4"
Me.btn4.Size = New System.Drawing.Size(36, 36)
Me.btn4.TabIndex = 6
Me.btn4.Text = "4"
'
'btn5
'
Me.btn5.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn5.Location = New System.Drawing.Point(72, 108)
Me.btn5.Name = "btn5"
Me.btn5.Size = New System.Drawing.Size(36, 36)
Me.btn5.TabIndex = 7
Me.btn5.Text = "5"
'
'btn6
'
Me.btn6.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn6.Location = New System.Drawing.Point(114, 108)
Me.btn6.Name = "btn6"
Me.btn6.Size = New System.Drawing.Size(36, 36)
Me.btn6.TabIndex = 8
Me.btn6.Text = "6"
'
'btnMultiply
'
Me.btnMultiply.BackColor = System.Drawing.Color.Navaj oWhite
Me.btnMultiply.DialogResul t = System.Windows.Forms.Dialo gResult.OK
Me.btnMultiply.Location = New System.Drawing.Point(156, 108)
Me.btnMultiply.Name = "btnMultiply"
Me.btnMultiply.Size = New System.Drawing.Size(36, 36)
Me.btnMultiply.TabIndex = 9
Me.btnMultiply.Text = "*"
'
'btn1
'
Me.btn1.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn1.Location = New System.Drawing.Point(30, 150)
Me.btn1.Name = "btn1"
Me.btn1.Size = New System.Drawing.Size(36, 36)
Me.btn1.TabIndex = 10
Me.btn1.Text = "1"
'
'btn2
'
Me.btn2.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn2.Location = New System.Drawing.Point(72, 150)
Me.btn2.Name = "btn2"
Me.btn2.Size = New System.Drawing.Size(36, 36)
Me.btn2.TabIndex = 11
Me.btn2.Text = "2"
'
'btn3
'
Me.btn3.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn3.Location = New System.Drawing.Point(114, 150)
Me.btn3.Name = "btn3"
Me.btn3.Size = New System.Drawing.Size(36, 36)
Me.btn3.TabIndex = 12
Me.btn3.Text = "3"
'
'btnSubtract
'
Me.btnSubtract.BackColor = System.Drawing.Color.Navaj oWhite
Me.btnSubtract.DialogResul t = System.Windows.Forms.Dialo gResult.OK
Me.btnSubtract.Location = New System.Drawing.Point(156, 150)
Me.btnSubtract.Name = "btnSubtract"
Me.btnSubtract.Size = New System.Drawing.Size(36, 36)
Me.btnSubtract.TabIndex = 13
Me.btnSubtract.Text = "-"
'
'btn0
'
Me.btn0.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn0.Location = New System.Drawing.Point(30, 192)
Me.btn0.Name = "btn0"
Me.btn0.Size = New System.Drawing.Size(36, 36)
Me.btn0.TabIndex = 14
Me.btn0.Text = "0"
'
'btnDecimalPlace
'
Me.btnDecimalPlace.BackCol or = System.Drawing.Color.Navaj oWhite
Me.btnDecimalPlace.Locatio n = New System.Drawing.Point(72, 192)
Me.btnDecimalPlace.Name = "btnDecimalPlace"
Me.btnDecimalPlace.Size = New System.Drawing.Size(36, 36)
Me.btnDecimalPlace.TabInde x = 15
Me.btnDecimalPlace.Text = "."
'
'btnClear
'
Me.btnClear.BackColor = System.Drawing.Color.Navaj oWhite
Me.btnClear.Location = New System.Drawing.Point(114, 192)
Me.btnClear.Name = "btnClear"
Me.btnClear.Size = New System.Drawing.Size(36, 36)
Me.btnClear.TabIndex = 16
Me.btnClear.Text = "C"
'
'btnAdd
'
Me.btnAdd.BackColor = System.Drawing.Color.Navaj oWhite
Me.btnAdd.DialogResult = System.Windows.Forms.Dialo gResult.OK
Me.btnAdd.Location = New System.Drawing.Point(156, 192)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(36, 36)
Me.btnAdd.TabIndex = 17
Me.btnAdd.Text = "+"
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(408, 144)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(120, 95)
Me.ListBox1.TabIndex = 0
'
'lblTape
'
Me.lblTape.BackColor = System.Drawing.Color.White
Me.lblTape.BorderStyle = System.Windows.Forms.Borde rStyle.Fix ed3D
Me.lblTape.FlatStyle = System.Windows.Forms.FlatS tyle.Syste m
Me.lblTape.Location = New System.Drawing.Point(324, 24)
Me.lblTape.Name = "lblTape"
Me.lblTape.Size = New System.Drawing.Size(144, 276)
Me.lblTape.TabIndex = 1
Me.lblTape.TextAlign = System.Drawing.ContentAlig nment.TopR ight
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.Burly Wood
Me.ClientSize = New System.Drawing.Size(466, 289)
Me.Controls.Add(Me.lblTape )
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.btnClea r)
Me.Controls.Add(Me.btnDeci malPlace)
Me.Controls.Add(Me.btn0)
Me.Controls.Add(Me.btnSubt ract)
Me.Controls.Add(Me.btn3)
Me.Controls.Add(Me.btn2)
Me.Controls.Add(Me.btn1)
Me.Controls.Add(Me.btnMult iply)
Me.Controls.Add(Me.btn6)
Me.Controls.Add(Me.btn5)
Me.Controls.Add(Me.btn4)
Me.Controls.Add(Me.btnDivi de)
Me.Controls.Add(Me.btn9)
Me.Controls.Add(Me.btn8)
Me.Controls.Add(Me.btn7)
Me.Controls.Add(Me.lblCurr Num)
Me.Menu = Me.mmuMain
Me.Name = "frmMain"
Me.Text = "DonaldCook_Unit4"
Me.ResumeLayout(False)
End Sub
#End Region
Private total As Double
Dim clearDisplay As Boolean
Dim Operand1 As Double, Operand2 As Double
Dim Operator As String
Private Sub mmuFormatColors_Click(ByVa l sender As System.Object, ByVal e As System.EventArgs) Handles mmuFormatColors.Click
cdSelectColors.ShowDialog( )
lblCurrNum.BackColor = cdSelectColors.Color
lblTape.BackColor = cdSelectColors.Color
End Sub
Private Sub mmuFormatFontColors_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmuFormatFontColors.Click
cdSelectColors.ShowDialog( )
lblCurrNum.ForeColor = cdSelectColors.Color
lblTape.ForeColor = cdSelectColors.Color
End Sub
Private Sub mmuFormatFonts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmuFormatFonts.Click
fdSelectFont.ShowDialog()
lblCurrNum.Font = fdSelectFont.Font
lblTape.Font = fdSelectFont.Font
End Sub
Private Sub Digit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click, btn1.Click, btn2.Click, _
btn3.Click, btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click
If clearDisplay Then
lblCurrNum.Text = ""
clearDisplay = False
End If
lblCurrNum.Text = lblCurrNum.Text + sender.text
End Sub
Private Sub btnDecimalPlace_Click(ByVa l sender As System.Object, ByVal e As System.EventArgs) Handles btnDecimalPlace.Click
If lblCurrNum.Text.IndexOf(". ") > 0 Then
Exit Sub
Else
lblCurrNum.Text = lblCurrNum.Text & "."
End If
End Sub
Private Sub lblCurrNum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPr essEventAr gs) Handles MyBase.KeyPress
If System.Char.IsDigit(e.KeyC har) Or e.KeyChar = "." Then
If clearDisplay Then
lblCurrNum.Text = ""
clearDisplay = False
End If
lblCurrNum.Text = lblTape.Text + e.KeyChar
End If
If e.KeyChar = "C" Or e.KeyChar = "c" Then
lblCurrNum.Text = ""
End If
Dim value As Double
Select Case e.KeyChar
Case "+"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total + value
addOperation("+ " & lblCurrNum.Text)
lblCurrNum.Text = ""
End If
e.Handled = True
Case "-"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total - value
addOperation("- " & lblCurrNum.Text)
lblCurrNum.Text = ""
End If
e.Handled = True
Case "*"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total * value
addOperation("* " & lblCurrNum.Text)
lblCurrNum.Text = ""
End If
e.Handled = True
Case "/"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total / value
addOperation("/ " & lblCurrNum.Text)
lblCurrNum.Text = ""
End If
e.Handled = True
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", Chr(8)
' Allow these keys to pass thru
Case Else
e.Handled = True
End Select
End Sub
Private Sub addOperation(ByVal op As String)
ListBox1.Items.Add(op)
ListBox1.Items.Add(total)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
End Sub
End Class
Thanks for tring.
Option Explicit On
Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuI
Friend WithEvents lblCurrNum As System.Windows.Forms.Label
Friend WithEvents mmuMain As System.Windows.Forms.MainM
Friend WithEvents fdSelectFont As System.Windows.Forms.FontD
Friend WithEvents cdSelectFontColor As System.Windows.Forms.Color
Friend WithEvents btn7 As System.Windows.Forms.Butto
Friend WithEvents btn8 As System.Windows.Forms.Butto
Friend WithEvents btn9 As System.Windows.Forms.Butto
Friend WithEvents btnDivide As System.Windows.Forms.Butto
Friend WithEvents btn4 As System.Windows.Forms.Butto
Friend WithEvents btn5 As System.Windows.Forms.Butto
Friend WithEvents btn6 As System.Windows.Forms.Butto
Friend WithEvents btnMultiply As System.Windows.Forms.Butto
Friend WithEvents btn1 As System.Windows.Forms.Butto
Friend WithEvents btn2 As System.Windows.Forms.Butto
Friend WithEvents btn3 As System.Windows.Forms.Butto
Friend WithEvents btnSubtract As System.Windows.Forms.Butto
Friend WithEvents btn0 As System.Windows.Forms.Butto
Friend WithEvents btnDecimalPlace As System.Windows.Forms.Butto
Friend WithEvents btnClear As System.Windows.Forms.Butto
Friend WithEvents btnAdd As System.Windows.Forms.Butto
Friend WithEvents mmuFormatColors As System.Windows.Forms.MenuI
Friend WithEvents mmuFormatFontColors As System.Windows.Forms.MenuI
Friend WithEvents mmuFormatFonts As System.Windows.Forms.MenuI
Friend WithEvents cdSelectColors As System.Windows.Forms.Color
Friend WithEvents ListBox1 As System.Windows.Forms.ListB
Friend WithEvents lblTape As System.Windows.Forms.Label
<System.Diagnostics.Debugg
Me.lblCurrNum = New System.Windows.Forms.Label
Me.mmuMain = New System.Windows.Forms.MainM
Me.MenuItem1 = New System.Windows.Forms.MenuI
Me.mmuFormatColors = New System.Windows.Forms.MenuI
Me.mmuFormatFontColors = New System.Windows.Forms.MenuI
Me.mmuFormatFonts = New System.Windows.Forms.MenuI
Me.fdSelectFont = New System.Windows.Forms.FontD
Me.cdSelectColors = New System.Windows.Forms.Color
Me.cdSelectFontColor = New System.Windows.Forms.Color
Me.btn7 = New System.Windows.Forms.Butto
Me.btn8 = New System.Windows.Forms.Butto
Me.btn9 = New System.Windows.Forms.Butto
Me.btnDivide = New System.Windows.Forms.Butto
Me.btn4 = New System.Windows.Forms.Butto
Me.btn5 = New System.Windows.Forms.Butto
Me.btn6 = New System.Windows.Forms.Butto
Me.btnMultiply = New System.Windows.Forms.Butto
Me.btn1 = New System.Windows.Forms.Butto
Me.btn2 = New System.Windows.Forms.Butto
Me.btn3 = New System.Windows.Forms.Butto
Me.btnSubtract = New System.Windows.Forms.Butto
Me.btn0 = New System.Windows.Forms.Butto
Me.btnDecimalPlace = New System.Windows.Forms.Butto
Me.btnClear = New System.Windows.Forms.Butto
Me.btnAdd = New System.Windows.Forms.Butto
Me.ListBox1 = New System.Windows.Forms.ListB
Me.lblTape = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'lblCurrNum
'
Me.lblCurrNum.BackColor = System.Drawing.Color.White
Me.lblCurrNum.BorderStyle = System.Windows.Forms.Borde
Me.lblCurrNum.Location = New System.Drawing.Point(0, 0)
Me.lblCurrNum.Name = "lblCurrNum"
Me.lblCurrNum.Size = New System.Drawing.Size(468, 23)
Me.lblCurrNum.TabIndex = 0
Me.lblCurrNum.TextAlign = System.Drawing.ContentAlig
'
'mmuMain
'
Me.mmuMain.MenuItems.AddRa
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.Add
Me.MenuItem1.Text = "Format"
'
'mmuFormatColors
'
Me.mmuFormatColors.Index = 0
Me.mmuFormatColors.Text = "Background Colors"
'
'mmuFormatFontColors
'
Me.mmuFormatFontColors.Ind
Me.mmuFormatFontColors.Tex
'
'mmuFormatFonts
'
Me.mmuFormatFonts.Index = 2
Me.mmuFormatFonts.Text = "Fonts"
'
'fdSelectFont
'
Me.fdSelectFont.ShowApply = True
'
'cdSelectColors
'
Me.cdSelectColors.FullOpen
'
'btn7
'
Me.btn7.BackColor = System.Drawing.Color.Navaj
Me.btn7.Location = New System.Drawing.Point(30, 66)
Me.btn7.Name = "btn7"
Me.btn7.Size = New System.Drawing.Size(36, 36)
Me.btn7.TabIndex = 2
Me.btn7.Text = "7"
'
'btn8
'
Me.btn8.BackColor = System.Drawing.Color.Navaj
Me.btn8.Location = New System.Drawing.Point(72, 66)
Me.btn8.Name = "btn8"
Me.btn8.Size = New System.Drawing.Size(36, 36)
Me.btn8.TabIndex = 3
Me.btn8.Text = "8"
'
'btn9
'
Me.btn9.BackColor = System.Drawing.Color.Navaj
Me.btn9.Location = New System.Drawing.Point(114, 66)
Me.btn9.Name = "btn9"
Me.btn9.Size = New System.Drawing.Size(36, 36)
Me.btn9.TabIndex = 4
Me.btn9.Text = "9"
'
'btnDivide
'
Me.btnDivide.BackColor = System.Drawing.Color.Navaj
Me.btnDivide.DialogResult = System.Windows.Forms.Dialo
Me.btnDivide.Location = New System.Drawing.Point(156, 66)
Me.btnDivide.Name = "btnDivide"
Me.btnDivide.Size = New System.Drawing.Size(36, 36)
Me.btnDivide.TabIndex = 5
Me.btnDivide.Text = "/"
'
'btn4
'
Me.btn4.BackColor = System.Drawing.Color.Navaj
Me.btn4.Location = New System.Drawing.Point(30, 108)
Me.btn4.Name = "btn4"
Me.btn4.Size = New System.Drawing.Size(36, 36)
Me.btn4.TabIndex = 6
Me.btn4.Text = "4"
'
'btn5
'
Me.btn5.BackColor = System.Drawing.Color.Navaj
Me.btn5.Location = New System.Drawing.Point(72, 108)
Me.btn5.Name = "btn5"
Me.btn5.Size = New System.Drawing.Size(36, 36)
Me.btn5.TabIndex = 7
Me.btn5.Text = "5"
'
'btn6
'
Me.btn6.BackColor = System.Drawing.Color.Navaj
Me.btn6.Location = New System.Drawing.Point(114, 108)
Me.btn6.Name = "btn6"
Me.btn6.Size = New System.Drawing.Size(36, 36)
Me.btn6.TabIndex = 8
Me.btn6.Text = "6"
'
'btnMultiply
'
Me.btnMultiply.BackColor = System.Drawing.Color.Navaj
Me.btnMultiply.DialogResul
Me.btnMultiply.Location = New System.Drawing.Point(156, 108)
Me.btnMultiply.Name = "btnMultiply"
Me.btnMultiply.Size = New System.Drawing.Size(36, 36)
Me.btnMultiply.TabIndex = 9
Me.btnMultiply.Text = "*"
'
'btn1
'
Me.btn1.BackColor = System.Drawing.Color.Navaj
Me.btn1.Location = New System.Drawing.Point(30, 150)
Me.btn1.Name = "btn1"
Me.btn1.Size = New System.Drawing.Size(36, 36)
Me.btn1.TabIndex = 10
Me.btn1.Text = "1"
'
'btn2
'
Me.btn2.BackColor = System.Drawing.Color.Navaj
Me.btn2.Location = New System.Drawing.Point(72, 150)
Me.btn2.Name = "btn2"
Me.btn2.Size = New System.Drawing.Size(36, 36)
Me.btn2.TabIndex = 11
Me.btn2.Text = "2"
'
'btn3
'
Me.btn3.BackColor = System.Drawing.Color.Navaj
Me.btn3.Location = New System.Drawing.Point(114, 150)
Me.btn3.Name = "btn3"
Me.btn3.Size = New System.Drawing.Size(36, 36)
Me.btn3.TabIndex = 12
Me.btn3.Text = "3"
'
'btnSubtract
'
Me.btnSubtract.BackColor = System.Drawing.Color.Navaj
Me.btnSubtract.DialogResul
Me.btnSubtract.Location = New System.Drawing.Point(156, 150)
Me.btnSubtract.Name = "btnSubtract"
Me.btnSubtract.Size = New System.Drawing.Size(36, 36)
Me.btnSubtract.TabIndex = 13
Me.btnSubtract.Text = "-"
'
'btn0
'
Me.btn0.BackColor = System.Drawing.Color.Navaj
Me.btn0.Location = New System.Drawing.Point(30, 192)
Me.btn0.Name = "btn0"
Me.btn0.Size = New System.Drawing.Size(36, 36)
Me.btn0.TabIndex = 14
Me.btn0.Text = "0"
'
'btnDecimalPlace
'
Me.btnDecimalPlace.BackCol
Me.btnDecimalPlace.Locatio
Me.btnDecimalPlace.Name = "btnDecimalPlace"
Me.btnDecimalPlace.Size = New System.Drawing.Size(36, 36)
Me.btnDecimalPlace.TabInde
Me.btnDecimalPlace.Text = "."
'
'btnClear
'
Me.btnClear.BackColor = System.Drawing.Color.Navaj
Me.btnClear.Location = New System.Drawing.Point(114, 192)
Me.btnClear.Name = "btnClear"
Me.btnClear.Size = New System.Drawing.Size(36, 36)
Me.btnClear.TabIndex = 16
Me.btnClear.Text = "C"
'
'btnAdd
'
Me.btnAdd.BackColor = System.Drawing.Color.Navaj
Me.btnAdd.DialogResult = System.Windows.Forms.Dialo
Me.btnAdd.Location = New System.Drawing.Point(156, 192)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(36, 36)
Me.btnAdd.TabIndex = 17
Me.btnAdd.Text = "+"
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(408, 144)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(120, 95)
Me.ListBox1.TabIndex = 0
'
'lblTape
'
Me.lblTape.BackColor = System.Drawing.Color.White
Me.lblTape.BorderStyle = System.Windows.Forms.Borde
Me.lblTape.FlatStyle = System.Windows.Forms.FlatS
Me.lblTape.Location = New System.Drawing.Point(324, 24)
Me.lblTape.Name = "lblTape"
Me.lblTape.Size = New System.Drawing.Size(144, 276)
Me.lblTape.TabIndex = 1
Me.lblTape.TextAlign = System.Drawing.ContentAlig
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.Burly
Me.ClientSize = New System.Drawing.Size(466, 289)
Me.Controls.Add(Me.lblTape
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.btnClea
Me.Controls.Add(Me.btnDeci
Me.Controls.Add(Me.btn0)
Me.Controls.Add(Me.btnSubt
Me.Controls.Add(Me.btn3)
Me.Controls.Add(Me.btn2)
Me.Controls.Add(Me.btn1)
Me.Controls.Add(Me.btnMult
Me.Controls.Add(Me.btn6)
Me.Controls.Add(Me.btn5)
Me.Controls.Add(Me.btn4)
Me.Controls.Add(Me.btnDivi
Me.Controls.Add(Me.btn9)
Me.Controls.Add(Me.btn8)
Me.Controls.Add(Me.btn7)
Me.Controls.Add(Me.lblCurr
Me.Menu = Me.mmuMain
Me.Name = "frmMain"
Me.Text = "DonaldCook_Unit4"
Me.ResumeLayout(False)
End Sub
#End Region
Private total As Double
Dim clearDisplay As Boolean
Dim Operand1 As Double, Operand2 As Double
Dim Operator As String
Private Sub mmuFormatColors_Click(ByVa
cdSelectColors.ShowDialog(
lblCurrNum.BackColor = cdSelectColors.Color
lblTape.BackColor = cdSelectColors.Color
End Sub
Private Sub mmuFormatFontColors_Click(
cdSelectColors.ShowDialog(
lblCurrNum.ForeColor = cdSelectColors.Color
lblTape.ForeColor = cdSelectColors.Color
End Sub
Private Sub mmuFormatFonts_Click(ByVal
fdSelectFont.ShowDialog()
lblCurrNum.Font = fdSelectFont.Font
lblTape.Font = fdSelectFont.Font
End Sub
Private Sub Digit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click, btn1.Click, btn2.Click, _
btn3.Click, btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click
If clearDisplay Then
lblCurrNum.Text = ""
clearDisplay = False
End If
lblCurrNum.Text = lblCurrNum.Text + sender.text
End Sub
Private Sub btnDecimalPlace_Click(ByVa
If lblCurrNum.Text.IndexOf(".
Exit Sub
Else
lblCurrNum.Text = lblCurrNum.Text & "."
End If
End Sub
Private Sub lblCurrNum_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPr
If System.Char.IsDigit(e.KeyC
If clearDisplay Then
lblCurrNum.Text = ""
clearDisplay = False
End If
lblCurrNum.Text = lblTape.Text + e.KeyChar
End If
If e.KeyChar = "C" Or e.KeyChar = "c" Then
lblCurrNum.Text = ""
End If
Dim value As Double
Select Case e.KeyChar
Case "+"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total + value
addOperation("+ " & lblCurrNum.Text)
lblCurrNum.Text = ""
End If
e.Handled = True
Case "-"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total - value
addOperation("- " & lblCurrNum.Text)
lblCurrNum.Text = ""
End If
e.Handled = True
Case "*"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total * value
addOperation("* " & lblCurrNum.Text)
lblCurrNum.Text = ""
End If
e.Handled = True
Case "/"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total / value
addOperation("/ " & lblCurrNum.Text)
lblCurrNum.Text = ""
End If
e.Handled = True
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", Chr(8)
' Allow these keys to pass thru
Case Else
e.Handled = True
End Select
End Sub
Private Sub addOperation(ByVal op As String)
ListBox1.Items.Add(op)
ListBox1.Items.Add(total)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
End Sub
End Class
Thanks for tring.
How about this?
Option Explicit On
Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuI tem
Friend WithEvents lblCurrNum As System.Windows.Forms.Label
Friend WithEvents mmuMain As System.Windows.Forms.MainM enu
Friend WithEvents fdSelectFont As System.Windows.Forms.FontD ialog
Friend WithEvents cdSelectFontColor As System.Windows.Forms.Color Dialog
Friend WithEvents btn7 As System.Windows.Forms.Butto n
Friend WithEvents btn8 As System.Windows.Forms.Butto n
Friend WithEvents btn9 As System.Windows.Forms.Butto n
Friend WithEvents btnDivide As System.Windows.Forms.Butto n
Friend WithEvents btn4 As System.Windows.Forms.Butto n
Friend WithEvents btn5 As System.Windows.Forms.Butto n
Friend WithEvents btn6 As System.Windows.Forms.Butto n
Friend WithEvents btnMultiply As System.Windows.Forms.Butto n
Friend WithEvents btn1 As System.Windows.Forms.Butto n
Friend WithEvents btn2 As System.Windows.Forms.Butto n
Friend WithEvents btn3 As System.Windows.Forms.Butto n
Friend WithEvents btnSubtract As System.Windows.Forms.Butto n
Friend WithEvents btn0 As System.Windows.Forms.Butto n
Friend WithEvents btnDecimalPlace As System.Windows.Forms.Butto n
Friend WithEvents btnClear As System.Windows.Forms.Butto n
Friend WithEvents btnAdd As System.Windows.Forms.Butto n
Friend WithEvents mmuFormatColors As System.Windows.Forms.MenuI tem
Friend WithEvents mmuFormatFontColors As System.Windows.Forms.MenuI tem
Friend WithEvents mmuFormatFonts As System.Windows.Forms.MenuI tem
Friend WithEvents cdSelectColors As System.Windows.Forms.Color Dialog
Friend WithEvents ListBox1 As System.Windows.Forms.ListB ox
Friend WithEvents TextBox1 As System.Windows.Forms.TextB ox
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.lblCurrNum = New System.Windows.Forms.Label
Me.mmuMain = New System.Windows.Forms.MainM enu
Me.MenuItem1 = New System.Windows.Forms.MenuI tem
Me.mmuFormatColors = New System.Windows.Forms.MenuI tem
Me.mmuFormatFontColors = New System.Windows.Forms.MenuI tem
Me.mmuFormatFonts = New System.Windows.Forms.MenuI tem
Me.fdSelectFont = New System.Windows.Forms.FontD ialog
Me.cdSelectColors = New System.Windows.Forms.Color Dialog
Me.cdSelectFontColor = New System.Windows.Forms.Color Dialog
Me.btn7 = New System.Windows.Forms.Butto n
Me.btn8 = New System.Windows.Forms.Butto n
Me.btn9 = New System.Windows.Forms.Butto n
Me.btnDivide = New System.Windows.Forms.Butto n
Me.btn4 = New System.Windows.Forms.Butto n
Me.btn5 = New System.Windows.Forms.Butto n
Me.btn6 = New System.Windows.Forms.Butto n
Me.btnMultiply = New System.Windows.Forms.Butto n
Me.btn1 = New System.Windows.Forms.Butto n
Me.btn2 = New System.Windows.Forms.Butto n
Me.btn3 = New System.Windows.Forms.Butto n
Me.btnSubtract = New System.Windows.Forms.Butto n
Me.btn0 = New System.Windows.Forms.Butto n
Me.btnDecimalPlace = New System.Windows.Forms.Butto n
Me.btnClear = New System.Windows.Forms.Butto n
Me.btnAdd = New System.Windows.Forms.Butto n
Me.ListBox1 = New System.Windows.Forms.ListB ox
Me.TextBox1 = New System.Windows.Forms.TextB ox
Me.SuspendLayout()
'
'lblCurrNum
'
Me.lblCurrNum.BackColor = System.Drawing.Color.White
Me.lblCurrNum.BorderStyle = System.Windows.Forms.Borde rStyle.Fix ed3D
Me.lblCurrNum.Location = New System.Drawing.Point(0, 0)
Me.lblCurrNum.Name = "lblCurrNum"
Me.lblCurrNum.Size = New System.Drawing.Size(468, 23)
Me.lblCurrNum.TabIndex = 0
Me.lblCurrNum.TextAlign = System.Drawing.ContentAlig nment.Midd leLeft
'
'mmuMain
'
Me.mmuMain.MenuItems.AddRa nge(New System.Windows.Forms.MenuI tem() {Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.Add Range(New System.Windows.Forms.MenuI tem() {Me.mmuFormatColors, Me.mmuFormatFontColors, Me.mmuFormatFonts})
Me.MenuItem1.Text = "Format"
'
'mmuFormatColors
'
Me.mmuFormatColors.Index = 0
Me.mmuFormatColors.Text = "Background Colors"
'
'mmuFormatFontColors
'
Me.mmuFormatFontColors.Ind ex = 1
Me.mmuFormatFontColors.Tex t = "Text Colors"
'
'mmuFormatFonts
'
Me.mmuFormatFonts.Index = 2
Me.mmuFormatFonts.Text = "Fonts"
'
'fdSelectFont
'
Me.fdSelectFont.ShowApply = True
'
'cdSelectColors
'
Me.cdSelectColors.FullOpen = True
'
'btn7
'
Me.btn7.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn7.Location = New System.Drawing.Point(30, 66)
Me.btn7.Name = "btn7"
Me.btn7.Size = New System.Drawing.Size(36, 36)
Me.btn7.TabIndex = 2
Me.btn7.Text = "7"
'
'btn8
'
Me.btn8.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn8.Location = New System.Drawing.Point(72, 66)
Me.btn8.Name = "btn8"
Me.btn8.Size = New System.Drawing.Size(36, 36)
Me.btn8.TabIndex = 3
Me.btn8.Text = "8"
'
'btn9
'
Me.btn9.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn9.Location = New System.Drawing.Point(114, 66)
Me.btn9.Name = "btn9"
Me.btn9.Size = New System.Drawing.Size(36, 36)
Me.btn9.TabIndex = 4
Me.btn9.Text = "9"
'
'btnDivide
'
Me.btnDivide.BackColor = System.Drawing.Color.Navaj oWhite
Me.btnDivide.DialogResult = System.Windows.Forms.Dialo gResult.OK
Me.btnDivide.Location = New System.Drawing.Point(156, 66)
Me.btnDivide.Name = "btnDivide"
Me.btnDivide.Size = New System.Drawing.Size(36, 36)
Me.btnDivide.TabIndex = 5
Me.btnDivide.Text = "/"
'
'btn4
'
Me.btn4.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn4.Location = New System.Drawing.Point(30, 108)
Me.btn4.Name = "btn4"
Me.btn4.Size = New System.Drawing.Size(36, 36)
Me.btn4.TabIndex = 6
Me.btn4.Text = "4"
'
'btn5
'
Me.btn5.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn5.Location = New System.Drawing.Point(72, 108)
Me.btn5.Name = "btn5"
Me.btn5.Size = New System.Drawing.Size(36, 36)
Me.btn5.TabIndex = 7
Me.btn5.Text = "5"
'
'btn6
'
Me.btn6.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn6.Location = New System.Drawing.Point(114, 108)
Me.btn6.Name = "btn6"
Me.btn6.Size = New System.Drawing.Size(36, 36)
Me.btn6.TabIndex = 8
Me.btn6.Text = "6"
'
'btnMultiply
'
Me.btnMultiply.BackColor = System.Drawing.Color.Navaj oWhite
Me.btnMultiply.DialogResul t = System.Windows.Forms.Dialo gResult.OK
Me.btnMultiply.Location = New System.Drawing.Point(156, 108)
Me.btnMultiply.Name = "btnMultiply"
Me.btnMultiply.Size = New System.Drawing.Size(36, 36)
Me.btnMultiply.TabIndex = 9
Me.btnMultiply.Text = "*"
'
'btn1
'
Me.btn1.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn1.Location = New System.Drawing.Point(30, 150)
Me.btn1.Name = "btn1"
Me.btn1.Size = New System.Drawing.Size(36, 36)
Me.btn1.TabIndex = 10
Me.btn1.Text = "1"
'
'btn2
'
Me.btn2.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn2.Location = New System.Drawing.Point(72, 150)
Me.btn2.Name = "btn2"
Me.btn2.Size = New System.Drawing.Size(36, 36)
Me.btn2.TabIndex = 11
Me.btn2.Text = "2"
'
'btn3
'
Me.btn3.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn3.Location = New System.Drawing.Point(114, 150)
Me.btn3.Name = "btn3"
Me.btn3.Size = New System.Drawing.Size(36, 36)
Me.btn3.TabIndex = 12
Me.btn3.Text = "3"
'
'btnSubtract
'
Me.btnSubtract.BackColor = System.Drawing.Color.Navaj oWhite
Me.btnSubtract.DialogResul t = System.Windows.Forms.Dialo gResult.OK
Me.btnSubtract.Location = New System.Drawing.Point(156, 150)
Me.btnSubtract.Name = "btnSubtract"
Me.btnSubtract.Size = New System.Drawing.Size(36, 36)
Me.btnSubtract.TabIndex = 13
Me.btnSubtract.Text = "-"
'
'btn0
'
Me.btn0.BackColor = System.Drawing.Color.Navaj oWhite
Me.btn0.Location = New System.Drawing.Point(30, 192)
Me.btn0.Name = "btn0"
Me.btn0.Size = New System.Drawing.Size(36, 36)
Me.btn0.TabIndex = 14
Me.btn0.Text = "0"
'
'btnDecimalPlace
'
Me.btnDecimalPlace.BackCol or = System.Drawing.Color.Navaj oWhite
Me.btnDecimalPlace.Locatio n = New System.Drawing.Point(72, 192)
Me.btnDecimalPlace.Name = "btnDecimalPlace"
Me.btnDecimalPlace.Size = New System.Drawing.Size(36, 36)
Me.btnDecimalPlace.TabInde x = 15
Me.btnDecimalPlace.Text = "."
'
'btnClear
'
Me.btnClear.BackColor = System.Drawing.Color.Navaj oWhite
Me.btnClear.Location = New System.Drawing.Point(114, 192)
Me.btnClear.Name = "btnClear"
Me.btnClear.Size = New System.Drawing.Size(36, 36)
Me.btnClear.TabIndex = 16
Me.btnClear.Text = "C"
'
'btnAdd
'
Me.btnAdd.BackColor = System.Drawing.Color.Navaj oWhite
Me.btnAdd.DialogResult = System.Windows.Forms.Dialo gResult.OK
Me.btnAdd.Location = New System.Drawing.Point(156, 192)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(36, 36)
Me.btnAdd.TabIndex = 17
Me.btnAdd.Text = "+"
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(408, 144)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(120, 95)
Me.ListBox1.TabIndex = 0
'
'TextBox1
'
Me.TextBox1.BorderStyle = System.Windows.Forms.Borde rStyle.Non e
Me.TextBox1.Location = New System.Drawing.Point(328, 24)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ReadOnly = True
Me.TextBox1.ScrollBars = System.Windows.Forms.Scrol lBars.Vert ical
Me.TextBox1.Size = New System.Drawing.Size(136, 264)
Me.TextBox1.TabIndex = 18
Me.TextBox1.Text = ""
Me.TextBox1.TextAlign = System.Windows.Forms.Horiz ontalAlign ment.Right
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.Burly Wood
Me.ClientSize = New System.Drawing.Size(466, 289)
Me.Controls.Add(Me.TextBox 1)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.btnClea r)
Me.Controls.Add(Me.btnDeci malPlace)
Me.Controls.Add(Me.btn0)
Me.Controls.Add(Me.btnSubt ract)
Me.Controls.Add(Me.btn3)
Me.Controls.Add(Me.btn2)
Me.Controls.Add(Me.btn1)
Me.Controls.Add(Me.btnMult iply)
Me.Controls.Add(Me.btn6)
Me.Controls.Add(Me.btn5)
Me.Controls.Add(Me.btn4)
Me.Controls.Add(Me.btnDivi de)
Me.Controls.Add(Me.btn9)
Me.Controls.Add(Me.btn8)
Me.Controls.Add(Me.btn7)
Me.Controls.Add(Me.lblCurr Num)
Me.KeyPreview = True
Me.Menu = Me.mmuMain
Me.Name = "frmMain"
Me.Text = "DonaldCook_Unit4"
Me.ResumeLayout(False)
End Sub
#End Region
Private total As Double
Dim clearDisplay As Boolean
Dim Operand1 As Double, Operand2 As Double
Dim Operator As String
Private Sub mmuFormatColors_Click(ByVa l sender As System.Object, ByVal e As System.EventArgs) Handles mmuFormatColors.Click
cdSelectColors.ShowDialog( )
lblCurrNum.BackColor = cdSelectColors.Color
TextBox1.BackColor = cdSelectColors.Color
End Sub
Private Sub mmuFormatFontColors_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmuFormatFontColors.Click
cdSelectColors.ShowDialog( )
lblCurrNum.ForeColor = cdSelectColors.Color
TextBox1.ForeColor = cdSelectColors.Color
End Sub
Private Sub mmuFormatFonts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmuFormatFonts.Click
fdSelectFont.ShowDialog()
lblCurrNum.Font = fdSelectFont.Font
TextBox1.Font = fdSelectFont.Font
End Sub
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click, btn1.Click, btn2.Click, _
btn3.Click, btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click, btnDecimalPlace.Click, btnAdd.Click, btnClear.Click, btnDivide.Click, btnMultiply.Click, btnMultiply.Click, btnSubtract.Click, btnClear.Click
frmMain_KeyPress(sender, New KeyPressEventArgs(sender.t ext))
End Sub
Private Sub frmMain_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPr essEventAr gs) Handles MyBase.KeyPress
If System.Char.IsDigit(e.KeyC har) Then
If clearDisplay Then
lblCurrNum.Text = ""
clearDisplay = False
End If
lblCurrNum.Text = lblCurrNum.Text & e.KeyChar
e.Handled = True
Exit Sub
End If
If e.KeyChar = "." Then
If lblCurrNum.Text.IndexOf(". ") = -1 Then
lblCurrNum.Text = lblCurrNum.Text & "."
End If
e.Handled = True
Exit Sub
End If
If e.KeyChar = "C" Or e.KeyChar = "c" Then
lblCurrNum.Text = ""
TextBox1.Text = ""
total = 0
e.Handled = True
Exit Sub
End If
Dim value As Double
Select Case e.KeyChar
Case "+"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total + value
TextBox1.Text = TextBox1.Text & "+ " & lblCurrNum.Text & vbCrLf
TextBox1.Text = TextBox1.Text & total & vbCrLf
lblCurrNum.Text = ""
End If
e.Handled = True
Case "-"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total - value
TextBox1.Text = TextBox1.Text & "- " & lblCurrNum.Text & vbCrLf
TextBox1.Text = TextBox1.Text & total & vbCrLf
lblCurrNum.Text = ""
End If
e.Handled = True
Case "*"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total * value
TextBox1.Text = TextBox1.Text & "* " & lblCurrNum.Text & vbCrLf
TextBox1.Text = TextBox1.Text & total & vbCrLf
lblCurrNum.Text = ""
End If
e.Handled = True
Case "/"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total / value
TextBox1.Text = TextBox1.Text & "/ " & lblCurrNum.Text & vbCrLf
TextBox1.Text = TextBox1.Text & total & vbCrLf
lblCurrNum.Text = ""
End If
e.Handled = True
Case Else
e.Handled = True
End Select
TextBox1.SelectionStart = TextBox1.TextLength
TextBox1.ScrollToCaret()
End Sub
End Class
Option Explicit On
Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuI
Friend WithEvents lblCurrNum As System.Windows.Forms.Label
Friend WithEvents mmuMain As System.Windows.Forms.MainM
Friend WithEvents fdSelectFont As System.Windows.Forms.FontD
Friend WithEvents cdSelectFontColor As System.Windows.Forms.Color
Friend WithEvents btn7 As System.Windows.Forms.Butto
Friend WithEvents btn8 As System.Windows.Forms.Butto
Friend WithEvents btn9 As System.Windows.Forms.Butto
Friend WithEvents btnDivide As System.Windows.Forms.Butto
Friend WithEvents btn4 As System.Windows.Forms.Butto
Friend WithEvents btn5 As System.Windows.Forms.Butto
Friend WithEvents btn6 As System.Windows.Forms.Butto
Friend WithEvents btnMultiply As System.Windows.Forms.Butto
Friend WithEvents btn1 As System.Windows.Forms.Butto
Friend WithEvents btn2 As System.Windows.Forms.Butto
Friend WithEvents btn3 As System.Windows.Forms.Butto
Friend WithEvents btnSubtract As System.Windows.Forms.Butto
Friend WithEvents btn0 As System.Windows.Forms.Butto
Friend WithEvents btnDecimalPlace As System.Windows.Forms.Butto
Friend WithEvents btnClear As System.Windows.Forms.Butto
Friend WithEvents btnAdd As System.Windows.Forms.Butto
Friend WithEvents mmuFormatColors As System.Windows.Forms.MenuI
Friend WithEvents mmuFormatFontColors As System.Windows.Forms.MenuI
Friend WithEvents mmuFormatFonts As System.Windows.Forms.MenuI
Friend WithEvents cdSelectColors As System.Windows.Forms.Color
Friend WithEvents ListBox1 As System.Windows.Forms.ListB
Friend WithEvents TextBox1 As System.Windows.Forms.TextB
<System.Diagnostics.Debugg
Me.lblCurrNum = New System.Windows.Forms.Label
Me.mmuMain = New System.Windows.Forms.MainM
Me.MenuItem1 = New System.Windows.Forms.MenuI
Me.mmuFormatColors = New System.Windows.Forms.MenuI
Me.mmuFormatFontColors = New System.Windows.Forms.MenuI
Me.mmuFormatFonts = New System.Windows.Forms.MenuI
Me.fdSelectFont = New System.Windows.Forms.FontD
Me.cdSelectColors = New System.Windows.Forms.Color
Me.cdSelectFontColor = New System.Windows.Forms.Color
Me.btn7 = New System.Windows.Forms.Butto
Me.btn8 = New System.Windows.Forms.Butto
Me.btn9 = New System.Windows.Forms.Butto
Me.btnDivide = New System.Windows.Forms.Butto
Me.btn4 = New System.Windows.Forms.Butto
Me.btn5 = New System.Windows.Forms.Butto
Me.btn6 = New System.Windows.Forms.Butto
Me.btnMultiply = New System.Windows.Forms.Butto
Me.btn1 = New System.Windows.Forms.Butto
Me.btn2 = New System.Windows.Forms.Butto
Me.btn3 = New System.Windows.Forms.Butto
Me.btnSubtract = New System.Windows.Forms.Butto
Me.btn0 = New System.Windows.Forms.Butto
Me.btnDecimalPlace = New System.Windows.Forms.Butto
Me.btnClear = New System.Windows.Forms.Butto
Me.btnAdd = New System.Windows.Forms.Butto
Me.ListBox1 = New System.Windows.Forms.ListB
Me.TextBox1 = New System.Windows.Forms.TextB
Me.SuspendLayout()
'
'lblCurrNum
'
Me.lblCurrNum.BackColor = System.Drawing.Color.White
Me.lblCurrNum.BorderStyle = System.Windows.Forms.Borde
Me.lblCurrNum.Location = New System.Drawing.Point(0, 0)
Me.lblCurrNum.Name = "lblCurrNum"
Me.lblCurrNum.Size = New System.Drawing.Size(468, 23)
Me.lblCurrNum.TabIndex = 0
Me.lblCurrNum.TextAlign = System.Drawing.ContentAlig
'
'mmuMain
'
Me.mmuMain.MenuItems.AddRa
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.Add
Me.MenuItem1.Text = "Format"
'
'mmuFormatColors
'
Me.mmuFormatColors.Index = 0
Me.mmuFormatColors.Text = "Background Colors"
'
'mmuFormatFontColors
'
Me.mmuFormatFontColors.Ind
Me.mmuFormatFontColors.Tex
'
'mmuFormatFonts
'
Me.mmuFormatFonts.Index = 2
Me.mmuFormatFonts.Text = "Fonts"
'
'fdSelectFont
'
Me.fdSelectFont.ShowApply = True
'
'cdSelectColors
'
Me.cdSelectColors.FullOpen
'
'btn7
'
Me.btn7.BackColor = System.Drawing.Color.Navaj
Me.btn7.Location = New System.Drawing.Point(30, 66)
Me.btn7.Name = "btn7"
Me.btn7.Size = New System.Drawing.Size(36, 36)
Me.btn7.TabIndex = 2
Me.btn7.Text = "7"
'
'btn8
'
Me.btn8.BackColor = System.Drawing.Color.Navaj
Me.btn8.Location = New System.Drawing.Point(72, 66)
Me.btn8.Name = "btn8"
Me.btn8.Size = New System.Drawing.Size(36, 36)
Me.btn8.TabIndex = 3
Me.btn8.Text = "8"
'
'btn9
'
Me.btn9.BackColor = System.Drawing.Color.Navaj
Me.btn9.Location = New System.Drawing.Point(114, 66)
Me.btn9.Name = "btn9"
Me.btn9.Size = New System.Drawing.Size(36, 36)
Me.btn9.TabIndex = 4
Me.btn9.Text = "9"
'
'btnDivide
'
Me.btnDivide.BackColor = System.Drawing.Color.Navaj
Me.btnDivide.DialogResult = System.Windows.Forms.Dialo
Me.btnDivide.Location = New System.Drawing.Point(156, 66)
Me.btnDivide.Name = "btnDivide"
Me.btnDivide.Size = New System.Drawing.Size(36, 36)
Me.btnDivide.TabIndex = 5
Me.btnDivide.Text = "/"
'
'btn4
'
Me.btn4.BackColor = System.Drawing.Color.Navaj
Me.btn4.Location = New System.Drawing.Point(30, 108)
Me.btn4.Name = "btn4"
Me.btn4.Size = New System.Drawing.Size(36, 36)
Me.btn4.TabIndex = 6
Me.btn4.Text = "4"
'
'btn5
'
Me.btn5.BackColor = System.Drawing.Color.Navaj
Me.btn5.Location = New System.Drawing.Point(72, 108)
Me.btn5.Name = "btn5"
Me.btn5.Size = New System.Drawing.Size(36, 36)
Me.btn5.TabIndex = 7
Me.btn5.Text = "5"
'
'btn6
'
Me.btn6.BackColor = System.Drawing.Color.Navaj
Me.btn6.Location = New System.Drawing.Point(114, 108)
Me.btn6.Name = "btn6"
Me.btn6.Size = New System.Drawing.Size(36, 36)
Me.btn6.TabIndex = 8
Me.btn6.Text = "6"
'
'btnMultiply
'
Me.btnMultiply.BackColor = System.Drawing.Color.Navaj
Me.btnMultiply.DialogResul
Me.btnMultiply.Location = New System.Drawing.Point(156, 108)
Me.btnMultiply.Name = "btnMultiply"
Me.btnMultiply.Size = New System.Drawing.Size(36, 36)
Me.btnMultiply.TabIndex = 9
Me.btnMultiply.Text = "*"
'
'btn1
'
Me.btn1.BackColor = System.Drawing.Color.Navaj
Me.btn1.Location = New System.Drawing.Point(30, 150)
Me.btn1.Name = "btn1"
Me.btn1.Size = New System.Drawing.Size(36, 36)
Me.btn1.TabIndex = 10
Me.btn1.Text = "1"
'
'btn2
'
Me.btn2.BackColor = System.Drawing.Color.Navaj
Me.btn2.Location = New System.Drawing.Point(72, 150)
Me.btn2.Name = "btn2"
Me.btn2.Size = New System.Drawing.Size(36, 36)
Me.btn2.TabIndex = 11
Me.btn2.Text = "2"
'
'btn3
'
Me.btn3.BackColor = System.Drawing.Color.Navaj
Me.btn3.Location = New System.Drawing.Point(114, 150)
Me.btn3.Name = "btn3"
Me.btn3.Size = New System.Drawing.Size(36, 36)
Me.btn3.TabIndex = 12
Me.btn3.Text = "3"
'
'btnSubtract
'
Me.btnSubtract.BackColor = System.Drawing.Color.Navaj
Me.btnSubtract.DialogResul
Me.btnSubtract.Location = New System.Drawing.Point(156, 150)
Me.btnSubtract.Name = "btnSubtract"
Me.btnSubtract.Size = New System.Drawing.Size(36, 36)
Me.btnSubtract.TabIndex = 13
Me.btnSubtract.Text = "-"
'
'btn0
'
Me.btn0.BackColor = System.Drawing.Color.Navaj
Me.btn0.Location = New System.Drawing.Point(30, 192)
Me.btn0.Name = "btn0"
Me.btn0.Size = New System.Drawing.Size(36, 36)
Me.btn0.TabIndex = 14
Me.btn0.Text = "0"
'
'btnDecimalPlace
'
Me.btnDecimalPlace.BackCol
Me.btnDecimalPlace.Locatio
Me.btnDecimalPlace.Name = "btnDecimalPlace"
Me.btnDecimalPlace.Size = New System.Drawing.Size(36, 36)
Me.btnDecimalPlace.TabInde
Me.btnDecimalPlace.Text = "."
'
'btnClear
'
Me.btnClear.BackColor = System.Drawing.Color.Navaj
Me.btnClear.Location = New System.Drawing.Point(114, 192)
Me.btnClear.Name = "btnClear"
Me.btnClear.Size = New System.Drawing.Size(36, 36)
Me.btnClear.TabIndex = 16
Me.btnClear.Text = "C"
'
'btnAdd
'
Me.btnAdd.BackColor = System.Drawing.Color.Navaj
Me.btnAdd.DialogResult = System.Windows.Forms.Dialo
Me.btnAdd.Location = New System.Drawing.Point(156, 192)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(36, 36)
Me.btnAdd.TabIndex = 17
Me.btnAdd.Text = "+"
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(408, 144)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(120, 95)
Me.ListBox1.TabIndex = 0
'
'TextBox1
'
Me.TextBox1.BorderStyle = System.Windows.Forms.Borde
Me.TextBox1.Location = New System.Drawing.Point(328, 24)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ReadOnly = True
Me.TextBox1.ScrollBars = System.Windows.Forms.Scrol
Me.TextBox1.Size = New System.Drawing.Size(136, 264)
Me.TextBox1.TabIndex = 18
Me.TextBox1.Text = ""
Me.TextBox1.TextAlign = System.Windows.Forms.Horiz
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.Burly
Me.ClientSize = New System.Drawing.Size(466, 289)
Me.Controls.Add(Me.TextBox
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.btnClea
Me.Controls.Add(Me.btnDeci
Me.Controls.Add(Me.btn0)
Me.Controls.Add(Me.btnSubt
Me.Controls.Add(Me.btn3)
Me.Controls.Add(Me.btn2)
Me.Controls.Add(Me.btn1)
Me.Controls.Add(Me.btnMult
Me.Controls.Add(Me.btn6)
Me.Controls.Add(Me.btn5)
Me.Controls.Add(Me.btn4)
Me.Controls.Add(Me.btnDivi
Me.Controls.Add(Me.btn9)
Me.Controls.Add(Me.btn8)
Me.Controls.Add(Me.btn7)
Me.Controls.Add(Me.lblCurr
Me.KeyPreview = True
Me.Menu = Me.mmuMain
Me.Name = "frmMain"
Me.Text = "DonaldCook_Unit4"
Me.ResumeLayout(False)
End Sub
#End Region
Private total As Double
Dim clearDisplay As Boolean
Dim Operand1 As Double, Operand2 As Double
Dim Operator As String
Private Sub mmuFormatColors_Click(ByVa
cdSelectColors.ShowDialog(
lblCurrNum.BackColor = cdSelectColors.Color
TextBox1.BackColor = cdSelectColors.Color
End Sub
Private Sub mmuFormatFontColors_Click(
cdSelectColors.ShowDialog(
lblCurrNum.ForeColor = cdSelectColors.Color
TextBox1.ForeColor = cdSelectColors.Color
End Sub
Private Sub mmuFormatFonts_Click(ByVal
fdSelectFont.ShowDialog()
lblCurrNum.Font = fdSelectFont.Font
TextBox1.Font = fdSelectFont.Font
End Sub
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click, btn1.Click, btn2.Click, _
btn3.Click, btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click, btnDecimalPlace.Click, btnAdd.Click, btnClear.Click, btnDivide.Click, btnMultiply.Click, btnMultiply.Click, btnSubtract.Click, btnClear.Click
frmMain_KeyPress(sender, New KeyPressEventArgs(sender.t
End Sub
Private Sub frmMain_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPr
If System.Char.IsDigit(e.KeyC
If clearDisplay Then
lblCurrNum.Text = ""
clearDisplay = False
End If
lblCurrNum.Text = lblCurrNum.Text & e.KeyChar
e.Handled = True
Exit Sub
End If
If e.KeyChar = "." Then
If lblCurrNum.Text.IndexOf(".
lblCurrNum.Text = lblCurrNum.Text & "."
End If
e.Handled = True
Exit Sub
End If
If e.KeyChar = "C" Or e.KeyChar = "c" Then
lblCurrNum.Text = ""
TextBox1.Text = ""
total = 0
e.Handled = True
Exit Sub
End If
Dim value As Double
Select Case e.KeyChar
Case "+"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total + value
TextBox1.Text = TextBox1.Text & "+ " & lblCurrNum.Text & vbCrLf
TextBox1.Text = TextBox1.Text & total & vbCrLf
lblCurrNum.Text = ""
End If
e.Handled = True
Case "-"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total - value
TextBox1.Text = TextBox1.Text & "- " & lblCurrNum.Text & vbCrLf
TextBox1.Text = TextBox1.Text & total & vbCrLf
lblCurrNum.Text = ""
End If
e.Handled = True
Case "*"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total * value
TextBox1.Text = TextBox1.Text & "* " & lblCurrNum.Text & vbCrLf
TextBox1.Text = TextBox1.Text & total & vbCrLf
lblCurrNum.Text = ""
End If
e.Handled = True
Case "/"
If lblCurrNum.Text.Length > 0 Then
value = CDbl(lblCurrNum.Text)
total = total / value
TextBox1.Text = TextBox1.Text & "/ " & lblCurrNum.Text & vbCrLf
TextBox1.Text = TextBox1.Text & total & vbCrLf
lblCurrNum.Text = ""
End If
e.Handled = True
Case Else
e.Handled = True
End Select
TextBox1.SelectionStart = TextBox1.TextLength
TextBox1.ScrollToCaret()
End Sub
End Class
ASKER
That works great thanks but I need it to do like this:
7+
7+
14
7-
7
4-
3
Can you do this?
Thanks
7+
7+
14
7-
7
4-
3
Can you do this?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much.
Tex
Tex
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextB
Friend WithEvents ListBox1 As System.Windows.Forms.ListB
<System.Diagnostics.Debugg
Me.TextBox1 = New System.Windows.Forms.TextB
Me.ListBox1 = New System.Windows.Forms.ListB
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(16, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(104, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(128, 8)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(160, 238)
Me.ListBox1.TabIndex = 1
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(296, 266)
Me.Controls.Add(Me.ListBox
Me.Controls.Add(Me.TextBox
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private total As Double
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPr
Dim value As Double
Select Case e.KeyChar
Case "+"
If TextBox1.Text.Length > 0 Then
value = CDbl(TextBox1.Text)
total = total + value
addOperation("+ " & TextBox1.Text)
TextBox1.Text = ""
End If
e.Handled = True
Case "-"
If TextBox1.Text.Length > 0 Then
value = CDbl(TextBox1.Text)
total = total - value
addOperation("- " & TextBox1.Text)
TextBox1.Text = ""
End If
e.Handled = True
Case "*"
If TextBox1.Text.Length > 0 Then
value = CDbl(TextBox1.Text)
total = total * value
addOperation("* " & TextBox1.Text)
TextBox1.Text = ""
End If
e.Handled = True
Case "/"
If TextBox1.Text.Length > 0 Then
value = CDbl(TextBox1.Text)
total = total / value
addOperation("/ " & TextBox1.Text)
TextBox1.Text = ""
End If
e.Handled = True
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", Chr(8)
' Allow these keys to pass thru
Case Else
e.Handled = True
End Select
End Sub
Private Sub addOperation(ByVal op As String)
ListBox1.Items.Add(op)
ListBox1.Items.Add(total)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
End Sub
End Class