Need help with an assignment for a dorm and meal calculator

jle7385

New member
Joined
Apr 11, 2011
Messages
2
Programming Experience
Beginner
I need some help with my school project. I have 3 of them so I may be back on later. Basically I have 2 list boxes, one on the main form to select a dorm, then one on the second form to select a meal plan. When I select them and hit calculate, enter, etc, it supposed to put the total in the main form. Here is my code so far. Anyone have any suggestions?

Main Form:

Public Class MainForm1


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

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
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 FarthingHall As Integer = 1200
Dim UniversitySuites As Integer = 1800
Dim dormResults As Integer
If ListBox1.SelectedIndex = -1 Then
MessageBox.Show("Select a dorm!", "Error")
End If
If ListBox1.SelectedIndex = 0 Then
lblDormCost.Text = AllenHall.ToString
dormResults = AllenHall
ElseIf ListBox1.SelectedIndex = 1 Then
lblDormCost.Text = PikeHall.ToString
dormResults = PikeHall
ElseIf ListBox1.SelectedIndex = 2 Then
lbldormcost.Text = FarthingHall.ToString
dormResults = FarthingHall
ElseIf ListBox1.SelectedIndex = 3 Then
lbldormcost.Text = UniversitySuites.ToString
dormResults = UniversitySuites
End If
End Sub

Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
ListBox1.ClearSelected()

End Sub


End Class


Second Form:

Public Class frmMealPlans

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

End Sub

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

End Sub

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim Meal7 As Integer = 560
Dim Meal14 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 = Meal7
ElseIf ListBox1.SelectedIndex = 1 Then
Results = Meal14
ElseIf ListBox1.SelectedIndex = 2 Then
Results = Unlimited
End If

MainForm1.lbldormcost.Text = CStr(MainForm1.dormResults + Results)
End Sub
End Class



I basically just doesn't do what I need it to do. Thanks.
 
Hey im not sure if this is your issue but it looks like your calling a variable from MainForm1 from your other form. If you change the scope of that variable to public and class-level it should work fine.

VB.NET:
Public Class MainForm1
    Public dormResults As Integer

    Private Sub btnSelectMeal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectMeal.Click
    ...
    End Sub
    
    ...
End Class
 
Back
Top