Inventory Program- help?
Inventory Program- help?
I'm trying to create a 'simple' program that allows the user to select a specific type of ladder out of data that has different types. In the first "case" or, if the user selects #1 from the menu, the output should read
"Extension Ladders
6 ft aluminum
10 ft aluminum
8 ft aluminum"
#2 output should read
Step Ladders
6 ft fiberglass
10 ft aluminum
6 ft aluminum
8 ft fiberglass
8 ft aluminum
#3 ouput should list the ladders by thier size,
6 FOOT
...
8 FOOT
....
10 FOOT
Currently When #1 or #2 is selected, the entire data list is outputed, and #3 is an endless stream of Fiberglass step.....Any help is appreciated!!!
COLOR 15, 1
CLS
DIM ladder AS STRING 'ladder name
DIM length AS INTEGER 'length of ladder
DIM choice AS INTEGER 'menu choice
DIM x AS INTEGER 'loop variable
DIM sp AS INTEGER 'space
DATA "Fiberglass Step",6
DATA "Aluminum Extension",6
DATA "Aluminum Step",10
DATA "Aluminum Extension",10
DATA "Aluminum Step",6
DATA "Fiberglass Step",8
DATA "Aluminum Extension",8
DATA "Aluminum Step",8
DATA "xxx",-1
CLS
PRINT " Ladders on Hand"
PRINT
PRINT " 1) Extension"
PRINT " 2) Step"
PRINT " 3) List by Size"
PRINT " 4) Exit"
PRINT
PRINT
INPUT " Select a Menu Item"; choice
SELECT CASE choice
CASE 1
CLS
PRINT "Extension Ladders"
READ ladder, length
WHILE ladder <> "xxx"
FOR x = 1 TO LEN(ladder) 'find and assign
IF MID$(ladder, x, 1) = " " THEN sp = x
NEXT x
IF ladder = MID$(ladder, sp + 1, 1) = E THEN
PRINT length; "ft "; LEFT$(ladder, sp - 1)
END IF
READ ladder, length
WEND
CASE 2
CLS
PRINT "Step Ladders"
READ ladder, length
WHILE ladder <> "xxx"
FOR x = 1 TO LEN(ladder) 'find and assign
IF MID$(ladder, x, 1) = " " THEN sp = x
NEXT x
IF ladder = MID$(ladder, sp + 1, 1) = S THEN
PRINT length; "ft "; LEFT$(ladder, sp - 1)
END IF
READ ladder, length
WEND
CASE 3
CLS
PRINT " 6 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 6 THEN
PRINT ladder
END IF
WEND
PRINT " 8 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 8 THEN
PRINT ladder
END IF
WEND
PRINT " 10 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 10 THEN
PRINT ladder
END IF
WEND
CASE 4
END
END SELECT
"Extension Ladders
6 ft aluminum
10 ft aluminum
8 ft aluminum"
#2 output should read
Step Ladders
6 ft fiberglass
10 ft aluminum
6 ft aluminum
8 ft fiberglass
8 ft aluminum
#3 ouput should list the ladders by thier size,
6 FOOT
...
8 FOOT
....
10 FOOT
Currently When #1 or #2 is selected, the entire data list is outputed, and #3 is an endless stream of Fiberglass step.....Any help is appreciated!!!
COLOR 15, 1
CLS
DIM ladder AS STRING 'ladder name
DIM length AS INTEGER 'length of ladder
DIM choice AS INTEGER 'menu choice
DIM x AS INTEGER 'loop variable
DIM sp AS INTEGER 'space
DATA "Fiberglass Step",6
DATA "Aluminum Extension",6
DATA "Aluminum Step",10
DATA "Aluminum Extension",10
DATA "Aluminum Step",6
DATA "Fiberglass Step",8
DATA "Aluminum Extension",8
DATA "Aluminum Step",8
DATA "xxx",-1
CLS
PRINT " Ladders on Hand"
PRINT " 1) Extension"
PRINT " 2) Step"
PRINT " 3) List by Size"
PRINT " 4) Exit"
INPUT " Select a Menu Item"; choice
SELECT CASE choice
CASE 1
CLS
PRINT "Extension Ladders"
READ ladder, length
WHILE ladder <> "xxx"
FOR x = 1 TO LEN(ladder) 'find and assign
IF MID$(ladder, x, 1) = " " THEN sp = x
NEXT x
IF ladder = MID$(ladder, sp + 1, 1) = E THEN
PRINT length; "ft "; LEFT$(ladder, sp - 1)
END IF
READ ladder, length
WEND
CASE 2
CLS
PRINT "Step Ladders"
READ ladder, length
WHILE ladder <> "xxx"
FOR x = 1 TO LEN(ladder) 'find and assign
IF MID$(ladder, x, 1) = " " THEN sp = x
NEXT x
IF ladder = MID$(ladder, sp + 1, 1) = S THEN
PRINT length; "ft "; LEFT$(ladder, sp - 1)
END IF
READ ladder, length
WEND
CASE 3
CLS
PRINT " 6 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 6 THEN
PRINT ladder
END IF
WEND
PRINT " 8 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 8 THEN
PRINT ladder
END IF
WEND
PRINT " 10 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 10 THEN
PRINT ladder
END IF
WEND
CASE 4
END
END SELECT
Flirt85,
The following code to determine if an extension ladder, won't work.
Instead, try the following:
The same applies to your step ladder logic.
For CASE 3: Just before the WEND for the 6, 8 and 10 foot ladder routines, you're missing the "read ladder,length" statement.
In general, you could simplify your program if you set up 3 data fileds per item, such as:
DATA "Aluiminum" , "Step" , 6
etc.
I don't have DOS available right now to test it, but you try it and let me know.
*****
The following code to determine if an extension ladder, won't work.
Code: Select all
FOR x = 1 TO LEN(ladder) 'find and assign
IF MID$(ladder, x, 1) = " " THEN sp = x
NEXT x
IF ladder = MID$(ladder, sp + 1, 1) = E THEN '*** THIS IS NO GOOD ***
PRINT length; "ft "; LEFT$(ladder, sp - 1)
END IF
Code: Select all
begin = INSTR(ladder,"Extension")
IF begin > 0 then
PRINT length; "ft "; LEFT$(ladder, begin-2)
END IF
For CASE 3: Just before the WEND for the 6, 8 and 10 foot ladder routines, you're missing the "read ladder,length" statement.
In general, you could simplify your program if you set up 3 data fileds per item, such as:
DATA "Aluiminum" , "Step" , 6
etc.
I don't have DOS available right now to test it, but you try it and let me know.
*****
data not printed in output
Good Morning Moneo,
Thank you for your help. I swapped my FOR NEXT code for your BEGIN code, and in case one, the ouput is correct.
However, I did the same swap with the CASE 2 code, and replaced "Extension" with "Step", and I get no output.
Also, with your help, Case 3 is no longer an endless loop. I think I may have another error in my code though, because nothing is printed after "8 Foot", and on.
Please help!
Thank you for your help. I swapped my FOR NEXT code for your BEGIN code, and in case one, the ouput is correct.
However, I did the same swap with the CASE 2 code, and replaced "Extension" with "Step", and I get no output.
Also, with your help, Case 3 is no longer an endless loop. I think I may have another error in my code though, because nothing is printed after "8 Foot", and on.
Please help!
Modified Code
Sorry Moneo, Here it is again:
COLOR 15, 1
CLS
DIM ladder AS STRING 'ladder name
DIM length AS INTEGER 'length of ladder
DIM choice AS INTEGER 'menu choice
DIM x AS INTEGER 'loop variable
DIM sp AS INTEGER 'space
DATA "Fiberglass Step",6
DATA "Aluminum Extension",6
DATA "Aluminum Step",10
DATA "Aluminum Extension",10
DATA "Aluminum Step",6
DATA "Fiberglass Step",8
DATA "Aluminum Extension",8
DATA "Aluminum Step",8
DATA "xxx",-1
CLS
PRINT " Ladders on Hand"
PRINT
PRINT " 1) Extension"
PRINT " 2) Step"
PRINT " 3) List by Size"
PRINT " 4) Exit"
PRINT
PRINT
INPUT " Select a Menu Item"; choice
SELECT CASE choice
CASE 1
CLS
PRINT "Extension Ladders"
READ ladder, length
WHILE ladder <> "xxx"
begin = INSTR(ladder, "Extension")
IF begin > 0 THEN
PRINT length; "ft "; LEFT$(ladder, begin - 2)
END IF
READ ladder, length
WEND
CASE 2
CLS
PRINT "Step Ladders"
READ ladder, length
WHILE ladder <> "xxx"
bring = INSTR(ladder, "Step")
IF begin > 0 THEN
PRINT length; "ft "; LEFT$(ladder, begin - 2)
END IF
READ ladder, length
WEND
CASE 3
CLS
PRINT " 6 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 6 THEN
PRINT ladder
END IF
READ ladder, length
WEND
PRINT " 8 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 8 THEN
PRINT ladder
END IF
WEND
PRINT " 10 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 10 THEN
PRINT ladder
END IF
READ ladder, length
WEND
CASE 4
END
END SELECT
Thank you for all of your help!! I really appreciate it!
COLOR 15, 1
CLS
DIM ladder AS STRING 'ladder name
DIM length AS INTEGER 'length of ladder
DIM choice AS INTEGER 'menu choice
DIM x AS INTEGER 'loop variable
DIM sp AS INTEGER 'space
DATA "Fiberglass Step",6
DATA "Aluminum Extension",6
DATA "Aluminum Step",10
DATA "Aluminum Extension",10
DATA "Aluminum Step",6
DATA "Fiberglass Step",8
DATA "Aluminum Extension",8
DATA "Aluminum Step",8
DATA "xxx",-1
CLS
PRINT " Ladders on Hand"
PRINT " 1) Extension"
PRINT " 2) Step"
PRINT " 3) List by Size"
PRINT " 4) Exit"
INPUT " Select a Menu Item"; choice
SELECT CASE choice
CASE 1
CLS
PRINT "Extension Ladders"
READ ladder, length
WHILE ladder <> "xxx"
begin = INSTR(ladder, "Extension")
IF begin > 0 THEN
PRINT length; "ft "; LEFT$(ladder, begin - 2)
END IF
READ ladder, length
WEND
CASE 2
CLS
PRINT "Step Ladders"
READ ladder, length
WHILE ladder <> "xxx"
bring = INSTR(ladder, "Step")
IF begin > 0 THEN
PRINT length; "ft "; LEFT$(ladder, begin - 2)
END IF
READ ladder, length
WEND
CASE 3
CLS
PRINT " 6 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 6 THEN
PRINT ladder
END IF
READ ladder, length
WEND
PRINT " 8 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 8 THEN
PRINT ladder
END IF
WEND
PRINT " 10 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 10 THEN
PRINT ladder
END IF
READ ladder, length
WEND
CASE 4
END
END SELECT
Thank you for all of your help!! I really appreciate it!
- {Nathan}
- Veteran
- Posts: 1169
- Joined: Thu Aug 19, 2004 6:08 pm
- Location: The wetlands of central Ohio, USA
- Contact:
Flirt85, you will notice below your subject line when you post a message a "code" button. If you push it, copy your code, and push it again, it will format your code to be much more readable. I have taken the liberty of doing this for you.
Code: Select all
COLOR 15, 1
CLS
DIM ladder AS STRING 'ladder name
DIM length AS INTEGER 'length of ladder
DIM choice AS INTEGER 'menu choice
DIM x AS INTEGER 'loop variable
DIM sp AS INTEGER 'space
DATA "Fiberglass Step",6
DATA "Aluminum Extension",6
DATA "Aluminum Step",10
DATA "Aluminum Extension",10
DATA "Aluminum Step",6
DATA "Fiberglass Step",8
DATA "Aluminum Extension",8
DATA "Aluminum Step",8
DATA "xxx",-1
CLS
PRINT " Ladders on Hand"
PRINT
PRINT " 1) Extension"
PRINT " 2) Step"
PRINT " 3) List by Size"
PRINT " 4) Exit"
PRINT
PRINT
INPUT " Select a Menu Item"; choice
SELECT CASE choice
CASE 1
CLS
PRINT "Extension Ladders"
READ ladder, length
WHILE ladder <> "xxx"
begin = INSTR(ladder, "Extension")
IF begin > 0 THEN
PRINT length; "ft "; LEFT$(ladder, begin - 2)
END IF
READ ladder, length
WEND
CASE 2
CLS
PRINT "Step Ladders"
READ ladder, length
WHILE ladder <> "xxx"
bring = INSTR(ladder, "Step")
IF begin > 0 THEN
PRINT length; "ft "; LEFT$(ladder, begin - 2)
END IF
READ ladder, length
WEND
CASE 3
CLS
PRINT " 6 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 6 THEN
PRINT ladder
END IF
READ ladder, length
WEND
PRINT " 8 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 8 THEN
PRINT ladder
END IF
WEND
PRINT " 10 FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = 10 THEN
PRINT ladder
END IF
READ ladder, length
WEND
CASE 4
END
END SELECT
Flirt85,Nathan1993 wrote:Flirt85, you will notice below your subject line when you post a message a "code" button. If you push it, copy your code, and push it again, it will format your code to be much more readable. I have taken the liberty of doing this for you.
Nathan1993 was trying to help out. Unfortunately your code is not indented, so using the "code" button is not going to help.
In my opinion, you should get in the habit of indenting your code to make it more readable. An example:
CASE 1
CLS
PRINT "Extension Ladders"
READ ladder, length
WHILE ladder <> "xxx"
begin = INSTR(ladder, "Extension")
IF begin > 0 THEN
PRINT length; "ft "; LEFT$(ladder, begin - 2)
END IF
READ ladder, length
WEND
*****************************************
The above would be more readable as:
Code: Select all
CASE 1
CLS
PRINT "Extension Ladders"
READ ladder, length
WHILE ladder <> "xxx"
begin = INSTR(ladder, "Extension")
IF begin > 0 THEN
PRINT length; "ft "; LEFT$(ladder, begin - 2)
END IF
READ ladder, length
WEND
Try it next time.
*****
Flirt85,
The problem with CASE 2 is that you used a variable named BRING instead of BEGIN.
bring = INSTR(ladder, "Step")
In CASE 3, at the end of you FOOT 8 logic you're missing the READ statement, as so:
END IF
READ ladder, length '***** Missing for FOOT 8.
WEND
The code for FOOT 6, 8 and 10 are so similar that I would have made a subroutine (maybe you prefer a SUB) to avoid redundant code, and also to avoid having one part work and the other not. Example:
CASE 3
CLS
WHICHFT=6
GOSUB FOOTLOGIC
WHICHFT=8
GOSUB FOOTLOGIC
WHICHFT=10
GOSUB FOOTLOGIC
CASE 4
etc....
FOOTLOGIC:
PRINT WHICHFT;" FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = WHICHFT THEN
PRINT ladder
END IF
READ ladder, length
WEND
RETURN '>>>>>>>>>>>>>>
My sample code is intended to be simple. You can make it fancier by:
CASE 3
CLS
FOR WHICHFT=6 TO 10 STEP 2
GOSUB FOOTLOGIC
NEXT WHICHFT
In which case you could just take the code of the subroutine and stick it into the FOR loop replacing the GOSUB.
The trouble with this type of fancier code is that the day that you have to work with a 7 foot ladder, for example, the fancy code doesn't work anymore, and you have to go back to a simple subrouting approach or come up with a clever way to do a FOR LOOP on values of 6, 7, 8 and 10. Is it worth it?
*****
The problem with CASE 2 is that you used a variable named BRING instead of BEGIN.
bring = INSTR(ladder, "Step")
In CASE 3, at the end of you FOOT 8 logic you're missing the READ statement, as so:
END IF
READ ladder, length '***** Missing for FOOT 8.
WEND
The code for FOOT 6, 8 and 10 are so similar that I would have made a subroutine (maybe you prefer a SUB) to avoid redundant code, and also to avoid having one part work and the other not. Example:
CASE 3
CLS
WHICHFT=6
GOSUB FOOTLOGIC
WHICHFT=8
GOSUB FOOTLOGIC
WHICHFT=10
GOSUB FOOTLOGIC
CASE 4
etc....
FOOTLOGIC:
PRINT WHICHFT;" FOOT"
RESTORE
READ ladder, length
WHILE ladder <> "xxx"
IF length = WHICHFT THEN
PRINT ladder
END IF
READ ladder, length
WEND
RETURN '>>>>>>>>>>>>>>
My sample code is intended to be simple. You can make it fancier by:
CASE 3
CLS
FOR WHICHFT=6 TO 10 STEP 2
GOSUB FOOTLOGIC
NEXT WHICHFT
In which case you could just take the code of the subroutine and stick it into the FOR loop replacing the GOSUB.
The trouble with this type of fancier code is that the day that you have to work with a 7 foot ladder, for example, the fancy code doesn't work anymore, and you have to go back to a simple subrouting approach or come up with a clever way to do a FOR LOOP on values of 6, 7, 8 and 10. Is it worth it?
*****
In order for code to be more readable on the forums, it has to already be indented. If it's not indented, then enclosing the code in a colored box is not going to make it any more readable. Do you agree?Nathan1993 wrote:Moneo, I was talking about it being more readable on the forums, not it QB. It's easier on the eyes, you know? Not using code tags is one of my pet peeves.
*****