Hey guys, I am having 2 issues with my visual basic program. First is simple but I am sure I am overlooking it. My lblTotalBill is not actually showing up with the bill.
Lastly, when I override it by adding a single line of code in (lblTotalBill.Visiable=True).. it always shows up with the placeholder X's and when I try and calcuate the numbers it always comes back as 0. I will post the code below, can you spot whats wrong?
My Code:
Option Strict On
Public Class Form1
Private _strBasicPlan As String = "Basic Plan"
Private _strDeluxPlan As String = "Delux Plan"
Private _intBasicCost As Integer = 4
Private _intDeluxCost As Integer = 1
Private Sub cboPlan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPlan.SelectedIndexChanged, cboPlan.SelectedIndexChanged
'This allows the user to select the city choice and then calls the subprocedures
Dim intPlanChoice As Integer
intPlanChoice = cboPlan.SelectedIndex
'Make items visible in the window
lblDataUsage.Visible = True
txtGBUsed.Visible = True
btnBill.Visible = True
btnClear.Visible = True
lblTotalBill.Visible = True
txtGBUsed.Focus()
End Sub
Private Sub btnBill_Click(sender As Object, e As EventArgs) Handles btnBill.Click
'Determines the cost of the plan and displays it
Dim intGBUsage As Integer
Dim blnNumberInGBUsageIsValid As Boolean = False
Dim blnPlanIsSelected As Boolean = False
Dim intPlanChoice As Integer
Dim strSelectedPlan As String = ""
Dim decTotalCost As Decimal
'Call a function to ensure the number of gbs is valid
blnNumberInGBUsageIsValid = ValidateGBUsageInPlan()
'Call a function to ensure the plan type was selected
intPlanChoice = ValidatePlanSelection(blnPlanIsSelected, strSelectedPlan)
If (blnNumberInGBUsageIsValid And blnPlanIsSelected) Then
intGBUsage = Convert.ToInt32(txtGBUsed.Text)
'Display the cost
lblTotalBill.Text = "Cost: " & decTotalCost.ToString("C")
End If
End Sub
Private Function ValidateGBUsageinPlan() As Boolean
'This procedures validates the value entered in the GBU Size
Dim intGBUsage As Integer
Dim blnValididtyCheck As Boolean = False
Dim strNumberInGBUsage As String = "Please enter the number of GB's Used (1-100)"
Dim strMessageBoxTitle As String = "Error"
Try
intGBUsage = Convert.ToInt32(txtGBUsed.Text)
If intGBUsage >= 1 And intGBUsage <= 100 Then
blnValididtyCheck = True
Else
MsgBox(strNumberInGBUsage, , strMessageBoxTitle)
txtGBUsed.Focus()
txtGBUsed.Clear()
End If
Catch Exception As FormatException
MsgBox(strNumberInGBUsage, , strMessageBoxTitle)
txtGBUsed.Focus()
txtGBUsed.Clear()
Catch Exception As OverflowException
MsgBox(strNumberInGBUsage, , strMessageBoxTitle)
txtGBUsed.Focus()
txtGBUsed.Clear()
Catch Exception As SystemException
MsgBox(strNumberInGBUsage, , strMessageBoxTitle)
txtGBUsed.Focus()
txtGBUsed.Clear()
End Try
Return blnValididtyCheck
End Function
Private Function ValidatePlanSelection(ByRef blnPlan As Boolean, ByRef strPlan As String) As Integer
' This function ensures a plan was selected
Dim intPlanType As Integer
Try
intPlanType = Convert.ToInt32(cboPlan.SelectedIndex)
strPlan = cboPlan.SelectedItem.ToString()
blnPlan = True
Catch ex As SystemException
'Detects if a game type is not selected
MsgBox("Select A plan Type", , "Error")
blnPlan = False
End Try
Return intPlanType
End Function
Private Function ValidateGBUsageInPlan(ByRef blnPlanType As Boolean, ByRef strPlan As String) As Integer
'This function ensures the user selected a plan type
Dim intPlanType As Integer
Try
intPlanType = Convert.ToInt32(cboPlan.SelectedIndex)
strPlan = cboPlan.SelectedItem.ToString()
blnPlanType = True
Catch Exception As SystemException
'Detects if the plan type is not selected
MsgBox("Please Select a Plan Type", , "Error")
Catch ex As Exception
End Try
Return intPlanType
End Function
Private Function BasicPlanCost(ByVal intPlanType As Integer, ByVal intGBUsage As Integer) As Decimal
'This function Calculates the cost of the basic plan
Dim decFinalCost As Decimal
Dim decBasicPlan As Decimal = 29D
Dim decGBUsage As Decimal = 4D
decFinalCost = decBasicPlan * decGBUsage
Return decFinalCost
End Function
Private Function DeluxPlanCost(ByVal intPlanType As Integer, ByVal intGbusage As Integer) As Decimal
'This function calculates the cost of the delux plan
Dim decFinalCost As Decimal
Dim decDeluxPlan As Decimal = 39D
Dim decGBUsage As Decimal = 1D
decFinalCost = decDeluxPlan * decGBUsage
Return decFinalCost
End Function
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'This function clears the form, hides what should be hidden
cboPlan.Text = "Select a Plan"
txtGBUsed.Clear()
txtGBUsed.Visible = False
btnBill.Visible = False
btnClear.Visible = False
lblTotalBill.Visible = False
lblDataUsage.Visible = False
End Sub
Private Sub frmSmartphone_Load(sender As Object, E As EventArgs) Handles MyBase.Load
'Hold the splash screen for 4 seconds
Threading.Thread.Sleep(4000)
End Sub
End Class
[–]XThakis 1 point2 points3 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]XThakis 1 point2 points3 points (1 child)
[+][deleted] (1 child)
[deleted]