Database
Posted: Wed Sep 21, 2005 9:57 am
Okay, I am working at my dealership making an inventory program that is more functional than the proprietary version we have. the problem I am running across is writing the information to a database file. here is the code I have...
TYPE VehicleInfo
Make AS STRING * 10
Model AS STRING * 15
Year AS INTEGER
Body AS STRING * 30
Shade AS STRING * 20
Mileage AS LONG
Stock AS STRING * 8
Price AS INTEGER
Fuel AS STRING * 5
Tran AS STRING * 10
END TYPE
DIM Vehicle AS VehicleInfo
Item = 0
MainMenu:
CLS
title$ = "Inventory Editor"
numberofchoices = 5 'number of choices in your menu (1 to numofchoices)
DIM menuchoices(numberofchoices) AS STRING
'your menu choices as text:
menuchoices(1) = "Add a Vehicle"
menuchoices(2) = "Remove a Vehicle"
menuchoices(3) = "Search inventory"
menuchoices(4) = "View Vehicle Info"
menuchoices(5) = "Quit"
CALL menu(numberofchoices, title$, menuchoices$(), Choice)
ERASE menuchoices 'makes the array inexistant
' choice is the selection now you can use : select case or other code
SELECT CASE Choice
CASE 1
GOTO Addcar
CASE 2
GOTO Removecar
CASE 3
GOTO Search
CASE 4
GOTO ViewCar
CASE 5
GOTO Quit
CASE ELSE
GOTO MainMenu
END SELECT
Addcar:
recordLen# = LEN(Vehicle)
OPEN "Invent.Txt" FOR RANDOM AS #1 LEN = recordLen#
CLS
LOCATE 5, 8
INPUT "Vehicle Make - ", Vehicle.Make
LOCATE 6, 8
INPUT "Vehicle Model - ", Vehicle.Model
LOCATE 7, 8
INPUT "Vehicle Year - ", Vehicle.Year
LOCATE 8, 8
INPUT "Vehicle Color - ", Vehicle.Shade
LOCATE 9, 8
INPUT "Vehicle Body - ", Vehicle.Body
LOCATE 10, 8
INPUT "Vehicle Mileage - ", Vehicle.Mileage
LOCATE 11, 8
INPUT "Stock Number - ", Vehicle.Stock
LOCATE 12, 8
INPUT "Price - ", Vehicle.Price
LOCATE 13, 8
INPUT "Fuel Type - ", Vehicle.Fuel
LOCATE 14, 8
INPUT "Transmission - ", Vehicle.Tran
PUT #1, , Vehicle
CLOSE #1
CLS
LOCATE 10, 10
PRINT "Vehicle added to inventory"
As one can see I have made the user defined variable for keeping the record of the vehicles information. My problem is that the program keeps overwriting the 1st record everytime I add a vehicle instead of appendin it to the next position in the file. What do I need to do to fix this?
TYPE VehicleInfo
Make AS STRING * 10
Model AS STRING * 15
Year AS INTEGER
Body AS STRING * 30
Shade AS STRING * 20
Mileage AS LONG
Stock AS STRING * 8
Price AS INTEGER
Fuel AS STRING * 5
Tran AS STRING * 10
END TYPE
DIM Vehicle AS VehicleInfo
Item = 0
MainMenu:
CLS
title$ = "Inventory Editor"
numberofchoices = 5 'number of choices in your menu (1 to numofchoices)
DIM menuchoices(numberofchoices) AS STRING
'your menu choices as text:
menuchoices(1) = "Add a Vehicle"
menuchoices(2) = "Remove a Vehicle"
menuchoices(3) = "Search inventory"
menuchoices(4) = "View Vehicle Info"
menuchoices(5) = "Quit"
CALL menu(numberofchoices, title$, menuchoices$(), Choice)
ERASE menuchoices 'makes the array inexistant
' choice is the selection now you can use : select case or other code
SELECT CASE Choice
CASE 1
GOTO Addcar
CASE 2
GOTO Removecar
CASE 3
GOTO Search
CASE 4
GOTO ViewCar
CASE 5
GOTO Quit
CASE ELSE
GOTO MainMenu
END SELECT
Addcar:
recordLen# = LEN(Vehicle)
OPEN "Invent.Txt" FOR RANDOM AS #1 LEN = recordLen#
CLS
LOCATE 5, 8
INPUT "Vehicle Make - ", Vehicle.Make
LOCATE 6, 8
INPUT "Vehicle Model - ", Vehicle.Model
LOCATE 7, 8
INPUT "Vehicle Year - ", Vehicle.Year
LOCATE 8, 8
INPUT "Vehicle Color - ", Vehicle.Shade
LOCATE 9, 8
INPUT "Vehicle Body - ", Vehicle.Body
LOCATE 10, 8
INPUT "Vehicle Mileage - ", Vehicle.Mileage
LOCATE 11, 8
INPUT "Stock Number - ", Vehicle.Stock
LOCATE 12, 8
INPUT "Price - ", Vehicle.Price
LOCATE 13, 8
INPUT "Fuel Type - ", Vehicle.Fuel
LOCATE 14, 8
INPUT "Transmission - ", Vehicle.Tran
PUT #1, , Vehicle
CLOSE #1
CLS
LOCATE 10, 10
PRINT "Vehicle added to inventory"
As one can see I have made the user defined variable for keeping the record of the vehicles information. My problem is that the program keeps overwriting the 1st record everytime I add a vehicle instead of appendin it to the next position in the file. What do I need to do to fix this?