Solved

old time calculator

Posted on 2004-04-17
6
346 Views
Last Modified: 2010-04-24
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.
0
Comment
Question by:TexRedneck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 10851168
This what you are looking for?

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.IContainer

    '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.TextBox
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.ListBox1 = New System.Windows.Forms.ListBox
        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.ListBox1)
        Me.Controls.Add(Me.TextBox1)
        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.KeyPressEventArgs) Handles TextBox1.KeyPress
        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
0
 

Author Comment

by:TexRedneck
ID: 10853909
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.IContainer

    '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.MenuItem
    Friend WithEvents lblCurrNum As System.Windows.Forms.Label
    Friend WithEvents mmuMain As System.Windows.Forms.MainMenu
    Friend WithEvents fdSelectFont As System.Windows.Forms.FontDialog
    Friend WithEvents cdSelectFontColor As System.Windows.Forms.ColorDialog
    Friend WithEvents btn7 As System.Windows.Forms.Button
    Friend WithEvents btn8 As System.Windows.Forms.Button
    Friend WithEvents btn9 As System.Windows.Forms.Button
    Friend WithEvents btnDivide As System.Windows.Forms.Button
    Friend WithEvents btn4 As System.Windows.Forms.Button
    Friend WithEvents btn5 As System.Windows.Forms.Button
    Friend WithEvents btn6 As System.Windows.Forms.Button
    Friend WithEvents btnMultiply As System.Windows.Forms.Button
    Friend WithEvents btn1 As System.Windows.Forms.Button
    Friend WithEvents btn2 As System.Windows.Forms.Button
    Friend WithEvents btn3 As System.Windows.Forms.Button
    Friend WithEvents btnSubtract As System.Windows.Forms.Button
    Friend WithEvents btn0 As System.Windows.Forms.Button
    Friend WithEvents btnDecimalPlace As System.Windows.Forms.Button
    Friend WithEvents btnClear As System.Windows.Forms.Button
    Friend WithEvents btnAdd As System.Windows.Forms.Button
    Friend WithEvents mmuFormatColors As System.Windows.Forms.MenuItem
    Friend WithEvents mmuFormatFontColors As System.Windows.Forms.MenuItem
    Friend WithEvents mmuFormatFonts As System.Windows.Forms.MenuItem
    Friend WithEvents cdSelectColors As System.Windows.Forms.ColorDialog
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents lblTape As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.lblCurrNum = New System.Windows.Forms.Label
        Me.mmuMain = New System.Windows.Forms.MainMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.mmuFormatColors = New System.Windows.Forms.MenuItem
        Me.mmuFormatFontColors = New System.Windows.Forms.MenuItem
        Me.mmuFormatFonts = New System.Windows.Forms.MenuItem
        Me.fdSelectFont = New System.Windows.Forms.FontDialog
        Me.cdSelectColors = New System.Windows.Forms.ColorDialog
        Me.cdSelectFontColor = New System.Windows.Forms.ColorDialog
        Me.btn7 = New System.Windows.Forms.Button
        Me.btn8 = New System.Windows.Forms.Button
        Me.btn9 = New System.Windows.Forms.Button
        Me.btnDivide = New System.Windows.Forms.Button
        Me.btn4 = New System.Windows.Forms.Button
        Me.btn5 = New System.Windows.Forms.Button
        Me.btn6 = New System.Windows.Forms.Button
        Me.btnMultiply = New System.Windows.Forms.Button
        Me.btn1 = New System.Windows.Forms.Button
        Me.btn2 = New System.Windows.Forms.Button
        Me.btn3 = New System.Windows.Forms.Button
        Me.btnSubtract = New System.Windows.Forms.Button
        Me.btn0 = New System.Windows.Forms.Button
        Me.btnDecimalPlace = New System.Windows.Forms.Button
        Me.btnClear = New System.Windows.Forms.Button
        Me.btnAdd = New System.Windows.Forms.Button
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.lblTape = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'lblCurrNum
        '
        Me.lblCurrNum.BackColor = System.Drawing.Color.White
        Me.lblCurrNum.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        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.ContentAlignment.MiddleLeft
        '
        'mmuMain
        '
        Me.mmuMain.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mmuFormatColors, Me.mmuFormatFontColors, Me.mmuFormatFonts})
        Me.MenuItem1.Text = "Format"
        '
        'mmuFormatColors
        '
        Me.mmuFormatColors.Index = 0
        Me.mmuFormatColors.Text = "Background Colors"
        '
        'mmuFormatFontColors
        '
        Me.mmuFormatFontColors.Index = 1
        Me.mmuFormatFontColors.Text = "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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        Me.btnDivide.DialogResult = System.Windows.Forms.DialogResult.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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        Me.btnMultiply.DialogResult = System.Windows.Forms.DialogResult.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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        Me.btnSubtract.DialogResult = System.Windows.Forms.DialogResult.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.NavajoWhite
        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.BackColor = System.Drawing.Color.NavajoWhite
        Me.btnDecimalPlace.Location = New System.Drawing.Point(72, 192)
        Me.btnDecimalPlace.Name = "btnDecimalPlace"
        Me.btnDecimalPlace.Size = New System.Drawing.Size(36, 36)
        Me.btnDecimalPlace.TabIndex = 15
        Me.btnDecimalPlace.Text = "."
        '
        'btnClear
        '
        Me.btnClear.BackColor = System.Drawing.Color.NavajoWhite
        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.NavajoWhite
        Me.btnAdd.DialogResult = System.Windows.Forms.DialogResult.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.BorderStyle.Fixed3D
        Me.lblTape.FlatStyle = System.Windows.Forms.FlatStyle.System
        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.ContentAlignment.TopRight
        '
        'frmMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.BurlyWood
        Me.ClientSize = New System.Drawing.Size(466, 289)
        Me.Controls.Add(Me.lblTape)
        Me.Controls.Add(Me.btnAdd)
        Me.Controls.Add(Me.btnClear)
        Me.Controls.Add(Me.btnDecimalPlace)
        Me.Controls.Add(Me.btn0)
        Me.Controls.Add(Me.btnSubtract)
        Me.Controls.Add(Me.btn3)
        Me.Controls.Add(Me.btn2)
        Me.Controls.Add(Me.btn1)
        Me.Controls.Add(Me.btnMultiply)
        Me.Controls.Add(Me.btn6)
        Me.Controls.Add(Me.btn5)
        Me.Controls.Add(Me.btn4)
        Me.Controls.Add(Me.btnDivide)
        Me.Controls.Add(Me.btn9)
        Me.Controls.Add(Me.btn8)
        Me.Controls.Add(Me.btn7)
        Me.Controls.Add(Me.lblCurrNum)
        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(ByVal 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(ByVal 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.KeyPressEventArgs) Handles MyBase.KeyPress
        If System.Char.IsDigit(e.KeyChar) 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.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 10854707
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.IContainer

    '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.MenuItem
    Friend WithEvents lblCurrNum As System.Windows.Forms.Label
    Friend WithEvents mmuMain As System.Windows.Forms.MainMenu
    Friend WithEvents fdSelectFont As System.Windows.Forms.FontDialog
    Friend WithEvents cdSelectFontColor As System.Windows.Forms.ColorDialog
    Friend WithEvents btn7 As System.Windows.Forms.Button
    Friend WithEvents btn8 As System.Windows.Forms.Button
    Friend WithEvents btn9 As System.Windows.Forms.Button
    Friend WithEvents btnDivide As System.Windows.Forms.Button
    Friend WithEvents btn4 As System.Windows.Forms.Button
    Friend WithEvents btn5 As System.Windows.Forms.Button
    Friend WithEvents btn6 As System.Windows.Forms.Button
    Friend WithEvents btnMultiply As System.Windows.Forms.Button
    Friend WithEvents btn1 As System.Windows.Forms.Button
    Friend WithEvents btn2 As System.Windows.Forms.Button
    Friend WithEvents btn3 As System.Windows.Forms.Button
    Friend WithEvents btnSubtract As System.Windows.Forms.Button
    Friend WithEvents btn0 As System.Windows.Forms.Button
    Friend WithEvents btnDecimalPlace As System.Windows.Forms.Button
    Friend WithEvents btnClear As System.Windows.Forms.Button
    Friend WithEvents btnAdd As System.Windows.Forms.Button
    Friend WithEvents mmuFormatColors As System.Windows.Forms.MenuItem
    Friend WithEvents mmuFormatFontColors As System.Windows.Forms.MenuItem
    Friend WithEvents mmuFormatFonts As System.Windows.Forms.MenuItem
    Friend WithEvents cdSelectColors As System.Windows.Forms.ColorDialog
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.lblCurrNum = New System.Windows.Forms.Label
        Me.mmuMain = New System.Windows.Forms.MainMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.mmuFormatColors = New System.Windows.Forms.MenuItem
        Me.mmuFormatFontColors = New System.Windows.Forms.MenuItem
        Me.mmuFormatFonts = New System.Windows.Forms.MenuItem
        Me.fdSelectFont = New System.Windows.Forms.FontDialog
        Me.cdSelectColors = New System.Windows.Forms.ColorDialog
        Me.cdSelectFontColor = New System.Windows.Forms.ColorDialog
        Me.btn7 = New System.Windows.Forms.Button
        Me.btn8 = New System.Windows.Forms.Button
        Me.btn9 = New System.Windows.Forms.Button
        Me.btnDivide = New System.Windows.Forms.Button
        Me.btn4 = New System.Windows.Forms.Button
        Me.btn5 = New System.Windows.Forms.Button
        Me.btn6 = New System.Windows.Forms.Button
        Me.btnMultiply = New System.Windows.Forms.Button
        Me.btn1 = New System.Windows.Forms.Button
        Me.btn2 = New System.Windows.Forms.Button
        Me.btn3 = New System.Windows.Forms.Button
        Me.btnSubtract = New System.Windows.Forms.Button
        Me.btn0 = New System.Windows.Forms.Button
        Me.btnDecimalPlace = New System.Windows.Forms.Button
        Me.btnClear = New System.Windows.Forms.Button
        Me.btnAdd = New System.Windows.Forms.Button
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'lblCurrNum
        '
        Me.lblCurrNum.BackColor = System.Drawing.Color.White
        Me.lblCurrNum.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        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.ContentAlignment.MiddleLeft
        '
        'mmuMain
        '
        Me.mmuMain.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mmuFormatColors, Me.mmuFormatFontColors, Me.mmuFormatFonts})
        Me.MenuItem1.Text = "Format"
        '
        'mmuFormatColors
        '
        Me.mmuFormatColors.Index = 0
        Me.mmuFormatColors.Text = "Background Colors"
        '
        'mmuFormatFontColors
        '
        Me.mmuFormatFontColors.Index = 1
        Me.mmuFormatFontColors.Text = "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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        Me.btnDivide.DialogResult = System.Windows.Forms.DialogResult.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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        Me.btnMultiply.DialogResult = System.Windows.Forms.DialogResult.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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        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.NavajoWhite
        Me.btnSubtract.DialogResult = System.Windows.Forms.DialogResult.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.NavajoWhite
        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.BackColor = System.Drawing.Color.NavajoWhite
        Me.btnDecimalPlace.Location = New System.Drawing.Point(72, 192)
        Me.btnDecimalPlace.Name = "btnDecimalPlace"
        Me.btnDecimalPlace.Size = New System.Drawing.Size(36, 36)
        Me.btnDecimalPlace.TabIndex = 15
        Me.btnDecimalPlace.Text = "."
        '
        'btnClear
        '
        Me.btnClear.BackColor = System.Drawing.Color.NavajoWhite
        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.NavajoWhite
        Me.btnAdd.DialogResult = System.Windows.Forms.DialogResult.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.BorderStyle.None
        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.ScrollBars.Vertical
        Me.TextBox1.Size = New System.Drawing.Size(136, 264)
        Me.TextBox1.TabIndex = 18
        Me.TextBox1.Text = ""
        Me.TextBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'frmMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.BurlyWood
        Me.ClientSize = New System.Drawing.Size(466, 289)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.btnAdd)
        Me.Controls.Add(Me.btnClear)
        Me.Controls.Add(Me.btnDecimalPlace)
        Me.Controls.Add(Me.btn0)
        Me.Controls.Add(Me.btnSubtract)
        Me.Controls.Add(Me.btn3)
        Me.Controls.Add(Me.btn2)
        Me.Controls.Add(Me.btn1)
        Me.Controls.Add(Me.btnMultiply)
        Me.Controls.Add(Me.btn6)
        Me.Controls.Add(Me.btn5)
        Me.Controls.Add(Me.btn4)
        Me.Controls.Add(Me.btnDivide)
        Me.Controls.Add(Me.btn9)
        Me.Controls.Add(Me.btn8)
        Me.Controls.Add(Me.btn7)
        Me.Controls.Add(Me.lblCurrNum)
        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(ByVal 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.text))
    End Sub

    Private Sub frmMain_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        If System.Char.IsDigit(e.KeyChar) 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
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:TexRedneck
ID: 10860053
That works great thanks but I need it to do like this:
7+
7+
14
7-
7
4-
3
Can you do this?
Thanks
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 10862569
You only need to make four changes...

Change:
    TextBox1.Text = TextBox1.Text & "+ " & lblCurrNum.Text & vbCrLf
to:
    TextBox1.Text = TextBox1.Text & lblCurrNum.Text & "+" & vbCrLf

Change:
    TextBox1.Text = TextBox1.Text & "- " & lblCurrNum.Text & vbCrLf
to:
    TextBox1.Text = TextBox1.Text & lblCurrNum.Text & "-" & vbCrLf


Change:
    TextBox1.Text = TextBox1.Text & "* " & lblCurrNum.Text & vbCrLf
to:
    TextBox1.Text = TextBox1.Text & lblCurrNum.Text & "*" & vbCrLf


Change:
    TextBox1.Text = TextBox1.Text & "/ " & lblCurrNum.Text & vbCrLf
to:
    TextBox1.Text = TextBox1.Text & lblCurrNum.Text & "/" & vbCrLf


Regards,

Idle_Mind
0
 

Author Comment

by:TexRedneck
ID: 10870088
Thanks so much.
Tex
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question