Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET General

Post new topic   Reply to topic
Please help with this calculator code!!!
View previous topic :: View next topic  
Author Message
jbillups
Newbie


Joined: 19 Nov 2005
Posts: 4
Location: Queens, NY

PostPosted: Nov 19th, 2005 03:09 PM    Post subject: Please help with this calculator code!!! Reply with quote

hi, i have this code, but i dont know how to fix it. Can someone please help me? I need it by Monday the 21st...

Code:
Public Class frmCalc
    Inherits System.Windows.Forms.Form

 " Windows Form Designer generated code " (not Shown)
   
    Dim BuildingNumber As Boolean
    Dim Accumulator As Decimal

    Const NoOperator As Integer = 1
    Const Addition As Integer = 2
    Const Subtraction As Integer = 3
    Const Multiplication As Integer = 4
    Const Division As Integer = 5
    Const EqualSign As Integer = 6

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

        Dim Accumulator As Decimal
        Dim LastOperation As Integer

        Me.lblOutput.Text = "0"
        Accumulator = 0
        LastOperation = Addition
        BuildingNumber = True

    End Sub

    Private Sub NumberPress(ByVal Num As Integer)

        If Me.lblOutput.Text = "0" Or Not BuildingNumber Then
            Me.lblOutput.Text = Format(Num)
            BuildingNumber = True
        Else
            Me.lblOutput.Text = Me.lblOutput.Text + Format(Num)
        End If
        Accumulator = Decimal.Parse(Me.lblOutput.Text)

    End Sub

    Private Sub OperatorPress(ByVal Operator As Integer)

        Dim NumberHolder As Decimal
        Dim OperationHolder As Integer
        Dim NumberEntered As Decimal
        Dim LastOperation As Integer

        NumberHolder = Accumulator
        OperationHolder = LastOperation
        NumberEntered = Decimal.Parse(Me.lblOutput.Text)

        Select Case Operator
            Case NoOperator
                NumberHolder = Decimal.Parse(Me.lblOutput.Text)
            Case Addition
                NumberHolder = NumberHolder + NumberEntered
            Case Subtraction
                NumberHolder = NumberHolder - NumberEntered
            Case Multiplication
                NumberHolder = NumberHolder * NumberEntered
            Case Division
                NumberHolder = NumberEntered / NumberHolder
        End Select

        Me.lblOutput.Text = Format(NumberHolder)
        If Operator = EqualSign Then
            LastOperation = Operator
        Else
            Operator = LastOperation
        End If

    End Sub

    Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click

        NumberPress(0)

    End Sub

    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click

        NumberPress(1)

    End Sub

    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click

        NumberPress(2)

    End Sub

    Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click

        NumberPress(3)

    End Sub

    Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click

        NumberPress(4)

    End Sub

    Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click

        NumberPress(4)

    End Sub

    Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click

        NumberPress(6)

    End Sub

    Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click

        NumberPress(7)

    End Sub

    Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click

        NumberPress(8)

    End Sub

    Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click

        NumberPress(9)

    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        OperatorPress(Addition)

    End Sub

    Private Sub btnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click

        OperatorPress(Subtraction)

    End Sub

    Private Sub ButtonMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMultiply.Click

        OperatorPress(Multiplication)

    End Sub

    Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click

        OperatorPress(Division)

    End Sub

    Private Sub btnEqualSign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEqualSign.Click

        OperatorPress(EqualSign)

    End Sub

    Private Sub frmCalc_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim Accumulator As Decimal
        Dim LastOperation As Integer

        Me.lblOutput.Text = "0"
        Accumulator = 0
        LastOperation = NoOperator
        BuildingNumber = True

    End Sub

    Private Sub PrimesUpTo(ByVal TopNumber As Integer)

        Dim CheckNumber As Integer
        Dim PrimeList As String
        Dim FirstPrime As Boolean
        Dim CheckThis As Integer
        Dim IsPrime As Boolean

        FirstPrime = True
        PrimeList = "No Primes"
        CheckNumber = 1
        Do While CheckNumber < TopNumber - 1
            IsPrime = True
            For CheckThis = 2 To CheckNumber
                If CheckNumber Mod CheckThis <> 0 Then
                    IsPrime = False
                    Exit For
                End If
            Next
            If (IsPrime) Then
                If (FirstPrime) Then
                    PrimeList = Format(CheckNumber)
                    FirstPrime = False
                Else
                    PrimeList = PrimeList + "," + Format(CheckNumber)
                End If
            End If
        Loop

        MessageBox.Show(PrimeList, "Prime Numbers", MessageBoxButtons.OK, MessageBoxIcon.Information)

    End Sub

    Private Sub btnPrimes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrimes.Click

        PrimesUpTo(Decimal.Round(Decimal.Parse(Me.lblOutput.Text), 0))

    End Sub
End Class


here is a picture of the application:
Back to top
View user's profile Send private message Visit poster's website AIM Address
DoobieKeebler
Moderator


Joined: 17 Jun 2005
Posts: 254
Location: 181°15'2.003"W, 93°5'16.956"N

PostPosted: Nov 21st, 2005 09:12 AM    Post subject: Reply with quote

What problems are you having with the code? What is it doing that it shouldn't, or not doing that it should?
_________________
Always take into account what a user would never ever in a million years do, because someone will.

"In theory, there's no difference between theory and practice. In practice, there is." -- Yogi Berra
Back to top
View user's profile Send private message
jbillups
Newbie


Joined: 19 Nov 2005
Posts: 4
Location: Queens, NY

PostPosted: Nov 21st, 2005 12:59 PM    Post subject: Reply with quote

The calculator cannot calculate anything. When you press a number key and then try to add, subtract & all of that, it shows as 0. Also, when you press primes, after you enter a number, a message is supposed to pop up and tell the user what numbers are prime up until the number you entered.

If it isnt possible to fix this then it's okay... I just wanted to know what I did wrong.
Back to top
View user's profile Send private message Visit poster's website AIM Address
jbillups
Newbie


Joined: 19 Nov 2005
Posts: 4
Location: Queens, NY

PostPosted: Nov 21st, 2005 07:00 PM    Post subject: Reply with quote

okay, i tried thinking of ways to change this, using the advice i was given but idk y its still not working right. i'm about to just give up.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET General All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic