Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > help with my rental car program


Reply
 
Thread Tools Display Modes
  #1  
Old 02-05-2007, 12:19 PM
bhs00 bhs00 is offline
Newcomer
 
Join Date: Feb 2007
Posts: 5
Unhappy 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
Reply With Quote
  #2  
Old 02-05-2007, 12:46 PM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

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
Reply With Quote
  #3  
Old 02-05-2007, 12:46 PM
stuffradio stuffradio is offline
Centurion
 
Join Date: Jan 2006
Posts: 182
Default

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.
Reply With Quote
  #4  
Old 02-05-2007, 01:19 PM
bhs00 bhs00 is offline
Newcomer
 
Join Date: Feb 2007
Posts: 5
Default

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.
Reply With Quote
  #5  
Old 02-05-2007, 06:17 PM
torpkevuk's Avatar
torpkevuk torpkevuk is offline
Contributor
 
Join Date: Oct 2003
Location: Nebraska, USA
Posts: 640
Default

Quote:
Originally Posted by bhs00 View Post
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
Reply With Quote
  #6  
Old 02-05-2007, 06:52 PM
bhs00 bhs00 is offline
Newcomer
 
Join Date: Feb 2007
Posts: 5
Default

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.
Reply With Quote
  #7  
Old 02-05-2007, 07:20 PM
Geofferz Geofferz is offline
Junior Contributor
 
Join Date: May 2003
Posts: 328
Default

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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->