bhs00
02-05-2007, 12:19 PM
I am writing a program to give users an interface that shows how much each car costs to rent. I have a file named cars.txt saved to my c drive on my computer. When the program begins the file should be read and the available cars should be shown in a list box. After the user enters start and ending dates and selects a car, the program should display the total rental price. Rentals of seven days or more are given a 20% discount. The optional insurance is $10 per day, and discounts do not apply to the insurance, which is always $10 per day. And also I am using a control I already have called DateRange, in which to datetimepickers are used to select the staring and end dates for the rental. Im almost through but im having a few problems. Is there anyone that could look over my code and tell me what im doing wrong and maybe how to fix it? Thanks
Here's my code:
Public Class Form1
Private Structure Car
Dim model As String
Dim price As Double
End Structure
Private Cars As New Collection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As New IO.StreamReader("c:\cars.txt")
Dim tmpCar As Car
Dim strLine As String
Do Until sr.EndOfStream
strLine = sr.ReadLine
If Not strLine = "" AndAlso Double.TryParse(strLine, 0) = False Then
tmpCar = New Car
lstCars.Items.Add(strLine)
tmpCar.model = strLine
ElseIf Double.TryParse(strLine, 0) = True Then
tmpCar.price = Double.Parse(strLine)
Cars.Add(tmpCar)
End If
Loop
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim duration
Dim amount
duration = DateRange1.Duration
If duration > 6 Then
tmpcar.price = tmpcar.price * 0.8
End If
If chkInsurance.Checked Then
tmpcar.price = tmpcar.price + 10
End If
lblPrice.Text = tmpcar.price
End Sub
End Class
Here's my code:
Public Class Form1
Private Structure Car
Dim model As String
Dim price As Double
End Structure
Private Cars As New Collection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As New IO.StreamReader("c:\cars.txt")
Dim tmpCar As Car
Dim strLine As String
Do Until sr.EndOfStream
strLine = sr.ReadLine
If Not strLine = "" AndAlso Double.TryParse(strLine, 0) = False Then
tmpCar = New Car
lstCars.Items.Add(strLine)
tmpCar.model = strLine
ElseIf Double.TryParse(strLine, 0) = True Then
tmpCar.price = Double.Parse(strLine)
Cars.Add(tmpCar)
End If
Loop
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim duration
Dim amount
duration = DateRange1.Duration
If duration > 6 Then
tmpcar.price = tmpcar.price * 0.8
End If
If chkInsurance.Checked Then
tmpcar.price = tmpcar.price + 10
End If
lblPrice.Text = tmpcar.price
End Sub
End Class