help with my rental car program

bhs00
02-05-2007, 01: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

wayneph
02-05-2007, 01:46 PM
It would be easier if you told us what problems you're having, so that we know what we're looking for.

stuffradio
02-05-2007, 01:46 PM
That's not a very secure way to do the program. My suggestion to you is have a database that can be looked at with reading privileges on the client side. Than load a database where the user can look at it.

bhs00
02-05-2007, 02:19 PM
well i dont have enough cars that would require a database at the moment, so I want to just use a textfile for right now. I need to be able to click a car from the list and then it be synched with the price so I can figure out the costs to display to the user.

torpkevuk
02-05-2007, 07:17 PM
well i dont have enough cars that would require a database at the moment, so I want to just use a textfile for right now. I need to be able to click a car from the list and then it be synched with the price so I can figure out the costs to display to the user.

yes.. but what problem are you actually having?
ie. what doesn't work

bhs00
02-05-2007, 07:52 PM
on the button click event, I am getting an error that tmpCar is not declared. and under the form1 load event I am getting a warning that tmpCar is being used without being assigned a value.

Geofferz
02-05-2007, 08:20 PM
tmpCar is not declared for use in the click event thats correct its only given scope in formload.
Also you have an if then else in form load
that is basically

If (result) then
mycar = new car
mycar.dosomething
else
mycar.dosomething
end if

Looking at that if the result is false then mycar will be un-initailzed
HTH G

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum