6 Replies - 478 Views - Last Post: 28 February 2018 - 10:53 AM Rate Topic: -----

#1 rawoods   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-February 18

Workshop Selector homework - Problem with calculation button

Posted 28 February 2018 - 10:13 AM

(I apologize if I do not give enough info, I'm new to asking for programming help!) So I'm working on a homework assignment where you have to create a workshop selector in VB. This is the code I have written for my program and when I run my code it seems to work and there are no crashes but the calculate button isn't calculating the right amounts from the list box 'List of Costs'. The amounts it calculates seem to be way over the actual total cost that I calculate when I use my own calculator to see if the program is adding the totals right. Any help is appreciated!

 Public Class frmMain

    'Global Variables
    Private intTotal As Integer

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        'clears list boxes
        lstWorkshops.SelectedIndex = -1
        lstLocations.SelectedIndex = -1
        lstCosts.Items.Clear()

        'Clears label
        lblDisplayCosts.Text = String.Empty

    End Sub

    Private Sub btnWorkshop_Click(sender As Object, e As EventArgs) Handles btnWorkshop.Click
        'Variables
        Dim intDays, intFee, intStay, intNum As Integer

        Dim strworkshop As String = CStr(lstWorkshops.SelectedIndex())
        Dim strLocations As String = CStr(lstLocations.SelectedIndex())

        'Program

        'Finding which option selected for Workshops

        If lstWorkshops.SelectedItem Is Nothing Or lstLocations.SelectedItem Is Nothing Then
            MessageBox.Show("Please make sure you selected a workshop and location.")
        Else

            If lstWorkshops.SelectedItem Is "Handling Stress" Then
                intDays = 3
                intFee = 595
            ElseIf lstWorkshops.SelectedItem Is "Time Management" Then
                intDays = 3
                intFee = 695
            ElseIf lstWorkshops.SelectedItem Is "Supervision Skills" Then
                intDays = 3
                intFee = 995
            ElseIf lstWorkshops.SelectedItem Is "Negotiation" Then
                intDays = 5
                intFee = 1295
            Else
                intDays = 1
                intFee = 395
            End If

            'Finding which option selected for locations

            If lstLocations.SelectedItem Is "Austin" Then
                intStay = 95
            ElseIf lstLocations.SelectedItem Is "Chicago" Then
                intStay = 125
            ElseIf lstLocations.SelectedItem Is "Dallas" Then
                intStay = 110
            ElseIf lstLocations.SelectedItem Is "Orlando" Then
                intStay = 100
            ElseIf lstLocations.SelectedItem Is "Phoenix" Then
                intStay = 92
            Else
                intStay = 90
            End If

            'Calculate total cost of workshop & location
            intTotal = (intStay * intDays) + intFee

            'List box display
            lstCosts.Items.Add(intTotal.ToString("c"))
        End If

    End Sub

    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click

            'To calculate all the totals in lstCosts together and display it
        For x As Integer = 0 To lstCosts.Items.Count - 1
            intTotal = intTotal + CInt(lstCosts.Items(x))
        Next

        lblDisplayCosts.Text = intTotal.ToString("c")

    End Sub
End Class 


Is This A Good Question/Topic? 0
  • +

Replies To: Workshop Selector homework - Problem with calculation button

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14097
  • View blog
  • Posts: 56,497
  • Joined: 12-June 08

Re: Workshop Selector homework - Problem with calculation button

Posted 28 February 2018 - 10:15 AM

Is this really VB6 or VB.NET?
Was This Post Helpful? 0
  • +
  • -

#3 rawoods   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-February 18

Re: Workshop Selector homework - Problem with calculation button

Posted 28 February 2018 - 10:28 AM

View Postmodi123_1, on 28 February 2018 - 10:15 AM, said:

Is this really VB6 or VB.NET?

Whoops I apologise I got the VB6 vs VB.Net .caption and .Text examples mixed up this is vb.net, I will delete and repost in the vb.net form!
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14097
  • View blog
  • Posts: 56,497
  • Joined: 12-June 08

Re: Workshop Selector homework - Problem with calculation button

Posted 28 February 2018 - 10:29 AM

I just moved it from vb6 to vb.net.
Was This Post Helpful? 0
  • +
  • -

#5 rawoods   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-February 18

Re: Workshop Selector homework - Problem with calculation button

Posted 28 February 2018 - 10:32 AM

View Postmodi123_1, on 28 February 2018 - 10:29 AM, said:

I just moved it from vb6 to vb.net.

Thank you! I will double check from now on!
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14097
  • View blog
  • Posts: 56,497
  • Joined: 12-June 08

Re: Workshop Selector homework - Problem with calculation button

Posted 28 February 2018 - 10:38 AM

You may want to think about clearing your total out here. Right now that variable keeps growing and growing. Each time the 'calculate' button is clicked set it to 0.
82            intTotal = intTotal + CInt(lstCosts.Items(x))

Was This Post Helpful? 1
  • +
  • -

#7 rawoods   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-February 18

Re: Workshop Selector homework - Problem with calculation button

Posted 28 February 2018 - 10:53 AM

View Postmodi123_1, on 28 February 2018 - 10:38 AM, said:

You may want to think about clearing your total out here. Right now that variable keeps growing and growing. Each time the 'calculate' button is clicked set it to 0.
82            intTotal = intTotal + CInt(lstCosts.Items(x))


That fixed it! Thank you so so so much!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1