Discussion Locked

Visual basic beginner

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am a brginner in Visual Basic and my question is, I have a project that I must do for class except my teacher well lets say she is not helping much. I need suggestions for developing a program that is for a bookstore and the requirements are a student picks the books he or she wants and puts them in a shopping cart? the shopping cart i have no idea where to start. once the student is finished I need to calculate their purchase I can do ths part. Its the shopping cart thing I don't get. Is there anyonr who could lead me in the right direction?

Sincerely Jamie

9 replies

by bill

Jamie, the 'shopping cart' your teacher is talking about, is nothing more than something to 'hold' the purchases, much like you would use an actual shopping cart to hold your groceries while shopping.

The simplest way to create the shoping cart is to set up a temp file, and let the user add items to the file, and when they do, you record say, the item number, the quantity they want, the price, the description and so on. Then, when they get to the 'check-out' you simply process this file to calculate the bill.

Also, at checkout, you could provide a 'look' at the file and let the user opt to delete some items before actually completing their shopping.

I hope this clears it up a bit for you, if not, drop me a note and we can talk further

-Bill

by original eggman

LOT of ways to do this
SIMPLE way.
Assuming you can create, open, write, append & delete records from a file.
(Indexed Random Access files are easier to work with once set up, flat text files are easier for beginner)
Since number of items in each "Cart" is small, this will work.

ASSUMING front end is written & you're at Add to Cart Stage

Can't get into CODE-I'll give you steps.

You'll need to set up a text file containing nothing but a number-any number-say 100
This will be the cart numbers, call it cartnumber.txt

When someone "Adds (First Item) to Cart"

Open cartnumber.txt

Fetch number from there & assign to variable. We'll use cartNo

Increment by one

Write NEW number BACK TO cartnumber.txt
(Don't Append, ONLY KEEP ONE RECORD in file, the NEXT cart)

Unlock & close cartnumber.txt

With 100 now in cartNo

Open new file (APPEND) - call it cart100.txt - This will hold books for THIS transaction.
(100 comes from cartNo & also be Order Number.)
Data for First Item will be line 1 in the file.

Next will be line 2, etc.
(Random files let you access by UPC/ISBN code, or anything else, - we'll keep it simple)

Click "View Cart"

Open cart100.txt

* Step through file, one line (record) at a time, suck out data & display the 4 items on screen.
* Stash all records into an array in memory - items[]

After adding four items, I decide I don't want second one.
Click "Remove From Cart"

* Empty Array Item Items[2]
* Open cart100.txt toWRITE Erasing Contents
* Write only array items containing data (test for empty records & skip) to now empty cart100.txt

Display new cart contents & flush array.

YES ITS CUMBERSOME-ITEMS WITH AN * could be eliminated using indexed files.

When done, you'll have a text file, cart100.txt to build the total & invoice.

AFTER CHECKOUT, delete cart100.

NOT most elegant/efficient but simple.

Good Luck

Egg

by original eggman

LOT of ways to do this
SIMPLE way.
Assuming you can create, open, write, append & delete records from a file.
(Indexed Random Access files are easier to work with once set up, flat text files are easier for beginner)
Since number of items in each "Cart" is small, this will work.

ASSUMING front end is written & you're at Add to Cart Stage

Can't get into CODE-I'll give you steps.

You'll need to set up a text file containing nothing but a number-any number-say 100
This will be the cart numbers, call it cartnumber.txt

When someone "Adds (First Item) to Cart"

Open cartnumber.txt

Fetch number from there & assign to variable. We'll use cartNo

Increment by one

Write NEW number BACK TO cartnumber.txt
(Don't Append, ONLY KEEP ONE RECORD in file, the NEXT cart)

Unlock & close cartnumber.txt

With 100 now in cartNo

Open new file (APPEND) - call it cart100.txt - This will hold books for THIS transaction.
(100 comes from cartNo & also be Order Number.)
Data for First Item will be line 1 in the file.

Next will be line 2, etc.
(Random files let you access by UPC/ISBN code, or anything else, - we'll keep it simple)

Click "View Cart"

Open cart100.txt

* Step through file, one line (record) at a time, suck out data & display the 4 items on screen.
* Stash all records into an array in memory - items[]

After adding four items, I decide I don't want second one.
Click "Remove From Cart"

* Empty Array Item Items[2]
* Open cart100.txt toWRITE Erasing Contents
* Write only array items containing data (test for empty records & skip) to now empty cart100.txt

Display new cart contents & flush array.

YES ITS CUMBERSOME-ITEMS WITH AN * could be eliminated using indexed files.

When done, you'll have a text file, cart100.txt to build the total & invoice.

AFTER CHECKOUT, delete cart100.

NOT most elegant/efficient but simple.

Good Luck

Egg

by shanghai sam

Well, since you are working with VISUAL BASIC, and assuming you are not developing an Internet application, there are two alternatives you might be doing this:

-Database
-Random Access Files

I would recommend DATABASES, since it will make your life much easier. If you choose to do so, include a Grid control in the form, and let it display the products. Use another grid connected to a temporary table, which will hold the items until the user decides to check out. Let them add items to this grid by highlighting something in the other grid, and clicking an ADD button.Have a table for transactions. This one will hold all transactions. You can refer to the items specific to an invoice by including a field INVOICE_NUMBER. Have another table for recording the invoice number, date, amount, etc.

If you decide to use files, you might as well just have a list box, and let them add items to this control. Just make sure you can specifically refer to the product with whatever is entered into the list. (parsing content)

E.G:

Item in list:
--------------------
20345 - Italian Food
--------------------

code to retrieve item code:

item=mid(list1.list(0),1,1)
'will append caracters to item
'until it finds a space
while item<>=" "
item=item & mid(list1.list(0),1,1)
wend
'item now contains: 20345

and just process the total.

This discussion is closed to new replies.