 |
 |

02-05-2007, 12:19 PM
|
|
Newcomer
|
|
Join Date: Feb 2007
Posts: 5
|
|
help with my rental car program
|
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:
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
|
|

02-05-2007, 12:46 PM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
|
It would be easier if you told us what problems you're having, so that we know what we're looking for.
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|

02-05-2007, 12:46 PM
|
|
Centurion
|
|
Join Date: Jan 2006
Posts: 182
|
|
|
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.
|
|

02-05-2007, 01:19 PM
|
|
Newcomer
|
|
Join Date: Feb 2007
Posts: 5
|
|
|
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.
|
|

02-05-2007, 06:17 PM
|
 |
Contributor
|
|
Join Date: Oct 2003
Location: Nebraska, USA
Posts: 640
|
|
Quote:
Originally Posted by bhs00
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
|
|

02-05-2007, 06:52 PM
|
|
Newcomer
|
|
Join Date: Feb 2007
Posts: 5
|
|
|
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.
|
|

02-05-2007, 07:20 PM
|
|
Junior Contributor
|
|
Join Date: May 2003
Posts: 328
|
|
|
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
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|