Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Having trouble with this dorm and meal plan code can someone point out what im d

ID: 3582960 • Letter: H

Question

Having trouble with this dorm and meal plan code can someone point out what im doing wrong ? Thank you.

Public Class MealPlan

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

    End Sub

    Private Sub BtnAddMealPlan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnter.Click

        'Define constant to assign the cost of Food

        Dim Meals7 As Integer = 1560

        Dim Meals14 As Integer = 2095

        Dim Unlimited As Integer = 2500

        Dim Results As Integer

        If ListBox1.SelectedIndex = -1 Then

            MessageBox.Show("Select at least one 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

        'Calculate Total Amount as DormCost+FoodCost

        Total = Total + Result

        Mainform1.txtTotal = Total.toString 'Assigning the total Amount to be displayed on Main Forms Total Text Field

    End Sub

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click

        Me.Close()

    End Sub

End Class

Public Class Main

    Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'Declaration of variable for Dormitary Cost, Food Cost and TotalAmount to be paid

        Dim dormCost As Decimal = 0

        Dim FoodCost As Decimal = 0

        Dim Total As Decimal = 0

    End Sub

    'Main module execute when load the form or application

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

        ' Declaration of constants to define the cost off Hall

        Dim frmMainForm As New Main

        Dim AllenHall As Integer = 2500

            Dim PikeHall As Integer = 2200

            Dim FathingHall As Integer = 2100

            Dim UniversitySuites As Integer = 2800

        frmMainForm.ShowDialog()

    End Sub

        'module which execute the code when Exit Button is clicked on the main form

        'which closes the form

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

            ' Closes the forms

            Me.Close()

        End Sub

        'Module which execute the code when user clicks on Clear Button of the form

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

        'Clear the Text Boxvalues to assign blank value

        txtDorm.Text = ""

        txtFoodPlan.Text = ""

        txtTotal.Text = ""

        End Sub

        Private Sub btnaddMealPlan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

        If ListBox1.SelectedText = -1 Then

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

        End If

        If ListBox1.SelectedRtf = 0 Then

            txtDorm.Text = AllenHall.ToString

            txtDorm = AllenHall

        ElseIf ListBox1.SelectedRtf = 1 Then

            txtDorm.Text = PikeHall.ToString

            txtDorm = PikeHall

        ElseIf ListBox1.SelectedRtf = 2 Then

            txtDorm.Text = FarthingHall.ToString

            txtDorm = FarthingHall

        ElseIf ListBox1.SelectedRtf = 3 Then

            txtDorm.Text = UniversitySuites.ToString

            txtDorm = UniversitySuites

        End If

        'calculate Total Amount as dormCost+FoodCost

        txtTotal = txtFoodPlan txtDorm

        txtTotal = Total.ToString 'assignment of the Total Amount value to Total Text Field of Main Form

    End Sub

    Private Sub btnViewMealPlan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewMealPlan.Click

        Dim frmMealPlan As New frmMealPlan

        frmMealPlan.ShowDialog()

    End Sub

End Class

This is starting out with visual basic 7th edition btw

Explanation / Answer

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

Private Sub BtnAddMealPlan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnter.Click
'Define constant to assign the cost of Food

Dim Meals7 As Integer = 1560
Dim Meals14 As Integer = 2095
Dim Unlimited As Integer = 2500
Dim Results As Integer

If ListBox1.SelectedIndex = -1 Then
MessageBox.Show("Select at least one 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
Else
   Results = 0

End If

'Calculate Total Amount as DormCost+FoodCost
Total = Cint(Mainform1.txtTotal) + Result
Mainform1.txtTotal = Total.toString 'Assigning the total Amount to be displayed on Main Forms Total Text Field

End Sub


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

End Class


Public Class Main
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Declaration of variable for Dormitary Cost, Food Cost and TotalAmount to be paid
Dim dormCost As Decimal = 0
Dim FoodCost As Decimal = 0
Dim Total As Decimal = 0
End Sub

'Main module execute when load the form or application
Private Sub MainForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

' Declaration of constants to define the cost off Hall

Dim frmMainForm As New Main
Dim AllenHall As Integer = 2500
Dim PikeHall As Integer = 2200
Dim FathingHall As Integer = 2100
Dim UniversitySuites As Integer = 2800

frmMainForm.ShowDialog()
End Sub

'module which execute the code when Exit Button is clicked on the main form
'which closes the form

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

'Module which execute the code when user clicks on Clear Button of the form

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

'Clear the Text Boxvalues to assign blank value
txtDorm.Text = ""
txtFoodPlan.Text = ""
txtTotal.Text = ""
End Sub



Private Sub btnaddMealPlan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
If ListBox1.SelectedText = -1 Then
MessageBox.Show("Select a meal plan", "Error")
End If
If ListBox1.SelectedIndex = 0 Then
txtDorm.Text = AllenHall.ToString
txtDorm = AllenHall
ElseIf ListBox1.SelectedIndex = 1 Then
txtDorm.Text = PikeHall.ToString
txtDorm = PikeHall
ElseIf ListBox1.SelectedIndex = 2 Then
txtDorm.Text = FarthingHall.ToString
txtDorm = FarthingHall
ElseIf ListBox1.SelectedIndex = 3 Then
txtDorm.Text = UniversitySuites.ToString
txtDorm = UniversitySuites
End If
'calculate Total Amount as dormCost+FoodCost
Total = CINT(txtFoodPlan.Text)+CINT(txtDorm.Text)
Mainform1.txtTotal = Total.ToString 'assignment of the Total Amount value to Total Text Field of Main Form

End Sub

Private Sub btnViewMealPlan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewMealPlan.Click
Dim frmMealPlan As New frmMealPlan
frmMealPlan.ShowDialog()
End Sub


End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote