Page 1 of 1

Help with Invoice Program

Posted: Sun May 07, 2006 4:54 pm
by flirt85
I'm also trying to create a program that outputs data into an invoice format. Any suggestions?


CLS
DIM item AS STRING 'item sold
DIM specs AS STRING 'specifications of item
DIM price AS SINGLE 'price of item
DIM subtotal AS SINGLE 'subtotal of items purchased
DIM tax AS SINGLE 'sales tax of items purchsed
DIM total AS SINGLE 'total price including tax
DIM h1 AS STRING 'heading 1
DIM h2 AS STRING 'heading 2
DIM x AS INTEGER 'loop variable
DIM datastring AS STRING 'data print string
DIM ct AS SINGLE 'counter

DATA "Computer","102GHz",835.89
DATA "Monitor"."17 inch",189.98
DATA "Printer","Color",256.23
DATA "Scanner","Flatbed",145.95
DATA "Speakers"."Stereo".32.27
DATA "Software","Office",387.77
DATA "xxx","xxx",-1

h1 = "Item Specs Cost"
h2 = "----- ----- ----"

PRINT h1 'print headings
PRINT h2

total = 0 'set total to 0
tax = 0 'set tax to 0
subtotal = 0 'set accumulator to 0
ct = 0 'set counter to 0
datastring = "\ \ \" 'set format string


READ item, specs, price
WHILE ct <= 5
subtotal = subtotal + price
ct = ct + 1

WEND
tax = 12.5 * subtotal
total = subtotal + tax

PRINT USING datastring; item; specs; price
LOCATE 8, 30
PRINT subtotal
LOCATE 9, 30
PRINT tax
LOCATE 10, 30
PRINT total

Posted: Sun May 07, 2006 8:04 pm
by moneo
Hi Flirt85,
You seem to be a pretty good programmer, judging from your code. Having looked at your inventory program also, I notice some things that I consider bad habits.
1) You seem to prefer processing input data directly out of DATA statements. I prefer to set up one or more arrays, and READ the DATA into the arrays, and then process the arrays. It''s a lot cleaner for me. However, in this particular simple program, your approach is acceptable since you are only making one pass over the data.

2) Your count CT goes from 0 to 5, which is confusing. You have 6 sets of data so you should really count from 1 to 6. Again, this is my preference.

3) You have "padding" data of "xxx" as the last DATA statement, which you don't need for this program.

3) The printing of your subtotal, tax, and total should line up, and be rounded to 2 decimal places, as follows.
MASK$="#,###.##"
PRINT USING MASK$;SUBTOTAL
PRINT USING MASK$;TAX
PRINT USING MASK$;TOTAL

Otherwise, your program looks good and should run.
*****

Invoice Program

Posted: Sun May 07, 2006 8:28 pm
by flirt85
Thank you Moneo. This program is becoming quite a pain. It runs as is, but only displays the first set of data....six times. I can see the PRINT MASK as an improvement, but my WHILE statement really needs help. Do you have any more suggestions?

Posted: Sun May 07, 2006 8:34 pm
by Theophage
well, it looks like you either need arrays for your item, specs, and price variables, or you need to put your print statements inside your WHILE / WEND loop...

Re: Invoice Program

Posted: Mon May 08, 2006 1:59 pm
by moneo
flirt85 wrote:Thank you Moneo. This program is becoming quite a pain. It runs as is, but only displays the first set of data....six times. I can see the PRINT MASK as an improvement, but my WHILE statement really needs help. Do you have any more suggestions?
It's not clear what level of subtotals and total you want. Let's assume that subtotal is the sum of all 6 prices, and tax is total tax for all 6 items, and total is the grand total.

If this were truly an invoice, you would want to show the price, tax, and extension for each item, with totals at the end, which of course must crossfoot. We'll do that next time.

The READ item,specs,price is outside of the WHILE loop, so you'll always be working with the same item, the first. You need to relocate the WEND so it covers that calculations for all 6 items, prints each of the 6 items, and then at the end, prints out only the subtotal, tax, and total. Here's you're original code:

Code: Select all

READ item, specs, price
WHILE ct <= 5
subtotal = subtotal + price
ct = ct + 1
WEND
tax = 12.5 * subtotal
total = subtotal + tax

PRINT USING datastring; item; specs; price
LOCATE 8, 30
PRINT subtotal
LOCATE 9, 30
PRINT tax
LOCATE 10, 30
PRINT total
Here's my suggested code:

Code: Select all

WHILE ct <= 5
READ item, specs, price
subtotal = subtotal + price
ct = ct + 1
PRINT USING datastring; item; specs; price
WEND

tax = 12.5 * subtotal
total = subtotal + tax

LOCATE 8, 30
PRINT subtotal
LOCATE 9, 30
PRINT tax
LOCATE 10, 30
PRINT total
*****

syntax error on READ and Type Mismatch on Print Using

Posted: Sun May 14, 2006 1:45 pm
by flirt85
I made the modifications to the code that you suggested, but on the READ statement inside of the loop, I recieve a Syntax error. Also, I have rarely been able to actually use the PRINT USING datastring because of the type mismatch error.....??

Posted: Sun May 14, 2006 8:36 pm
by moneo
Hi Flirt85, I thought you had disappeared.

Regarding the READ error, take a look at this DATA statement which has a period instead of a comma between the first 2 fields, which is probably the cause.

DATA "Monitor"."17 inch",189.98

As far as the PRINT USING is concerned, I never use it like you do for formatting data fields, just for formatting values with dollar signs, commas, decimal points.
I think you're getting a type mismatch error because you're mixing string and numeric data.

Instead if using the PRINT USING, why don't you use your own formatting technique by putting, let's say, 2 spaces between the fields. Try it. It might not be as pretty, but it will certainly work without giving an error.
*****

Posted: Mon May 15, 2006 3:11 pm
by flirt85
Good afternoon Moneo,
Between work and school, it takes me awhile to get online =) I'm still getting a READ error after I fixed the period into a comma in my data. I found another period and fixed it as well. I don't get it?

Posted: Tue May 16, 2006 2:16 pm
by moneo
flirt85 wrote:......
I'm still getting a READ error after I fixed the period into a comma in my data. I found another period and fixed it as well. I don't get it?
If you have more than one constant (string or numeric) on a DATA statement, then you must delimit (separate) each of these with a COMMA. I just noticed that the DATA statement for "Speakers" has 2 periods instead of commas. There's nothing special to understand. That's just the rule for DATA statements.
*****

Posted: Fri May 19, 2006 2:44 pm
by moneo
Flirt85,

A good way to be able to see the information and the delimeters in a DATA statement more clearly is to line up and spread out the fields. Example:

Code: Select all

DATA "Computer" , "102GHz"   ,  835.89
DATA "Monitor"  , "17 inch"  ,  189.98
DATA "Printer"  , "Color"    ,  256.23
etc....
While doing this, I just noticed that "Monitor" was delimited with a period instead of a comma. When you spread it out, it becomes more visible.
*****