This is for a challenge I must do. It is two forms. I have it almost done, but my second form is not giving me a total. I can't figure it out. Thanks in advance!!

Here's the code:

Main form 1

Public Class MainForm1

    Private Sub MainForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim frmMainForm1 As New MainForm1

        frmMainForm1.ShowDialog()

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        ' Closes the forms
        Me.Close()
    End Sub

  
    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Dim AllenHall As Integer = 1500
        Dim PikeHall As Integer = 1600
        Dim FathingHall As Integer = 1200
        Dim UniversitySuites As Integer = 1800

        If ListBox1.SelectedIndex = -1 Then


            MessageBox.Show("Select a meal plan", "Error")
        End If


        If ListBox1.SelectedIndex = 0 Then
            lblDormCost.Text = AllenHall.ToString
        ElseIf ListBox1.SelectedIndex = 1 Then
            lblDormCost.Text = PikeHall.ToString
        ElseIf ListBox1.SelectedIndex = 2 Then
            lblDormCost.Text = FathingHall.ToString
        ElseIf ListBox1.SelectedIndex = 3 Then
            lblDormCost.Text = UniversitySuites.ToString


        End If
    End Sub


    Private Sub btnSelectMeal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectMeal.Click
        Dim frmMealPlans As New frmMealPlans

        frmMealPlans.ShowDialog()



    End Sub


    Public Sub frmMealPlans 




    End Sub
End Class

(Form 2)

Public Class frmMealPlans

    Private Property Results As Object

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

    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        ' Close the form.
        Me.Close()

    End Sub


    Private Sub BtnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnter.Click
        Dim Meals7 As Integer = 560
        Dim Meals14 As Integer = 1095
        Dim Unlimited As Integer = 1500
        Dim Results As Integer

        If ListBox1.SelectedIndex = -1 Then
            MessageBox.Show("Select a meal plan", "Error")

        End If

        If ListBox1.SelectedIndex = 0 Then
            Results = Meals7
        ElseIf ListBox1.SelectedIndex = 1 Then
            Results = Meals14
        ElseIf ListBox1.SelectedIndex = 2 Then
            Results = Unlimited

        End If


    End Sub
End Class

Recommended Answers

All 3 Replies

I figured it out for ya. I added some labels for testing purposes, and replaced the If/thens with case statements, as well as added a call statement for adding the numbers.

Also note that the form name was changed(my computer was whining about no form 1, so I changed the form name), but I tested it out and it works

Form 1

Public Class Form1

    Dim totCost As Integer = 0

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim frmMainForm1 As New Form1

        frmMainForm1.ShowDialog()

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        ' Closes the forms
        Me.Close()
    End Sub


    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Dim AllenHall As Integer = 1500
        Dim PikeHall As Integer = 1600
        Dim FathingHall As Integer = 1200
        Dim UniversitySuites As Integer = 1800
        Dim Cost As Integer


        Select Case ListBox1.SelectedIndex

            Case -1

                MessageBox.Show("Select a meal plan", "Error")

            Case 0

                lblDormCost.Text = AllenHall.ToString
                Cost = AllenHall

            Case 1

                lblDormCost.Text = PikeHall.ToString
                Cost = PikeHall

            Case 2

                lblDormCost.Text = FathingHall.ToString
                Cost = FathingHall

            Case 3

                lblDormCost.Text = UniversitySuites.ToString
                Cost = UniversitySuites

        End Select

    End Sub

    Public Sub btnSelectMeal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectMeal.Click
        Dim frmMealPlans As New frmMealPlans

        frmMealPlans.Show()




    End Sub


   
End Class

Form 2

Public Class frmMealPlans

    Dim totCost As Integer
    Dim hallcost As Integer
    Dim Results As Integer




    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        ' Close the form.
        Me.Close()

    End Sub


    Private Sub BtnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
        Dim Meals7 As Integer = 560
        Dim Meals14 As Integer = 1095
        Dim Unlimited As Integer = 1500



        Select Case ListBox1.SelectedIndex
            Case -1
                MessageBox.Show("Select a meal plan", "Error")
            Case 0
                Results = Meals7
            Case 1
                Results = Meals14
            Case 2
                Results = Unlimited
        End Select

        Label1.Text = Results.ToString

        Call Calculate(hallcost)


    End Sub
    Public Sub Calculate(ByVal hallcost As Integer)

        Dim AllenHall As Integer = 1500
        Dim PikeHall As Integer = 1600
        Dim FathingHall As Integer = 1200
        Dim UniversitySuites As Integer = 1800
        Dim Cost As Integer


        Select Case Form1.ListBox1.SelectedIndex

            Case 0

                Form1.lblDormCost.Text = PikeHall.ToString
                Cost = AllenHall

            Case 1

                Form1.lblDormCost.Text = PikeHall.ToString
                Cost = PikeHall

            Case 2

                Form1.lblDormCost.Text = FathingHall.ToString
                Cost = FathingHall

            Case 3

                Form1.lblDormCost.Text = UniversitySuites.ToString
                Cost = UniversitySuites

        End Select

        totCost = Cost + Results
        Form1.lblMealcost.Text = totCost.ToString

    End Sub
End Class

Thank you so much...this has been driving me nuts!

no problem, happy to help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.