Public Class Rental
Private Sub Rental_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
'Enables user to exit program
Me.Close()
End Sub
Private Sub Rates_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rates.Click
'Code dislplays rental information in the information list box
Dim fmtStr As String = "{0, -10}{1, 15}{1, 15}"
Info.Items.Clear()
Info.Items.Add(String.Format(fmtStr, "Price of Equipment", "Half-Day", "Full-Day"))
Info.Items.Add(String.Format(fmtStr, "1. Rug Cleaner", "$16.00", "$24.00"))
Info.Items.Add(String.Format(fmtStr, "2. Lawn Mower", "$12.00", "$18.00"))
Info.Items.Add(String.Format(fmtStr, "3. Paint Sprayer", "$20.00", "$30.00"))
End Sub
Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
'Clears input and bill information text boxes
Item.Clear()
Duration.Clear()
Bill.ClearSelected()
End Sub
Private Sub Bill_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bill.SelectedIndexChanged
End Sub
Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calculate.Click
'varialbes
Dim Bill As Integer
Dim H As Double
Dim F As Integer
Select Case Bill
Case 1
If Bill = 1 & H = "1/2 Day Rug Cleaner, $30 (deposit) + $16 (rental fee) = $46" Then
ElseIf Bill = 1 & F = "1 Day Rug Cleaner, $30 (deposit) + $24 (rental fee) = $54" Then
End If
Case 2
If Bill = 2 & H = "1/2 Day Lawn Mower Rental, $30 (deposit) + $12 (rental fee) = $42" Then
ElseIf Bill = 2 & F = "1 Day Lawn Mower Rental, $30 (deposit) + $18 (rental fee) = $48" Then
End If
Case 3
If Bill = 3 & H = "1/2 Day Paint Sprayer Rental, $30 (deposit) + $20 (rental fee) = $50" Then
ElseIf Bill = 3 & F = "1 Day Lawn Mower Rental, $30 (deposit) + $30 (rental fee) = $60" Then
End If
End Select
Calculate.Text = "Receipt from Hill's Rental Equipment"
End Sub
End Class
Issues with case statement output
Page 1 of 14 Replies - 854 Views - Last Post: 31 August 2009 - 08:48 AM
#1
Issues with case statement output
Posted 16 June 2009 - 12:14 PM
I am working on another project to sharpen my visual basic.net skills. I wanted to make a simple equipment rental program. The program has a button to diplay the rental items and rates in the first list box and a button to display the bill in the second list box based on the user input of the item the user wants to rent in the first text box and F or H for full day or half day rental in the second text box. The program runs and the rental information displays when the user clicks the display rental rates button; however the bill list box does not display the bill for the input the user has entered into the item and duration text boxes. Could someone please tell me how to fix this issue as I am doing a trial program here so that I can create a program for a friend's small business and am a new BSIT/SE graduate and have never had to create a program like this before, thanks.
Replies To: Issues with case statement output
#2
Re: Issues with case statement output
Posted 16 June 2009 - 12:51 PM
If Bill = 1 & H = "1/2 Day Rug Cleaner, $30 (deposit) + $16 (rental fee) = $46" Then
....
to be frank i don't think this code will work ... to make to if statements u can use the keyword And , & in other hand is used to add strings values
If (Bill = 1) and ( H = "1/2 Day Rug Cleaner, $30 (deposit) + $16 (rental fee) = $46") Then
another things , when u check about values it is better to use Boolean value .... like to make a boolean variable called Full day to check if it is full day rent , if it is false then it is half day rent , it is easier to check it that way instead of making string check
if the rent will go for full day then Fullday = true
hope u can do it right in this way
#3
Re: Issues with case statement output
Posted 16 June 2009 - 01:37 PM
1) Please use MEANINGFUL variable names - e.g. H should be HalfDayCost or something equivalent.
2) You arrive in Calculate_Click and then declare the Bill variable. It is not assigned any value and then you try to do a case statement on an undefined value. You need to set Bill from somewhere. The declaration of Bill as a local Integer probably overrides the declaration of Bill as a CheckBox in your design for the duration of that method so remove it from the Dim statements.
3) H is defined as a Double and you assign it a String value
4) F is defined as an Integer and you assign it a String value
5) You have a Rug Cleaner in the Sprayer rental case.
6) The case statement already knows what Bill is, so get rid of the "If Bill = 2 Then" logic in the case statement elements
7) You should be able to generate the billing string incrementally as you only need one of them. e.g.
If Duration = Half Then ' This line will depend on your control used
BillString = "1/2 Day "
Else
BillString = "1 Day "
End If
then in the case statement add...
BillString &= "Paint Sprayer Deposit $30 + "
and another Duration if statement that adds the cost for the chosen duration.
8) Looking at this, you are generally not understanding the difference between a variable and the attributes of a control. You have Bill as some sort of selectable control, probably a radiobutton, so ask it which entry is set e.g. Select Case RadioButton.Selected...
2) You arrive in Calculate_Click and then declare the Bill variable. It is not assigned any value and then you try to do a case statement on an undefined value. You need to set Bill from somewhere. The declaration of Bill as a local Integer probably overrides the declaration of Bill as a CheckBox in your design for the duration of that method so remove it from the Dim statements.
3) H is defined as a Double and you assign it a String value
4) F is defined as an Integer and you assign it a String value
5) You have a Rug Cleaner in the Sprayer rental case.
6) The case statement already knows what Bill is, so get rid of the "If Bill = 2 Then" logic in the case statement elements
7) You should be able to generate the billing string incrementally as you only need one of them. e.g.
If Duration = Half Then ' This line will depend on your control used
BillString = "1/2 Day "
Else
BillString = "1 Day "
End If
then in the case statement add...
BillString &= "Paint Sprayer Deposit $30 + "
and another Duration if statement that adds the cost for the chosen duration.
8) Looking at this, you are generally not understanding the difference between a variable and the attributes of a control. You have Bill as some sort of selectable control, probably a radiobutton, so ask it which entry is set e.g. Select Case RadioButton.Selected...
#4
Re: Issues with case statement output
Posted 16 June 2009 - 02:36 PM
I don't know, I am totally lost here. I just thought I would create a similar program for my friends small business to save her some money, but it is not going to be as easy as I thought. I only have minimal experience with VB.NEt and guess she will just have to pay someone who knows what they are doing. Thanks.
mark.bottomley, on 16 Jun, 2009 - 12:37 PM, said:
1) Please use MEANINGFUL variable names - e.g. H should be HalfDayCost or something equivalent.
2) You arrive in Calculate_Click and then declare the Bill variable. It is not assigned any value and then you try to do a case statement on an undefined value. You need to set Bill from somewhere. The declaration of Bill as a local Integer probably overrides the declaration of Bill as a CheckBox in your design for the duration of that method so remove it from the Dim statements.
3) H is defined as a Double and you assign it a String value
4) F is defined as an Integer and you assign it a String value
5) You have a Rug Cleaner in the Sprayer rental case.
6) The case statement already knows what Bill is, so get rid of the "If Bill = 2 Then" logic in the case statement elements
7) You should be able to generate the billing string incrementally as you only need one of them. e.g.
If Duration = Half Then ' This line will depend on your control used
BillString = "1/2 Day "
Else
BillString = "1 Day "
End If
then in the case statement add...
BillString &= "Paint Sprayer Deposit $30 + "
and another Duration if statement that adds the cost for the chosen duration.
8) Looking at this, you are generally not understanding the difference between a variable and the attributes of a control. You have Bill as some sort of selectable control, probably a radiobutton, so ask it which entry is set e.g. Select Case RadioButton.Selected...
2) You arrive in Calculate_Click and then declare the Bill variable. It is not assigned any value and then you try to do a case statement on an undefined value. You need to set Bill from somewhere. The declaration of Bill as a local Integer probably overrides the declaration of Bill as a CheckBox in your design for the duration of that method so remove it from the Dim statements.
3) H is defined as a Double and you assign it a String value
4) F is defined as an Integer and you assign it a String value
5) You have a Rug Cleaner in the Sprayer rental case.
6) The case statement already knows what Bill is, so get rid of the "If Bill = 2 Then" logic in the case statement elements
7) You should be able to generate the billing string incrementally as you only need one of them. e.g.
If Duration = Half Then ' This line will depend on your control used
BillString = "1/2 Day "
Else
BillString = "1 Day "
End If
then in the case statement add...
BillString &= "Paint Sprayer Deposit $30 + "
and another Duration if statement that adds the cost for the chosen duration.
8) Looking at this, you are generally not understanding the difference between a variable and the attributes of a control. You have Bill as some sort of selectable control, probably a radiobutton, so ask it which entry is set e.g. Select Case RadioButton.Selected...
#5
Re: Issues with case statement output
Posted 31 August 2009 - 08:48 AM
mistymoon1966, on 16 Jun, 2009 - 11:14 AM, said:
I am working on another project to sharpen my visual basic.net skills. I wanted to make a simple equipment rental program. The program has a button to diplay the rental items and rates in the first list box and a button to display the bill in the second list box based on the user input of the item the user wants to rent in the first text box and F or H for full day or half day rental in the second text box. The program runs and the rental information displays when the user clicks the display rental rates button; however the bill list box does not display the bill for the input the user has entered into the item and duration text boxes. Could someone please tell me how to fix this issue as I am doing a trial program here so that I can create a program for a friend's small business and am a new BSIT/SE graduate and have never had to create a program like this before, thanks.
Public Class Rental
Private Sub Rental_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
'Enables user to exit program
Me.Close()
End Sub
Private Sub Rates_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rates.Click
'Code dislplays rental information in the information list box
Dim fmtStr As String = "{0, -10}{1, 15}{1, 15}"
Info.Items.Clear()
Info.Items.Add(String.Format(fmtStr, "Price of Equipment", "Half-Day", "Full-Day"))
Info.Items.Add(String.Format(fmtStr, "1. Rug Cleaner", "$16.00", "$24.00"))
Info.Items.Add(String.Format(fmtStr, "2. Lawn Mower", "$12.00", "$18.00"))
Info.Items.Add(String.Format(fmtStr, "3. Paint Sprayer", "$20.00", "$30.00"))
End Sub
Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
'Clears input and bill information text boxes
Item.Clear()
Duration.Clear()
Bill.ClearSelected()
End Sub
Private Sub Bill_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bill.SelectedIndexChanged
End Sub
Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calculate.Click
'varialbes
Dim Bill As Integer
Dim H As Double
Dim F As Integer
Select Case Bill
Case 1
If Bill = 1 & H = "1/2 Day Rug Cleaner, $30 (deposit) + $16 (rental fee) = $46" Then
ElseIf Bill = 1 & F = "1 Day Rug Cleaner, $30 (deposit) + $24 (rental fee) = $54" Then
End If
Case 2
If Bill = 2 & H = "1/2 Day Lawn Mower Rental, $30 (deposit) + $12 (rental fee) = $42" Then
ElseIf Bill = 2 & F = "1 Day Lawn Mower Rental, $30 (deposit) + $18 (rental fee) = $48" Then
End If
Case 3
If Bill = 3 & H = "1/2 Day Paint Sprayer Rental, $30 (deposit) + $20 (rental fee) = $50" Then
ElseIf Bill = 3 & F = "1 Day Lawn Mower Rental, $30 (deposit) + $30 (rental fee) = $60" Then
End If
End Select
Calculate.Text = "Receipt from Hill's Rental Equipment"
End Sub
End Class
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|