Results 1 to 7 of 7

Thread: [RESOLVED] VB2010 Simple calc program needs help

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2010
    Posts
    10

    Resolved [RESOLVED] VB2010 Simple calc program needs help

    Hello All,

    This is my first post, so if I'm doing something wrong, please let me know. I'm brand-spanking new to programming and I need a little help. I bought a membership to learn visual studio.net and started with the beginner series. I'm less than a third of the way through the videos and started a little programming of my own. I need help finishing it off...

    Here is the code:
    Code:
    Public Class Form1
    
        Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
            Dim Mortgage As Double
            Dim Electricity As Double
            Dim gas As Double
            Dim SWgas As Double
            Dim Car As Double
            Dim Water As Double
            Dim Cable As Double
            Dim Trash As Double
            Dim CCB As Double
            Dim Income As Double
            Dim Xtra As Double
            Dim Phone As Double
            Dim Retire As Double
            Dim Save As Double
    
            Mortgage = Double.Parse(txtMortgage.Text)
            Electricity = Double.Parse(txtElectricity.Text)
            gas = Double.Parse(txtGas.Text)
            SWgas = Double.Parse(txtSWgas.Text)
            Car = Double.Parse(txtCar.Text)
            Water = Double.Parse(txtWater.Text)
            Cable = Double.Parse(txtCable.Text)
            Trash = Double.Parse(txtTrash.Text)
            CCB = Double.Parse(txtCCB.Text)
            Income = Double.Parse(txtIncome.Text)
            Xtra = Double.Parse(txtXtra.Text)
            Phone = Double.Parse(txtPhone.Text)
            Retire = Double.Parse(txtRetire.Text)
            Save = Double.Parse(txtSave.Text)
        End Sub
        Function calculateIncome(ByVal Income As Double, ByVal Xtra As Double) As Double
            Return Income + Xtra
        End Function
        Function calculateBills(ByVal Mortgage As Double, ByVal Electricity As Double, ByVal gas As Double, ByVal SWgas As Double, ByVal Car As Double, ByVal Water As Double, ByVal Cable As Double, ByVal Trash As Double, ByVal CCB As Double, ByVal Phone As Double, ByVal Retire As Double, ByVal Save As Double) As Double
            Return Mortgage + Electricity + gas + SWgas + Car + Water + Cable + Trash + CCB + Phone + Retire + Save
        End Function
        Function calculatePlaymoney(ByVal calculateIncome As Double, ByVal calculateBills As Double)
            Return calculateBills - calculateIncome
        End Function
        Sub displayNumbers(ByVal calculateIncome As Double, ByVal calculateBills As Double, ByVal calculatePlaymoney As Double)
            txtTotalincome.Text = Format(calculateIncome.ToString(), "Currency")
            txttotBills.Text = Format(calculateBills.ToString(), "Currency")
            txtLeftover.Text = Format(calculatePlaymoney.ToString(), "Currency")
        End Sub
    
    End Class
    I would really appreciate any help you all could provide. Not looking for gimme's, but some nudging in the right direction is/would be awesome. I've also included a screenshot of the form in case it helps...


    Thanks,

    Mike
    Attached Images Attached Images  
    Last edited by ttownfire; May 17th, 2010 at 11:46 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB2010 Simple calc program needs help

    You might do better to ask an actual question rather than just posting some code and asking us to do something with it when we don't really know what you're looking for. What exactly are you trying to do and what exactly are you having trouble with?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2010
    Posts
    10

    Re: VB2010 Simple calc program needs help

    You are right, my bad.

    I'm looking to capture the the bills and total them. Also, capture the income and total it. Then subtract the two and display the result in the text boxes as labled. I'm not sure if I'm heading down the right path.

    I'm also looking for a good syntax reference...

    thank you,

    Mike

  4. #4
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: VB2010 Simple calc program needs help

    Looks ok to me, just handle the calculate button event and sum up your bills, then set:

    Code:
    totalBills.Text = total.ToString()
    Then sum up your total income and set the income textbox:

    Code:
    totalIncome.Text = income.ToString()
    Finally, set your difference with (income - total).ToString()

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2010
    Posts
    10

    Re: VB2010 Simple calc program needs help

    Thanks Monk... now where do I "call" them? I added the code but when I click the button nothing happens...

    Thanks.

  6. #6
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: VB2010 Simple calc program needs help

    Code:
    Public Class Form1
    
        Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
            Dim Mortgage As Double = Double.Parse(txtMortgage.Text)
            Dim Electricity As Double = Double.Parse(txtElectricity.Text)
            Dim gas As Double = Double.Parse(txtGas.Text)
            Dim SWgas As Double = Double.Parse(txtSWgas.Text)
            Dim Car As Double = Double.Parse(txtCar.Text)
            Dim Water As Double = Double.Parse(txtWater.Text)
            Dim Cable As Double = Double.Parse(txtCable.Text)
            Dim Trash As Double = Double.Parse(txtTrash.Text)
            Dim CCB As Double = Double.Parse(txtCCB.Text)
            Dim Income As Double = Double.Parse(txtIncome.Text)
            Dim Xtra As Double = Double.Parse(txtXtra.Text)
            Dim Phone As Double = Double.Parse(txtPhone.Text)
            Dim Retire As Double = Double.Parse(txtRetire.Text)
            Dim Save As Double = Double.Parse(txtSave.Text)
    	Dim calcIncome As Double = calculateIncome(Income, Xtra)
    	Dim calcBills As Double = calculateBills(Mortgage, Electricity, gas, SWgas, Car, Water, Cable, Trash, CCB, Phone, Retire, Save)
    	Dim calcPlay As Double = calculatePlaymoney(calcIncome, calcBills)
    	displayNumbers(calcIncome, calcBills, calcPlay)
    	End Sub
        Function calculateIncome(ByVal Income As Double, ByVal Xtra As Double) As Double
            Return Income + Xtra
        End Function
        Function calculateBills(ByVal Mortgage As Double, ByVal Electricity As Double, ByVal gas As Double, ByVal SWgas As Double, ByVal Car As Double, ByVal Water As Double, ByVal Cable As Double, ByVal Trash As Double, ByVal CCB As Double, ByVal Phone As Double, ByVal Retire As Double, ByVal Save As Double) As Double
            Return Mortgage + Electricity + gas + SWgas + Car + Water + Cable + Trash + CCB + Phone + Retire + Save
        End Function
        Function calculatePlaymoney(ByVal calculateIncome As Double, ByVal calculateBills As Double) As Double
            Return calculateBills - calculateIncome
        End Function
        Sub displayNumbers(ByVal calculateIncome As Double, ByVal calculateBills As Double, ByVal calculatePlaymoney As Double)
            txtTotalincome.Text = Format(calculateIncome.ToString(), "Currency")
            txttotBills.Text = Format(calculateBills.ToString(), "Currency")
            txtLeftover.Text = Format(calculatePlaymoney.ToString(), "Currency")
        End Sub
    
    End Class

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2010
    Posts
    10

    Re: [RESOLVED] VB2010 Simple calc program needs help

    Thank you Zach... I hate to bother you... but would you briefly explain why you did what you did?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width