Hi guys Im quite new using Visual Studio 2008 and I have to do an assigment for university. So I have done my calculations but the problem is that each time I press calculate it gives me a result of 0.
This is the code i have up to now:
Public Class frmCorsas1
Private Sub cmdStock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStock.Click
If txtNumberCars.Text = " " Then
MessageBox.Show("Please enter number of cars you want to hire")
ElseIf Val(txtNumberCars.Text) - (10) Then
MessageBox.Show(10 - txtNumberCars.Text & " " & "Cars left", "Stock Message")
End If
End Sub
Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCalculate.Click
If Val(txtDays.Text) < 1 Then
txtTotal.Text = ((Val(txtDays.Text) * 25) - (((25 * 2.5) / 100) * Val(txtDays.Text)) * Val(txtNumberCars.Text))
Else
txtTotal.Text = Val(txtDays.Text) * 25
End If
If Val(txtWeeks.Text) < 1 Then
txtTotal.Text = ((Val(txtWeeks.Text) * 100) - (((100 * 3.75) / 100) * Val(txtWeeks.Text)) * Val(txtNumberCars.Text))
Else
txtTotal.Text = Val(txtWeeks.Text) * 100
End If
If Val(txtMonths.Text) < 1 Then
txtTotal.Text = ((Val(txtMonths.Text) * 100) - (((100 * 3.75) / 100) * Val(txtMonths.Text)) * Val(txtNumberCars.Text))
ElseIf Val(txtMonths.Text) = 1 Then
txtTotal.Text = Val(txtMonths.Text) * 100
End If
End Sub
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
Me.Close()
End Sub
Private Sub txtNumberCars_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNumberCars.TextChanged
If Val(txtNumberCars.Text) > 10 Then
MessageBox.Show("There is only 10 cars in stock.", "Stock Information")
End If
End Sub
Private Sub txtDays_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDays.TextChanged
If Val(txtDays.Text) > 6 Then
MessageBox.Show("If you want the car for more than 6 days enter the weeks", "Days")
txtDays.Text = " "
End If
End Sub
End Class
This is what I have to do:
4Hire is a new car hire company. It has just purchased 10 Vauxhall Corsas, 10 Vauxhall Astras and 5 Vauxhall Vectras, which they want to hire out on a daily, weekly or monthly basis.
The charge will vary according to the type of car and length of hire period.
• Corsas will cost £25 per day, £100 per week and £300 per month
If a customer wishes to hire a car for more than just one day, one week or one month, they will be given a discount of 2.5% on day hire, 3.75% on week hire and 4.25% on monthly hire.
I'll be very thankful for your help..
Dionne
Help with calculations using text boxes.
Started by dionne, Feb 17 2010 09:15 AM
2 replies to this topic
#1
Posted 17 February 2010 - 09:15 AM
|
|
|
#2
Posted 17 February 2010 - 10:29 PM
Of course you will get always 0 when you press cmdCalculate each time look at your conditions, you have a logical error:
I think you mean, you want it this way (anyway this is the logic):
greater rather then smaller... any other thing you are lost about don't hesitate to ask!
good luck
If Val(txtDays.Text) < 1 Then If Val(txtWeeks.Text) < 1 Then If Val(txtMonths.Text) < 1 Then
I think you mean, you want it this way (anyway this is the logic):
If Val(txtDays.Text) > 1 Then If Val(txtWeeks.Text) > 1 Then If Val(txtMonths.Text) > 1 Then
greater rather then smaller... any other thing you are lost about don't hesitate to ask!
good luck
Share your Knowledge, It's one way to achieve immortality.
Video Tutorial Channel
Video Tutorial Channel
#3
Posted 18 February 2010 - 07:00 AM
Thank you so much for your help, but now i'm having another problem.
It shows the total but does not calculate the discount if someone enters more than 1 day, more 1 week or more than 1 months.
this is the code for my calculations now:
If Val(txtDays.Text) > 1 And Val(txtDays.Text) < 6 Then
txtTotal.Text = ((Val(txtDays.Text) * 25) - ((25 * 0.025) * Val(txtDays.Text)) * txtNumberCars.Text)
ElseIf Val(txtDays.Text) = 1 Then
txtTotal.Text = Val(txtDays.Text) * 25
End If
If Val(txtWeeks.Text) > 1 Then
txtTotal.Text = ((Val(txtWeeks.Text) * 100) - (((100 * 3.75) / 100) * Val(txtWeeks.Text))) * Val(txtNumberCars.Text)
ElseIf Val(txtWeeks.Text) = 1 Then
txtTotal.Text = Val(txtWeeks.Text) * 100
End If
If Val(txtMonths.Text) > 1 Then
txtTotal.Text = ((Val(txtMonths.Text) * 300) - ((300 * 0.0425) * Val(txtMonths.Text)) * txtNumberCars.Text)
ElseIf Val(txtMonths.Text) = 1 Then
txtTotal.Text = Val(txtMonths.Text) * 300
End If
If txtDays.Text <> " " And txtMonths.Text <> " " And txtWeeks.Text <> " " Then
txtTotal.Text = (Val(txtDays.Text) * 25) + (((Val(txtWeeks.Text) * 100) + ((Val(txtMonths.Text) * 300) - (300 * 0.0375) * Val(txtMonths.Text))) * txtNumberCars.Text)
End If
Thank you so much for your help.
It shows the total but does not calculate the discount if someone enters more than 1 day, more 1 week or more than 1 months.
this is the code for my calculations now:
If Val(txtDays.Text) > 1 And Val(txtDays.Text) < 6 Then
txtTotal.Text = ((Val(txtDays.Text) * 25) - ((25 * 0.025) * Val(txtDays.Text)) * txtNumberCars.Text)
ElseIf Val(txtDays.Text) = 1 Then
txtTotal.Text = Val(txtDays.Text) * 25
End If
If Val(txtWeeks.Text) > 1 Then
txtTotal.Text = ((Val(txtWeeks.Text) * 100) - (((100 * 3.75) / 100) * Val(txtWeeks.Text))) * Val(txtNumberCars.Text)
ElseIf Val(txtWeeks.Text) = 1 Then
txtTotal.Text = Val(txtWeeks.Text) * 100
End If
If Val(txtMonths.Text) > 1 Then
txtTotal.Text = ((Val(txtMonths.Text) * 300) - ((300 * 0.0425) * Val(txtMonths.Text)) * txtNumberCars.Text)
ElseIf Val(txtMonths.Text) = 1 Then
txtTotal.Text = Val(txtMonths.Text) * 300
End If
If txtDays.Text <> " " And txtMonths.Text <> " " And txtWeeks.Text <> " " Then
txtTotal.Text = (Val(txtDays.Text) * 25) + (((Val(txtWeeks.Text) * 100) + ((Val(txtMonths.Text) * 300) - (300 * 0.0375) * Val(txtMonths.Text))) * txtNumberCars.Text)
End If
Thank you so much for your help.


Sign In
Create Account

Back to top









