QBasic and QB64 Discussion Board

[QB Forum Archives (1999-2009)/ ] [QB FAQ] [QB Links and Downloads] [Subforums and Chat Room] [Search]

QB64.Net Homepage   QB/QB64 Keywords   QB Graphics Forum   Homework Policy



Subscript out of range

by (no login)

First off this is for a homework assignment. I just need help with why the error keeps popping up. This program I am writing is supposed to print 30 random numbers then sort them numerically. Here is my code:

DIM lst(1 TO 30)
CLS
RANDOMIZE TIMER
RANDOMIZE seed
count = 1
GOSUB randnum
GOSUB sort
GOSUB sortprint
END



randnum:
FOR rnum = 1 TO 30
LET num = INT(RND * 100)
lst(count) = num
PRINT num
count = count + 1
NEXT rnum
PRINT "Unsorted List"
PRINT "Press any key to continue", anykey$
LET anykey$ = INPUT$(1)
RETURN

sort:
LET max = count - 1
LET swapflag = 0
DO WHILE swapflag = 0
LET swapflag = 1
FOR numsub = 1 TO max
IF lst(count) > lst(count + 1) THEN
SWAP lst(count), lst(count + 1)
LET swapflag = 0
END IF
NEXT numsub
LOOP
RETURN

sortprint:
FOR numsub = 1 TO count
PRINT lst(count)
NEXT numsub
RETURN


I keep getting a subscript out of range error. I can not figure out why!

Posted on Nov 25, 2012, 10:48 AM

Respond to this message   

Return to Index


count

by David (no login)

count is already up to 30 then you put in 1st(count+1).

Other comments- I'm surprised that you can actually name an array 1st.
Use the for next loop counter to increment the array index,
and your sort subroutine could do with a little work.
For such a small number of elements I would use "select sort" as it's easy to code and very stable.

Posted on Nov 25, 2012, 12:12 PM

Respond to this message   

Return to Index


Some Elementary Questions about QB64

by (Login jerryg50)

I am new to QB64. I used to use the MS QBasic Compiler.

I found this software to work great so-far.

Question 1:
Can I work it full screen, or in a larger screen that what I see?
The displayed screen is rather small.

Question 1:
When I installed it, did it install to the registry in any way?

I myself could not find it in any common registry entries such as regular programs.
I did not see it listed in Add Remove Programs.


Question 3:

After compiling the basic code as an EXE program, is the compiled program by default able to run as a stand-alone type program without libraries to accompany it?


Thanks in advance...

Jerry Greenberg

Posted on Nov 24, 2012, 12:59 PM

Respond to this message   

Return to Index


Re: Some Elementary Questions about QB64

by (Login MCalkins)
Moderator

First of all, please be aware of these additional resources:
http://www.qb64.net/forum/
http://www.qb64.net/wiki/index.php?title=Main_Page

>Can I work it full screen, or in a larger screen that what I see?
The displayed screen is rather small.

Yes, with the SDL version of QB64, you should be able to press Alt+Enter. Actually, with Alt+Enter, QB64 toggles between 3 modes: windowed, full screen stretched, and full screen square pixels.

Not yet, with the OpenGL version of QB64.

>When I installed it, did it install to the registry in any way?

No. QB64 stays in its own folder. To uninstall it, just delete the folder.

If you have some version of MinGW formally installed with environment variables, that can conflict with QB64.

>After compiling the basic code as an EXE program, is the compiled program by default able to run as a stand-alone type program without libraries to accompany it?

No. If you are using the SDL version of QB64, it requires some of the .DLL files that are in the QB64 folder. You can find which ones by trial and error.

the OpenGL version of QB64 uses static libraries instead of .DLLs. It doesn't depend on 3rd party .DLLs, but the .EXE files are bigger.

Regards,
Michael

Posted on Nov 24, 2012, 1:52 PM

Respond to this message   

Return to Index


Pi Calculation

by Oboe Shoes (no login)

On QB64.net, someone posted a Pi calculation program which relies on Python's support for bignums (arbitrary-precision integers). It prints pi to arbitrary precision (3.141592653589793238...)

Here is the original math paper which shows how to computation works.

http://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf

Posted on Nov 23, 2012, 3:28 PM

Respond to this message   

Return to Index


Pi using qbasic

by david (no login)

I've already wrote a program in qbasic to do this.
It will calculate up to about 2000 places maximum (long integer will overflow if you try anything greater).

You need to scroll down to the pi program.

http://www.network54.com/Forum/178387/thread/1102524466/last-1199216509/ProgramList+David

Posted on Nov 24, 2012, 3:43 AM

Respond to this message   

Return to Index


* I enjoyed your programs

by George (no login)

Posted on Nov 25, 2012, 1:10 PM

Respond to this message   

Return to Index


Re: Pi Calculation

by (no login)

Why not use the following formula that many people use:

pi = 4*atn(1)

Regards..... Moneo

Posted on Dec 15, 2012, 10:45 AM

Respond to this message   

Return to Index


Sequential File

by Jay (no login)

How do I create a sequential file in qbasic? I have a file that creates a sequential file but how doi create a file that will read and print data?

Posted on Nov 20, 2012, 7:18 PM

Respond to this message   

Return to Index


* Don't you have a textbook that explains how to do it?

by Solitaire (no login)

Posted on Nov 20, 2012, 7:49 PM

Respond to this message   

Return to Index


And if you don't have a textbook...

by (Login MCalkins)
Moderator

QBASIC has a built in help.

Also, QB64 has a wiki:

http://www.qb64.net/wiki/index.php?title=Main_Page

Check out the OPEN statement, and the LINE INPUT statement.

Regards,
Michael

Posted on Nov 20, 2012, 8:08 PM

Respond to this message   

Return to Index


I do but it doesn't explain it well

by Jay (no login)

Posted on Nov 20, 2012, 8:24 PM

Respond to this message   

Return to Index


No it doesn't (in QB at any rate). Here...

by (Login qb432l)
R

The main things to remember about sequential files is that data must be retrieved from the file in the same order and using the same data types as were written to the file.

For example:

a% = 10
b$ = "Hello"
c! = 3.14159

OPEN "Various.DAT" FOR OUTPUT AS #1
WRITE #1, a%, b$, c!
CLOSE #1

OPEN "Various.DAT" FOR INPUT AS #1
INPUT #1, d%, e$, f!
CLOSE #1

PRINT d%, e$, f!

Trying to retrieve data using the wrong data type or in the wrong order, will mess things up.

You can write literals to a file (10, "Hello" and 3.14159), but they must be retrieved using variables, and of the appropriate type.

Also be aware that opening a file for OUTPUT erases any existing file of that name. If you want to add to the contents of an existing file, open it for APPEND -- keeping in mind, of course, the existing order of data types in the file as well as those appended to it.

-Bob

Posted on Nov 20, 2012, 10:44 PM

Respond to this message   

Return to Index


Ok so would an example be like this?

by Jay (no login)

' Program To Read And Create A Formatted Report

' Variables Used

' SalesmanNum$ Salesman Number
' SalesmanNam Salesman Name
' SalesAmount Sales Amount
' CommissionRate Commission Rate
' CommissionAm Commission Amount
' T$, H$ Print images
' D$ Print images

' *********************************** Program Mainline ******************************
OPEN "SALEDATA.TXT" FOR OUTPUT AS #1
CLS
GOSUB InitializePrintImages
GOSUB PrintHeadings
GOSUB PrintReport
GOSUB Terminate
CLOSE #1
END

' **************************** Initialize Print Images ***********************************
InitializePrintImages:
LET T$ = " COMMISSION AMOUNT BY SALESMAN"
LET H$ = " Salesman Number Salesman Name Sales Amount Commission Rate Commission Amount"
LET D$ = " ### \ \ ####.## #.#% ##.#####"
RETURN

' *************************** Print Headings *****************************************
PrintHeadings:
PRINT #1, CHR$(12); 'Advance to top of page
PRINT #1, T$ 'Print Title
PRINT #1, " " 'Print blank line
PRINT #1, H$ 'Print column headings
PRINT #1, " " 'Print blank line
RETURN

' ************************ Print Report ************************************
PrintReport:
GOSUB ReadData
DO UNTIL UCASE$(SalesmanNum$) = "END"
LET CommissionAm = SalesAmount * CommissionRate
PRINT #1, USING D$; SalesmanNumber; SalesmanName; SalesAmount; CommissionRate
GOSUB ReadData
LOOP
RETURN

' ********************* Read Commission Data *********************************
ReadData:
READ SalesmanNum$, SalesmanName, SalesAmount, CommissionRate
DATA 1245, HERMAN HOLLERITH, 1157.85, 6.5
DATA 1386, BLAISE PASCAL, 2540.00, 5
DATA 1457, CHARLES BABBAGE, 1853.70, 4
DATA 1819, JOHN ATANASOFF, 650.00, 4
DATA 1722, JOHN VON NEUMANN, 1000.00, 5
DATA END 0,0,0,0
RETURN

' ****************** Terminate ***********************************
Terminate:
PRINT #1, " "
RETURN
' ******************************** END OF PROGRAM ************************


Posted on Nov 21, 2012, 8:03 AM

Respond to this message   

Return to Index


Syntax error

by (no login)

I keep getting the littlest errors that dont really stick out to me....


Why would I be getting a syntax error on this line?

READ SalesmanNum$, SalesmanNam, SalesAmount, CommissionRate

It seems to me like everything is the same throughout the code


' Program To Read And Create A Formatted Report

' Variables Used

' SalesmanNum$ Salesman Number
' SalesmanNam Salesman Name
' SalesAmount Sales Amount
' CommissionRate Commission Rate
' CommissionAm Commission Amount
' T$, H$ Print images
' D$ Print images

' *********************************** Program Mainline ******************************
OPEN "SALEDATA.TXT" FOR OUTPUT AS #1
CLS
GOSUB InitializePrintImages
GOSUB PrintHeadings
GOSUB PrintReport
GOSUB Terminate
CLOSE #1
END

' **************************** Initialize Print Images ***********************************
InitializePrintImages:
LET T$ = " COMMISSION AMOUNT BY SALESMAN"
LET H$ = " Salesman Number Salesman Name Sales Amount Commission Rate Commission Amount"
LET D$ = " ### \ \ ####.## #.#% ##.#####"
RETURN

' *************************** Print Headings *****************************************
PrintHeadings:
PRINT #1, CHR$(12); 'Advance to top of page
PRINT #1, T$ 'Print Title
PRINT #1, " " 'Print blank line
PRINT #1, H$ 'Print column headings
PRINT #1, " " 'Print blank line
RETURN

' ************************ Print Report ************************************
PrintReport:
GOSUB ReadData
DO UNTIL UCASE$(SalesmanNum$) = "END"
LET CommissionAm = SalesAmount * CommissionRate
LOOP
RETURN

' ********************* Read Commission Data *********************************

PrintDetail:
PRINT USING D1$; SalesmanNum$; SalesmanNam; SalesAmount; CommissionRate
RETURN

ReadData:
READ SalesmanNum$, SalesmanNam, SalesAmount, CommissionRate
RETURN

MyData:
DATA 1245, HERMAN HOLLERITH, 1157.85, 6.5
DATA 1386, BLAISE PASCAL, 2540.00, 5
DATA 1457, CHARLES BABBAGE, 1853.70, 4
DATA 1819, JOHN ATANASOFF, 650.00, 4
DATA 1722, JOHN VON NEUMANN, 1000.00, 5
DATA "END" 0,0,0,0
RETURN

' ****************** Terminate ***********************************
Terminate:
PRINT #1, " "
RETURN
' ******************************** END OF PROGRAM ************************


Posted on Nov 21, 2012, 11:12 AM

Respond to this message   

Return to Index


I've seen code like this before.

by (Login MCalkins)
Moderator

Based on Solitaire's reference to a textbook, and your affirmative response, I take it that this is some assignment from some textbook.

I wonder how many programmers have come to these forums with the exact same assignment.

Based on the style of code, my guess is that it is an obsolete text book.

If you don't mind me asking, what is the name of the textbook, and how old is it? Also, what is the nature of the course you are taking? Is it in school? If so, what level?

Are you taking this course to become a professional programmer, as a required part of some other course ,or just for the fun of it?

I think that the problem is that you are trying to read what would be a string into a numeric type.

Regards,
Michael

Posted on Nov 21, 2012, 12:59 PM

Respond to this message   

Return to Index


Yeah probably

by Jay (no login)

The name of the book is QuickBASIC and QBASIC Using /modular Structure by Julia Case Bradley from 1996 I think. This is a college course, BASIC Programming, The school just threw this in my major, which is Web Page Design.The class is an online class, I've asked my professor all these questions, he has answered me but his explanations have been very brief.. This is really my first semester taking a BASIC class

Posted on Nov 21, 2012, 6:33 PM

Respond to this message   

Return to Index


Re: Yeah probably

by (Login MCalkins)
Moderator

No offense to you, but I find that quite astonishing.

For Web Page Design, I would have thought that the programming languages they would teach you would be JavaScript and at least one of PHP, Python, or Perl, or even C++ for the server side.

Even for BASIC, they should be using a better textbook. Even by QBASIC standards, that programming style is somewhat archaic.

A professor gets paid to answer questions online? The people at these forums do it for free, and are probably better at it? :-O

Regards,
Michael

Posted on Nov 21, 2012, 9:39 PM

Respond to this message   

Return to Index


inquire

by (no login)

when I open some Qbasic programs, gave me in machine language. please how to change it again to qbasic

Posted on Nov 30, 2012, 12:30 AM

Respond to this message   

Return to Index


Do you mean the .EXE?

by (Login MCalkins)
Moderator

If you mean the compiled .EXE, then there is no easy way to decompile it. It's not impossible, but it's not easy.

If you mean a QuickBASIC 4.5 source file, open it in QB, then choose "File", "Save As...", then "Text - Readable By Other Programs".

Regards,
Michael

Posted on Nov 30, 2012, 1:09 AM

Respond to this message   

Return to Index


several things: (1 P.S.)

by (Login MCalkins)
Moderator

SalesmanNam needs to be a STRING. You can do this either by:
DIM SalesmanNam AS STRING
or by giving it an $ suffix.

After that, you'll need to fix PrintReport. It contains an infinite loop.

GOSUB ReadData
DO UNTIL UCASE$(SalesmanNum$) = "END"
LET CommissionAm = SalesAmount * CommissionRate
LOOP

You need to call ReadData inside the loop. There are several ways of going about this. You could do this:

GOSUB ReadData
DO UNTIL UCASE$(SalesmanNum$) = "END"
LET CommissionAm = SalesAmount * CommissionRate
GOSUB PrintDetail
GOSUB ReadData
LOOP

That reads the data once to start with. Then it checks for "END", processes the data, then reads again, then loops. Or, you could do this:

DO
GOSUB ReadData
IF UCASE$(SalesmanNum$) = "END" THEN EXIT DO
LET CommissionAm = SalesAmount * CommissionRate
GOSUB PrintDetail
LOOP

Either one does the job. In either case, you read a line of data, check whether it is "END" then process the data.

As you can see, you need to call PrintDetail inside the loop also.

You're not doing anything with CommissionAm. Shouldn't you print it inside PrintDetail?

There might be other issues, but that's what I could see.

By the way, LET is optional.

Regards,
Michael

P.S.

On your last DATA line, you need a comma between "END" and 0.

There's something wrong with your PRINT USING line in PrintDetail. D1$ doesn't seem to be used anywhere else. I changed it to D$, but it still didn't work. I've never been good with PRINT USING, so I'll leave it to you.

Also, shouldn't that go to the file? You omitted the #1.

Posted on Nov 21, 2012, 9:57 PM

Respond to this message   

Return to Index


I fixed the mistakes I think but

by (no login)

the output screen is black when I try to run the program... so do I have to open my text file with the data to view the output?

my code?

' Variables Used

' SalesmanNum Salesman Number
' SalesmanNam$ Salesman Name
' SalesAmount Sales Amount
' CommissionRate Commission Rate
' CommissionAm Commission Amount
' T$, H$ Print images
' D$ Print images

' *********************************** Program Mainline ******************************
OPEN "SALEDATA.TXT" FOR OUTPUT AS #1
CLS
GOSUB InitializePrintImages
GOSUB PrintHeadings
GOSUB PrintReport
GOSUB Terminate
CLOSE #1
END

' **************************** Initialize Print Images ***********************************
InitializePrintImages:
LET T$ = " COMMISSION AMOUNT BY SALESMAN"
LET H$ = " Salesman Number Salesman Name Sales Amount Commission Rate Commission Amount"
LET D$ = " ### \ \ ####.## #.#% ##.#####"
RETURN

' *************************** Print Headings *****************************************
PrintHeadings:
PRINT #1, CHR$(12); 'Advance to top of page
PRINT #1, T$ 'Print Title
PRINT #1, " " 'Print blank line
PRINT #1, H$ 'Print column headings
PRINT #1, " " 'Print blank line
RETURN

' ************************ Print Report ************************************
PrintReport:
DO
GOSUB ReadData
IF UCASE$(SalesmanNum$) = "END" THEN EXIT DO
LET CommissionAm = SalesAmount * CommissionRate
GOSUB ReadData
LOOP
RETURN

' ********************* Read Commission Data *********************************

ReadData:
DATA 1245, HERMAN HOLLERITH, 1157.85, 6.5
DATA 1386, BLAISE PASCAL, 2540.00, 5
DATA 1457, CHARLES BABBAGE, 1853.70, 4
DATA 1819, JOHN ATANASOFF, 650.00, 4
DATA 1722, JOHN VON NEUMANN, 1000.00, 5
DATA "END", 0,0,0,0
RETURN


' **************************************************
' * LPRINT DETAILS *
' ***************************************************

PrintDetail:
PRINT USING D1$; SalesmanNum; SalesmanNam$; SalesAmount; CommissionRate 'Print details
RETURN

' ******************************************************
' * LPRINT TOTALS *

' ****************** Terminate ***********************************
Terminate:
PRINT #1, " "
RETURN
' ******************************** END OF PROGRAM ************************


Posted on Nov 23, 2012, 8:35 AM

Respond to this message   

Return to Index


I fixed the mistakes I think but*

by Jay (no login)

On my code there is no LPRINT TOTALS, I dont erase it after copy and paste oops

Posted on Nov 23, 2012, 8:48 AM

Respond to this message   

Return to Index


*asterisks in post titles like that usually mean an empty post.

by (Login MCalkins)
Moderator

Posted on Nov 23, 2012, 10:03 AM

Respond to this message   

Return to Index


Re: I fixed the mistakes I think but (1 edit)

by (Login MCalkins)
Moderator

Yeah, if all you're doing is outputing to a file, then you would have to open the file to see the output. As your initial question was about file I/O, I assumed that's what you wanted to do.

-----

PrintReport:
DO
GOSUB ReadData
IF UCASE$(SalesmanNum$) = "END" THEN EXIT DO
LET CommissionAm = SalesAmount * CommissionRate
GOSUB ReadData
LOOP
RETURN

The problem with that is that you have 2 GOSUB ReadData inside the loop. One of my examples had 2 GOSUB ReadData lines, but only one was inside the loop. Further, if you're going to have the IF ... THEN EXIT DO, then you only need one GOSUB ReadData. The only reason that I had 2 of them in one example was because the loop condition was on the beginning of the loop.

What do you need to do?
You need to read all the lines of data. Any one of them could start with "END", at which point, you're done. Otherwise, you need to process each and every line of data, until you reach the "END.

Your current code basically skips every other line, because you have 2 ReadData's for every instance of processing. And I still don't see GOSUB PrintDetail...

I think that if you were to just change the second GOSUB ReadData to GOSUB PrintDetail, you would be doing much better.

-----

You broke your ReadData. Where's the READ statement?

READ SalesmanNum$, SalesmanNam$, SalesAmount, CommissionRate
RETURN

-----

Remember that SalesmanNum$ is still a string. It has to be, to get the "END".

-----

Because you forgot (or mistakenly removed) the $ from SalesmanNum$ on your PRINT USING line, it is using a separate variable, and thus printing 0. When you add the $, you get an error, because your PRINT USING expects a number. I think that the solution involves VAL(). Also, remember to make it PRINT #1, USING ... to get it to go to the file.

PRINT #1, USING D$; VAL(SalesmanNum$); SalesmanNam$; SalesAmount; CommissionRate 'Print details

I think that there is probably something wrong with your D$ format string, but I'll leave that to someone else. Specifically, I think you don't have enough #s for the Salesman Number. You're truncating the names, but I'm not sure if that's intentional. And you're still not printing CommissionAm. Why don't you add that to your PRINT USING line?

Regards,
Michael

Posted on Nov 23, 2012, 9:59 AM

Respond to this message   

Return to Index


Actually, my VAL() suggestion is not ideal...

by (Login MCalkins)
Moderator

It converts a string to a number, which PRINT converts right back to a string. That's not very efficient. It might be better to change your D$ format string to accommodate the Salesman Number being a string.

Regards,
Michael

Posted on Nov 23, 2012, 10:30 AM

Respond to this message   

Return to Index


Ok so like this?

by (no login)

' **************************** Initialize Print Images ***********************************
InitializePrintImages:
LET T$ = " COMMISSION AMOUNT BY SALESMAN"
LET H$ = " Salesman Number$ Salesman Name Sales Amount Commission Rate Commission Amount"
LET D$ = " ### \ \ ####.## #.#% ##.#####"
RETURN

' *************************** Print Headings *****************************************
PrintHeadings:
PRINT #1, CHR$(12); 'Advance to top of page
PRINT #1, T$ 'Print Title
PRINT #1, " " 'Print blank line
PRINT #1, H$ 'Print column headings
PRINT #1, " " 'Print blank line
RETURN

' ************************ Print Report ************************************
PrintReport:
DO
GOSUB ReadData
IF UCASE$(SalesmanNum$) = "END" THEN EXIT DO
LET CommissionAm = SalesAmount * CommissionRate
GOSUB ReadData
LOOP
RETURN

' ********************* Read Commission Data *********************************

ReadData:
DATA 1245, HERMAN HOLLERITH, 1157.85, 6.5
DATA 1386, BLAISE PASCAL, 2540.00, 5
DATA 1457, CHARLES BABBAGE, 1853.70, 4
DATA 1819, JOHN ATANASOFF, 650.00, 4
DATA 1722, JOHN VON NEUMANN, 1000.00, 5
DATA "END", 0,0,0,0
RETURN


' **************************************************
' * LPRINT DETAILS *
' ***************************************************

PrintDetail:
PRINT USING D1$; SalesmanNum$; SalesmanNam; SalesAmount; CommissionRate 'Print details
RETURN

Posted on Nov 23, 2012, 12:01 PM

Respond to this message   

Return to Index


Sorry, no... (1 edit)

by (Login MCalkins)
Moderator

Just glancing at it, a lot of the issues I mentioned in:
http://www.network54.com/Forum/648955/message/1353693540/

are still there. Also, it looks like you reverted your fix of SalesmanNam. But SalesmanNam$ and SalesmanNum$ need to be STRINGs.

Just to be clear that you understand data types:
STRINGs hold text.
Numeric types hold only numbers. Integer types (INTEGER, LONG) hold integers. Floating point types (SINGLE, DOUBLE) hold fractional numbers. In all cases, it is binary.

In the case of SalesmanNum$, it might look like it can be a numeric type, but remember that you have that "END" there, which could only be stored in a STRING. DATA is a little confusing, because it lets you get away with not putting STRINGs in quotation marks. Obviously, the names have to be STRINGs.

To avoid confusion, I would suggest putting all the STRING DATA in quotation marks, even though you don't have to.

Consider this:

DIM t AS STRING
DIM i AS LONG
t = "1234"
i = 1234

You see? "1234" is a STRING, even though it contains numbers. BASIC considers it to be text, and it is physically stored as ASCII characters for the numerals.

1234 is an integer. BASIC considers it to be a number, and it will be stored in the variable as a binary number.

Especially considering that you are probably going to move on to other languages when you actually get into web design, why don't you have a look at:

http://en.wikipedia.org/wiki/Type_system

Regards,
Michael

Posted on Nov 23, 2012, 2:34 PM

Respond to this message   

Return to Index


Can't believe i messed up on the string again

by (no login)


This looks better i think. I now have an input and output sequential file, but i still cant see any data on my output screen in either file

' Program To Read And Create A Formatted Report

' Variables Used

' SalesNum = Salesman Number
' SalesmanNam$ = Salesman Name
' SalesAmt = Sales Amount
' CommRt = Commission Rate
' CommissionAm = Commission Amount
' T1$, H1$ Print images
' D1$ Print images

' *********************************** Program Mainline ******************************
OPEN "SALEDATA.DAT" FOR OUTPUT AS #1
CLS
GOSUB InitializePrintImages
GOSUB PrintHeadings
GOSUB PrintReport
GOSUB Terminate
CLOSE #1
END

' **************************** Initialize Print Images ***********************************
InitializePrintImages:
LET T1$ = " COMMISSION AMOUNT BY SALESMAN"
LET H1$ = " Salesman Number Salesman Name$ Sales Amount Commission Rate Commission Amount"
LET D1$ = " ### \ \ ####.## #.#% ##.#####"
RETURN

' *************************** Print Headings *****************************************
PrintHeadings:
PRINT #1, CHR$(12); 'Advance to top of page
PRINT #1, T1$ 'Print Title
PRINT #1, " " 'Print blank line
PRINT #1, H1$ 'Print column headings
PRINT #1, " " 'Print blank line
RETURN

' ************************ Print Report ************************************
PrintReport:
DO UNTIL SalesNum = 0
LET CommAm = SaleAmount * (CommRt / 100)
PRINT SalesNum; SalesmanNam$; SaleAmt; CommRt; CommissionAm
INPUT #1, SalesNum, SalesmanNam$, SaleAmt, CommRt
LOOP
RETURN


' ********************* Read Commission Data *********************************

ReadData:
DATA 1245, HERMAN HOLLERITH, 1157.85, 6.5
DATA 1386, BLAISE PASCAL, 2540.00, 5
DATA 1457, CHARLES BABBAGE, 1853.70, 4
DATA 1819, JOHN ATANASOFF, 650.00, 4
DATA 1722, JOHN VON NEUMANN, 1000.00, 5
DATA "END", 0,0,0,0
RETURN


' **************************************************
' * LPRINT DETAILS *
' ***************************************************

PrintDetail:
PRINT USING D1$; SalesNum; SalesmanNam$; SalesAmt; CommRt; CommissionAm 'Print details
RETURN

' ****************** Terminate ***********************************
Terminate:
PRINT #1, " "
RETURN
' ******************************** END OF PROGRAM ************************


Posted on Nov 23, 2012, 5:22 PM

Respond to this message   

Return to Index


Re: Can't believe i messed up on the string again

by (Login MCalkins)
Moderator

Your READ statement is still missing.

Note that DATA lines are not executable. They do not need to be in a subroutine, although they can follow a label for use with RESTORE.

I see that you changed a bunch of your variable names.

Several of the issues that I mentioned previously remain.

I would suggest taking your time, and really making sure that you understand the concepts. Honestly, I get the impression that you are making changes to the code, sort of hoping that it will work, without really understanding the concepts. Granted, the style that your textbook seems to promote is not well suited to proper learning.

You need to understand what the program is supposed to do, and also understand how the pieces of BASIC language fit together to make it happen. As far as I am concerned, things like DATA, READ, and PRINT USING are implementation details, and are secondary to the goal of calculating and outputting sales data. However, the textbook and the teacher might not see it that way. They are trying to teach you a particular style of programming. There is something to be said for breaking a program down into small pieces, in this case, GOSUB routines, if for nothing else, as a learning aid. But modern real world code is unlikely to look anything like this assignment. For one thing, the GOSUB style does not directly support local variables, so a style that relies just on GOSUB is not ideal for larger programs.

I just noticed, not only do you not have a READ, but you now have an INPUT #1. That reminds me that you initially asked about sequential file access. Were you supposed to read the data from a file, and if so, why did you even have DATA and READ at all? I'm guessing that you were evolving code from a previous assignment. The problem that jumps out is that you've opened the file for output. BASIC won't let you do sequential formatted input and output to the same open file handle at the same time, and you probably wouldn't want to either. Why don't you OPEN your input file FOR INPUT AS one number, and OPEN your output file FOR OUTPUT as another number. Then you can INPUT from the one and PRINT or PRINT USING to the other. And then, you can get rid of the DATA lines. (The content would be in the input file.) (This is all assuming that that is what your assignment is. I'm not clear on what your exact assignment is.)

Regards,
Michael

Posted on Nov 23, 2012, 6:21 PM

Respond to this message   

Return to Index


I have to read the data from a .dat and print a chart of commission rates

by (no login)

What do you mean when you say the read data isn't included?

Posted on Nov 23, 2012, 9:18 PM

Respond to this message   

Return to Index


Re: I have to read the data from a .dat and print a chart of commission rates

by (Login MCalkins)
Moderator

>What do you mean when you say the read data isn't included?

Do you mean when I said that the DATA statements aren't executable? Or did you mean when I was talking about a missing READ statement? Anyway, it's a moot point for this assignment.


Here is a relatively simple example of a program that reads from an input file and writes to the screen and an output file.

the input file:
--------------------------------
-1, abc, 1.12
1, def, 0.34
3, xyz, 12.34
0,,0
--------------------------------

the code:
--------------------------------
DIM x AS LONG
DIM y AS STRING
DIM z AS DOUBLE
DIM t AS STRING

CLS
OPEN "delmein.txt" FOR INPUT AS 1
OPEN "delmeout.txt" FOR OUTPUT AS 2
DO UNTIL EOF(1)                                         'stop at end of file
 INPUT #1, x, y, z
 IF 0 = x THEN EXIT DO                                  'stop at x=0
 t = "x:" + STR$(x) + "   y: " + y + "   z:" + STR$(z) + "   x*z:" + STR$(x * z)
 PRINT t                                                'to the screen
 PRINT #2, t                                            'to the file
LOOP
CLOSE                                                   'closes all files
END
--------------------------------

Obviously, that's not the basis of anything that you should turn in for this assignment, but it demonstrates the concept without much fuss or distraction. I chose to store the output in the STRING variable 't', because I am outputting it twice, (once to the file, and once to the screen). If I were only outputting it once, I wouldn't bother with 't'; I'd just do it directly on the PRINT line. The string could be formatted better, but this is a simple demonstration.

This won't directly help you with the assignment, but hopefully it will help with the concepts.

Regards,
Michael

Posted on Nov 23, 2012, 10:00 PM

Respond to this message   

Return to Index


Ok I does clear things up so basically....

by (no login)


I was referring to the missing READ statement

So basically the code portion is the output file and the input is just the data?

So if im only outputting it to the screen it would be

"x:" + STR$(x) + " y: " + y + " z:" + STR$(z) + " x*z:" + STR$(x * z)

Posted on Nov 24, 2012, 9:44 AM

Respond to this message   

Return to Index


It does clear things up slighty... (EDIT)

by Jay (no login)

I was referring to the missing READ statement


So basically the code portion is the output file and the input is just the data?

So if im only outputting it to the screen it would be

"x:" + STR$(x) + " y: " + y + " z:" + STR$(z) + " x*z:" + STR$(x * z)

And so what does "t" represent, a piece of READ Data?

Posted on Nov 24, 2012, 9:47 AM

Respond to this message   

Return to Index


to the screen only

by (Login MCalkins)
Moderator

>So basically the code portion is the output file and the input is just the data?

No, the code creates the output when it is executed.

>So if im only outputting it to the screen it would be

"x:" + STR$(x) + " y: " + y + " z:" + STR$(z) + " x*z:" + STR$(x * z)

That's an expression. You'd have to put it somewhere. QBASIC won't let you have an expression alone, without doing something with the value. You could do:

PRINT "x:" + STR$(x) + " y: " + y + " z:" + STR$(z) + " x*z:" + STR$(x * z)

but, as PRINT will accept numbers, the STR$() becomes unnecessary. I would do something like this:

DIM x AS LONG
DIM y AS STRING
DIM z AS DOUBLE

CLS
OPEN "delmein.txt" FOR INPUT AS 1
DO UNTIL EOF(1)                                         'stop at end of file
 INPUT #1, x, y, z
 IF 0 = x THEN EXIT DO                                  'stop at x=0
 PRINT "x:"; x, "y: "; y, "z:"; z, "x*z"; x * z
LOOP
CLOSE
END

Rather than concatenating a bunch of strings together with '+', I feed a mix of strings and numbers to the PRINT statement, separated by semicolons and commas.

The formatting is a little different. The commas on the PRINT statement (as opposed to semicolons) align the cursor.

Regards,
Michael

Posted on Nov 24, 2012, 10:45 AM

Respond to this message   

Return to Index


Ok so it would be like this?

by (no login)

DIM x AS LONG
DIM y AS STRING
DIM z AS DOUBLE

CLS


x = SalesNum
y = SalesmanNam$
z = SalesAmt

OPEN "SALEDATA.txt" FOR INPUT AS 1
DO UNTIL EOF(1) 'stop at end of file
INPUT #1, x, y, z
IF 0 = x THEN EXIT DO 'stop at x=0
PRINT "x:"; x, "y: "; y, "z:"; z, "x*z"; x * z
LOOP
CLOSE
END

Posted on Nov 24, 2012, 12:02 PM

Respond to this message   

Return to Index


No... (perhaps some advice from the other members?)

by (Login MCalkins)
Moderator

As I said, that wasn't meant to be the basis for your homework assignment.

I get the impression that your understanding of variables and assignment is a little weak.

What do you think that this does?

x = SalesNum
y = SalesmanNam$
z = SalesAmt

That implicitly creates 3 variables, which are initialized to their defaults (0 for the numbers, "" for the string), and then assigns their values to the 3 variables that were explicitly defined with the DIM statements. It does Not magically link x with the concept of SalesNum or anything like that. BASIC is an imperative/procedural, language, not a declarative language. This is not algebra, and the compiler is not intelligent.

x = SalesNum is not some assertion that the two are linked for the rest of the program. It is a simple assignment. Since SalesNum appears nowhere else in the program, it is like you are saying, x = 0, but implicitly creating an otherwise unused variable in the process...

I think that you need to go back and relearn the fundamentals of programming. Start with data types, variables, variable assignment, and expressions. Then, move on to simple statements and functions.

LONG is a type.
DIM x AS LONG creates a variable of that type.
1 + 2 is an expression.
x = 1 + 2 assigns the value of the expression to the variable.

PRINT is a statement.
PRINT x prints the value of x to the screen.

I don't see any point learning about GOSUB and file I/O until you understand variables and data types. If not for the fact that you are taking a college course, I would almost suggest throwing away your textbook, and finding a decent tutorial, or using the built-in help and your own intelligence. There is a lot of sample code all over the place that you can use as a guide, but you have to apply your own intelligence and comprehend the concepts.

Perhaps some of the other members can provide further advice.

(I think one of the bigger flaws in QBASIC is that it allows implicit variable definition. I think that a lot of beginner bugs would be sorted pretty quickly if people could see when they are creating variables. I am still waiting for Galleon to implement his color highlighting for variable creation.)

Regards,
Michael

Posted on Nov 24, 2012, 2:09 PM

Respond to this message   

Return to Index


I glanced through your other topics.

by (Login MCalkins)
Moderator

It looks like TheBOB and lawgin already gave advice.

I would say this: it's not so much that we don't teach programming; I think it's more that we expect the person to comprehend the fundamentals. I don't think any of us mind helping out. It just seems kind of pointless helping you pass a test when you don't even understand the basic subject matter.

There are tutorials out there, some written by members of theses forums. I guess sometimes people don't feel like rewriting a tutorial every time that they answer a question.

I think that the main problem here is that you advanced beyond the basics without understanding them. It's like trying to change a tire before you know how to use a jack. There's nothing wrong with being a beginner, but you have to learn stuff in a logical order, and you have to comprehend the concepts.

Regards,
Michael

Posted on Nov 24, 2012, 2:25 PM

Respond to this message   

Return to Index


Variable assignments

by Solitaire (no login)

This will not work:

DIM x AS LONG
DIM y AS STRING
DIM z AS DOUBLE
CLS
x = SalesNum
y = SalesmanNam$
z = SalesAmt

You need to assign a KNOWN VALUE to your variables. The value of SalesNum etc. is not known. Those names themselves should be variables:

DIM SalesNum AS LONG
DIM SalesmanNam AS STRING
DIM SalesAmt AS DOUBLE

Then you need to assign a known value to those variables before you can use them. For example:

SalesNum = 456
SalesmanNam$ = "Dave Jones"
SalesAmt = 345.78

You are probably more familiar with the LET keyword for variable assignments:

LET SalesNum = 456
LET SalesmanNam$ = "Dave Jones"
LET SalesAmt = 345.78

However, be aware that LET is obsolete and the assignment statement will work very well without it.

Alternatively, you can also assign a value via a user input:

INPUT "Enter your name: ", SalesmanNam$

Use either the assignment statement or the INPUT statement to initialize your variables with known values before you can use them in the rest of the program. Of course, you know that variable values can be reassigned later in the program after the initialization. Again, this can be done either through an assignment or an INPUT statement.

I hope you also understand that string variable values must be enclosed within quotation marks:

DIM myname AS STRING
DIM mynumber AS INTEGER

myname$ = "Joe Smith"
mynumber = 25

Posted on Nov 24, 2012, 2:24 PM

Respond to this message   

Return to Index


After spending time fixing both my input and output files..

by (no login)

I was able to get the output file to run (with some help from my instructor)


REM*****THIS PROGRAM IS DESIGNED TO CERATE A SEQUENTIAL DATA FILE******

REM*******************PROGRAM VARIABLES****************
REM SPERSONNUM$ SALES PERSON'S NUMBER
REM NAM$ NAME
REM COMMR$ COMMISSION RATE
REM SALAMT$ AMOUNT OFSALARIES

REM *******************MAIN MODULE*********************

GOSUB OpenFile
GOSUB CreateFile
GOSUB CloseFile
PRINT
PRINT " END OF PROGRAM "
END

REM ********************OPEN FILE***********************
OpenFile:
OPEN "SALEDATA.DAT" FOR OUTPUT AS #1
RETURN
REM *******************CREATE FILE**********************
CreateFile:
GOSUB InputSalesmanNum
DO UNTIL SPERSONNUM = 0
GOSUB InputSalesData
GOSUB WriteRecord
GOSUB InputSalesmanNum
LOOP
RETURN
REM *********INPUT SALESMAN NUMBER*********************
InputSalesmanNum:
CLS
LOCATE 9, 14
PRINT "ENTER SALESMAN NUMBER";
INPUT "(ENTER 0 TO END)", SPERSONNUM
RETURN
REM *************SALES DATA******************************
InputSalesData:
LOCATE 11, 14
INPUT " SALESMAN NAME ", NAM$
LOCATE 13, 14
INPUT "ENTER SALE AMOUNT ", SALAMT
LOCATE 15, 14
INPUT "ENTER COMMISSION RATE ", COMMR
RETURN

' ************ Print The Report ***************

PrintReport:
DO UNTIL SalesNum = 0
LET Comm = SaleAmt * (CommRt / 100)
PRINT #1, USING D$; SalesNum; NAM$; SaleAmt; CommRt; Comm
INPUT #1, SalesNum, NAM$, SaleAmt, CommRt
LOOP
RETURN

RETURN
REM *****************WRITE RECORD TO DISK****************
WriteRecord:
WRITE #1, SPERSONNUM, NAM$, SALAMT, COMMR
RETURN
REM *****************CLOSE FILE***********************
CloseFile:
CLOSE #1
RETURN

The only program im having is that the program doesn't actually calculate the Commission Amount like I need it to, I dont know if its in the wrong spot ( LET Comm = SaleAmt * (CommRt / 100)or what because the program just runs in loop until the Read Data in done, anyone have any idea how to fix this?

Posted on Nov 25, 2012, 2:32 PM

Respond to this message   

Return to Index


Check your variable names.

by (Login MCalkins)
Moderator

CommRt is not the same as COMMR.
SALAMT is not the same as SaleAmt.

I really really wish that there were a way of enforcing explicit variable definition.

Regards,
Michael

Posted on Nov 25, 2012, 4:13 PM

Respond to this message   

Return to Index


I did and now get an (I think I was looking an the wrong code)

by (no login)

Expected: variable or end-of-statement error on the SalesmanNam$ of the line LINE INPUT #1, SalesNum; SalesmanNam$; SalesAmt; CommRt; CommissionAm, I put LINE INPUT after I I got an "Input past end of file" error.. an idea how to fix it?

' This program reads a sequential file
'
'
'
'
' SalesNum = Salesman Number
' SalesmanNam$ = Salesman Name
' SalesAmt = Sales Amount
' CommRt = Commission Rate
' CommissionAm = Commission Amount
'
' *******************************************
' Program mainline
' *******************************************
CLS
GOSUB CreateFile
GOSUB LoadFile
GOSUB CloseFile
END

' ******************* Create The File ***************

CreateFile:
OPEN "SALEDATA.DAT" FOR INPUT AS #1
RETURN

' ***************** Load File **********************
LoadFile:
DO UNTIL UCASE$(SalesmanNam$) = "END"
INPUT "Salesman Number", SalesNum
INPUT "Salesman Name", SalesmanNam$
INPUT "Sales Amount", SalesAmt
INPUT "Commission Rate", CommRt
INPUT "Commission Amount", CommissionAm
PRINT
LINE INPUT #1, SalesNum; SalesmanNam$; SalesAmt; CommRt; CommissionAm
LOOP
RETURN
'****************************************************************************
' Close File
'****************************************************************************

CloseFile:
CLOSE #1
RETURN



Posted on Nov 25, 2012, 8:54 PM

Respond to this message   

Return to Index


There is a difference between INPUT and LINE INPUT

by (Login MCalkins)
Moderator

INPUT reads comma separated values. Thus it can accept more than one variable at a time.
LINE INPUT reads the entire line at once as a string, regardless of commas.

So, if you have a line in the file:

0, 0, "abc", 1, 2

If you were to read it with:

DIM v AS LONG, w AS LONG, x AS STRING, y AS LONG, z AS LONG 'define the variables
OPEN "file" FOR INPUT AS 1
INPUT #1, v, w, x, y, z

then:
v would be 0
w would be 0
x would be "abc"
y would be 1
z would be 2

With line input, you would read the whole line at once as a single string.

DIM t AS STRING
OPEN "file" FOR INPUT AS 1
LINE INPUT #1, t

then t would be:
0, 0, "abc", 1, 2

For your program, I suggest changing the LINE INPUT to INPUT, and changing the semicolons on that line to commas. Note that you can remove all the individual INPUTs that don't have file numbers. Why ask the user if you're just going to ignore that and get it from the file?

If at that point, you get an INPUT past end of file, then you probably have a problem in the file.

Regards,
Michael

Posted on Nov 26, 2012, 2:22 AM

Respond to this message   

Return to Index


I tried your suggestion....

by (no login)

Of changing the semi colon's to commas but still got the error, so how do i fix the problem with the .DAT file?

Posted on Nov 26, 2012, 7:57 AM

Respond to this message   

Return to Index


Re: I tried your suggestion....

by (Login MCalkins)
Moderator

It should have comma separated values of a number, a string, and 3 more numbers per line. The string of the last line should be "end".

--------------------Example:
0,"abc",0,0,0
1,"abc",0,0,0
2,"abc",0,0,0
3,"abc",0,0,0
0,"end",0,0,0
--------------------

If there is any mismatch, or if there is no "end", or if you don't have the 3 numbers after the "end", then you will probably have an error.

Regards,
Michael

Posted on Nov 27, 2012, 3:03 AM

Respond to this message   

Return to Index


*Ok I will try that.. thanks

by (no login)

Posted on Nov 27, 2012, 3:30 PM

Respond to this message   

Return to Index


We've been seeing this same homework assignment here for 25 years...

by Pete (no login)

You'd really think that sales would be up by now! :)

Hey, if you get some time, I recommend applying what you learned about sequential files to something you like, and can use in your daily life. Here's a quick example:

CUT AND PASTE THESE 3 DATA ENTRIES INTO NOTEPAD AND SAVE THEM IN YOUR QB FOLDER AS MYFILE.TXT

1,Bing.com
2,Google.com
3,Yahoo.com

-----------------------------------------------------

CLS
LOCATE 3, 1
OPEN "MYFILE.TXT" FOR INPUT AS #1
DO UNTIL EOF(1)
INPUT #1, num$, myvar$
PRINT num$;
LOCATE CSRLIN, POS(0) + 1: PRINT myvar$
LOOP
CLOSE #1
PRINT

inputrow% = CSRLIN

DO
LOCATE inputrow%, 1
LINE INPUT "Input number of web page to open in default browser or leave blank to quit: "; mynum$
IF mynum$ = "" THEN SYSTEM: REM Blank entry ends and closes program.

OPEN "MYFILE.TXT" FOR INPUT AS #1
DO UNTIL EOF(1)
INPUT #1, num$, myvar$

IF mynum$ = num$ THEN
SHELL "cmd /c START www." + myvar$
FLAG% = -1
EXIT DO
END IF
LOOP
CLOSE #1

IF FLAG% = 0 THEN
LOCATE 25, 1
PRINT "No matching file, retry...";
SLEEP 3
LOCATE 25,1
PRINT SPACE$(80);
ELSE FLAG% = 0
END IF

LOCATE inputrow%, 1: PRINT SPACE$(80);
LOOP

------------------------------------------

Note, if you are using Win 98, change cmd to command. If you are using QB64, you can use:

SHELL _hide "START www." + myvar$

Have fun!


Pete

Posted on Dec 3, 2012, 11:13 AM

Respond to this message   

Return to Index


Roguelike Line of Sight Code

by (no login)

I'd like to use this code but it will not compile in QB64 and as a newcomer to QB64 I'm not sure exactly what I need to tweak to make it compile?

Any help would be greatly appreciated. Also if anyone is aware of any more Ascii/Roguelike code snippets for QB/QB64?

http://petesqbsite.com/sections/express/issue17/index.html#los

Posted on Nov 19, 2012, 5:03 AM

Respond to this message   

Return to Index


One possible problem...

by (Login qb432l)
R

The data type BYTE is not recognized by QB64. If you replace it with INTEGER that might make a difference, or if it's important to use only 1 byte, then use a one character string and convert.

-Bob

Posted on Nov 20, 2012, 11:08 AM

Respond to this message   

Return to Index


*QB64 does have _BYTE and _UNSIGNED _BYTE. Symbols: %%, ~%%

by (Login MCalkins)
Moderator

Posted on Nov 20, 2012, 6:12 PM

Respond to this message   

Return to Index


*Aha! The underscore! I tried BYTE to make sure but got an error - no underscore! Thanks.

by (Login qb432l)
R

*

Posted on Nov 20, 2012, 10:27 PM

Respond to this message   

Return to Index


looks like freebasic

by George (no login)

just switch to freebasic and don't look back

Posted on Nov 20, 2012, 3:59 PM

Respond to this message   

Return to Index


Type Not Defined Error?

by (no login)

DIM Num(10) AS INTERGER
DIM X AS INTERGER

Num(1) = 10
Num(2) = 12
Num(3) = 34
Num(4) = 45
Num(5) = 43
Num(6) = 56
Num(7) = 67
Num(8) = 87
Num(9) = 65
Num(10) = 90

For Index=1 to 10
PRINT Num(x)
Next x

Why would I be getting a type not defined error on "AS" from the

DIM Num(10) AS INTERGER line?

Posted on Nov 18, 2012, 9:07 PM

Respond to this message   

Return to Index


* Try AS INTEGER...

by (Login burger2227)
R

Posted on Nov 18, 2012, 9:49 PM

Respond to this message   

Return to Index


wow i cant spell haha

by (no login)

I can't believe I overlooked that.... lol

I have one more.question, how would I print that data set in reserve order?

Something like this

FOR 1 TO 10
PRINT Num(x)-1
FOR NEXT

?

Posted on Nov 19, 2012, 12:20 AM

Respond to this message   

Return to Index


10-x

by . (no login)

Posted on Nov 19, 2012, 12:38 AM

Respond to this message   

Return to Index


you could do either:

by (Login MCalkins)
Moderator

FOR 1 TO 10
PRINT Num(11 - x)
NEXT

or:

FOR 10 TO 1 STEP -1
PRINT Num(x)
NEXT

One other thing: Arrays usually start at 0, so, in BASIC:

DIM Num(10) AS INTEGER

creates an array with 11 elements, numbered 0 to 10. In programming, you'll find that a lot of things start at 0. The BASIC language exposes some of this, but hides it in other cases. If you move on to some other language, such as Assembly or C++, you'll find that even more things start at 0, such as line numbers and string byte offsets, although BASIC artificially starts them at 1.
When I use BASIC arrays, I usually like to explicitly specify an lbound of 0:

DIM Num(0 TO 10) AS INTEGER

Regards,
Michael

Posted on Nov 19, 2012, 3:55 AM

Respond to this message   

Return to Index


Great I was able to get run the program

by (no login)

Thanks!

Posted on Nov 20, 2012, 8:52 AM

Respond to this message   

Return to Index


Subscript Out Of Range? (NEW CODE)

by (no login)

Here is my completed code for my next assignment due Sunday, I get a Subscript Out Of Range error on the line

LET TotIncome = TotIncome + AnIncome(N) 'Calc total and dont really know why?


Any help to solving this error would be appreciated!

My Code:

DIM IDNum(1 TO 14), AnIncome(1 TO 14), NumPersons(1 TO 14)


GOSUB InitializeVariables
GOSUB LoadTables
GOSUB CalcPoverty
GOSUB CalcAvg


InitializeVariables:
LET TotIncome = TotIncome + AnIncome(N) 'Calc total
LET TotBelowPov = TotBelowPov + BelowPov(N) 'Calc total below pov
LET AveIncome = TotIncome / 14 'Calc average income
LET PercentBelowPov = TotBelowPov / 14 * 100 'Calc % below pov
LET AboveAve(N) = 48
LET PageCt = 0
LET IDNum = 0
LET NumPersons = 0
PRINT T1$ = " Income Survey PAGE ##"
LET H1$ = ""
PRINT H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
PRINT D1$ = " #### $#,###.## #"
PRINT ST$ = " / \ SUBTOTAL #"
PRINT TL$ = " TOTAL #"
LET MaxLines = 30
RETURN

'******************************
' Read numbers into the array
' *****************************


LoadTables:
FOR N = 1 TO 14
READ IDNum(N), AnIncome(N), NumPersons(N)
NEXT N

DATA 2497, 12,500, 2
DATA 3323, 13,00, 5
DATA 4521, 18,210, 4
DATA 6789, 8,000, 2
DATA 5476, 6,000, 1
DATA 4423, 16,400, 3
DATA 6587, 25,000, 4
DATA 3221, 10,500, 4
DATA 5555, 15,000, 2
DATA 0085, 19,700, 3
DATA 3097, 20,000, 8
DATA 4480, 23,400, 5
DATA 0265, 19,700, 2
DATA 8901, 13,000, 3

CalcPoverty:
IF NumPersons(N) <= 2 THEN
PovertyLevel(N) = 8000
ELSEIF NumPersons(N) > 2 THEN
PovertyLevel(N) = 8000 + (2000 * (NumPersons(N) - 2))
END IF
IF AnIncome(N) < PovertyLevel(N) THEN
BelowPov(N) = 1
ELSE
BelowPov(N) = 0
END IF
RETURN


CalcAvg:
FOR N = 1 TO 14
IF AnIncome(N) > AveIncome THEN
AboveAve(N) = 1
ELSE
AboveAve(N) = 0
END IF
NEXT N
RETURN






Posted on Nov 16, 2012, 9:47 AM

Respond to this message   

Return to Index


N must be a known value

by Solitaire (no login)

You did not initialize the value of N before the instruction using that variable. The default is 0 and your array starts with 1, so the array with that index does not exist.

All variables must be initialized with a known value. In your case, use a literal value to assign to each variable. Don't do any of the calculations until the end.

Posted on Nov 16, 2012, 4:49 PM

Respond to this message   

Return to Index


So it should look like this?

by (no login)

DIM N = 1 TO 14

Posted on Nov 17, 2012, 12:36 AM

Respond to this message   

Return to Index


Absolutely not!

by Solitaire (Login Solitaire1)
S

That syntax only applies to a FOR-NEXT loop.

You cannot assign unknown values to variables. You must initialize each variable with a known literal value. If it's a number, it should be initialized to 0. Any calculations you do with those numbers should be placed in a separate subroutine near the end of your program. You cannot assign a value to an array index without first knowing the index number. It looks like you are using the upperbound value of your array, so simply use the number 14 in one of the assignments:

InitializeVariables:
LET TotIncome = 0
LET TotBelowPov = 0
LET AveIncome = 0
LET PercentBelowPov = 0
LET AboveAve(14) = 48
LET PageCt = 0
LET IDNum = 0
LET NumPersons = 0
PRINT T1$ = " Income Survey PAGE ##"
LET H1$ = ""
PRINT H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
PRINT D1$ = " #### $#,###.## #"
PRINT ST$ = " / \ SUBTOTAL #"
PRINT TL$ = " TOTAL #"
LET MaxLines = 30
RETURN

Furthermore, the variable N you are using in the FOR-NEXT loop is nothing more than a counter. It can only be used INSIDE the loop.

If you want each index of the arrays to display the results, then they must be placed inside a FOR-NEXT loop. Your CalcPoverty sub must include a FOR-NEXT loop. Otherwise, the N will be equal to 0 and your array will generate an out-of-range error.

The calculated results should be placed after the last END IF inside the CalcAvg loop:

LET TotIncome = TotIncome + AnIncome(N) 'Calc total
LET TotBelowPov = TotBelowPov + BelowPov(N) 'Calc total below pov
LET AveIncome = TotIncome / 14 'Calc average income
LET PercentBelowPov = TotBelowPov / 14 * 100 'Calc % below pov

You will then need to print the results to the screen, still inside the loop.



Posted on Nov 17, 2012, 8:29 AM

Respond to this message   

Return to Index


Jay: I overlooked a syntax error in your code. Please respond.

by Solitaire (Login Solitaire1)
S

The following is not permitted:

PRINT H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
PRINT D1$ = " #### $#,###.## #"
PRINT ST$ = " / \ SUBTOTAL #"
PRINT TL$ = " TOTAL #"

You cannot print a variable assignment -- the output will be 0. There is no reason to use a variable if you are going to print the literal string. Either do this:

PRINT " ID Number ANNUAL INCOME NUMBER OF PERSONS "
PRINT " #### $#,###.## #"
PRINT " / \ SUBTOTAL #"
PRINT " TOTAL #"

or do this:

LET H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
LET D1$ = " #### $#,###.## #"
LET ST$ = " / \ SUBTOTAL #"
LET TL$ = " TOTAL #"

and print the string variables separately later in the program:

PRINT H2$
PRINT D1$
PRINT ST$
PRINT TL$

NOTE: The LET keyword is optional and obsolete. I included it because you've been using it and I didn't want to confuse you. But your teacher is using a very old textbook and really should discourage the use of the LET keyword. All the variable assignments can be simply done like this:

H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
D1$ = " #### $#,###.## #"
ST$ = " / \ SUBTOTAL #"
TL$ = " TOTAL #"

etc.

PS: I am expecting a response from you. It is good forum etiquette to respond when someone has taken the time to try and help you. Please let us know how you did.

Posted on Nov 20, 2012, 5:52 AM

Respond to this message   

Return to Index


I ended up getting so help for my profesor and sumbitted this

by (no login)

DIM IDNum(1 TO 14), AnIncome(1 TO 14), NumPersons(1 TO 14), PovertyLevel(1 TO 14), BelowPov(1 TO 14)

GOSUB InitializeVariables
GOSUB LoadTables
CLS
GOSUB PrintDetail
GOSUB PrintSubtotals
GOSUB PrintTotals
END

InitializeVariables:
LET PageCt = 0
LET IDNum = 0
LET NumPersons = 0
LET T1$ = " Income Survey PAGE ##"
LET H1$ = ""
LET H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
LET D1$ = " #### $##,###.## #"
LET ST$ = " \ \ SUBTOTAL #"
LET TL$ = " TOTAL #"
LET MaxLines = 30
RETURN

'******************************
' Read numbers into the array
' *****************************


LoadTables:
FOR N = 1 TO 14
READ IDNum(N), AnIncome(N), NumPersons(N)
GOSUB CalcPoverty
LET TotIncome = TotIncome + AnIncome(N)
NEXT N

DATA 2497, 12500, 2
DATA 3323, 1300, 5
DATA 4521, 18210, 4
DATA 6789, 8000, 2
DATA 5476, 6000, 1
DATA 4423, 16400, 3
DATA 6587, 25000, 4
DATA 3221, 10500, 4
DATA 5555, 15000, 2
DATA 0085, 19700, 3
DATA 3097, 20000, 8
DATA 4480, 23400, 5
DATA 0265, 19700, 2
DATA 8901, 13000, 3
DATA 0,0,0
DATA END
RETURN

CalcPoverty:
IF NumPersons(N) <= 2 THEN
PovertyLevel(N) = 8000
ELSEIF NumPersons(N) > 2 THEN
PovertyLevel(N) = 8000 + (2000 * (NumPersons(N) - 2))
END IF
IF AnIncome(N) < PovertyLevel(N) THEN
LET TotBelowPov = TotBelowPov + 1
END IF
RETURN

PrintDetail:
PRINT H2$
FOR N = 1 TO 14
PRINT USING D1$; IDNum(N); AnIncome(N); NumPersons(N) 'Print details
NEXT N
RETURN

PrintSubtotals:
LET AvgIncome = TotIncome / 14 'Calc average income
LET PercentBelowPov = TotBelowPov / 14 * 100 'Calc % below pov
RETURN

PrintTotals:
PRINT USING "$##,###.## \ \"; AvgIncome; "is the average income"
GOSUB PrintAboveAverage
PRINT USING "##.#% \ \"; PercentBelowPov; "of households are below the poverty line"
RETURN

PrintAboveAverage:
PRINT H2$
FOR N = 1 TO 14
IF AnIncome(N) > AvgIncome THEN
PRINT USING D1$; IDNum(N); AnIncome(N); NumPersons(N)
END IF
NEXT N
RETURN

Posted on Nov 20, 2012, 8:41 AM

Respond to this message   

Return to Index


do loop not looping

by Leon Schrecengost (no login)

It appears that the do loop is not looping. I added a locate print time$ after the DO statement and I expected to see the time update as it looped. It does not. Is there a trick that I missed.
Leon

Posted on Nov 15, 2012, 3:55 PM

Respond to this message   

Return to Index


* Post your code.

by Solitaire (no login)

Posted on Nov 15, 2012, 6:28 PM

Respond to this message   

Return to Index


not looping

by Leon Schrecengost (no login)

I done some more investagation and found that it is looping. I don't understand why the first test failed.
prior to the DO statement I have t$= time$ In the loop I put locate 1,1:prinr t$.
It printed the time once but never updated. This is what led me to think the loop was not working.
When I put the locate and print time$ after the DO it worked.Does it not recognize things defined prior to the DO LOOP?
Leon

Posted on Nov 16, 2012, 9:18 AM

Respond to this message   

Return to Index


Re: not looping

by (Login MCalkins)
Moderator

DO marks the beginning of the loop block. LOOP marks the end of the loop block. Everything in between is the loop body that is repeated. So if you have:

DIM t$
t$ = TIME$
DO
 PRINT t$
LOOP

t$ = TIME$ gets executed once before the loop is entered.
PRINT t$ is executed repeatedly, because it is inside the loop body. However, t$ is not being updated.

DIM t$
DO
 t$ = TIME$
PRINT t$
LOOP

Since t$ = TIME$ has been moved inside the loop body, t$ will be updated.

If you are still using QBASIC 1.1, don't forget to use the debugging facilities, particularly F8 to step through your code to see what it is doing.

Regards,
Michael

Posted on Nov 17, 2012, 2:56 AM

Respond to this message   

Return to Index


Qb64 working on iPad III

by (no login)

I have an iPad III and I would like to use qb64 program on iPad .
I am not able to download qb64 on my iPad, as the browser says unable to download!
Is there any solutions to how I can use qb64 program on IPAD III ?

Posted on Nov 14, 2012, 8:17 AM

Respond to this message   

Return to Index


Use an emulator

by (no login)

I don't think there is a QBASIC compiler written for the iPad. Maybe you can use an emulator - search the app store.

Posted on Nov 15, 2012, 3:53 PM

Respond to this message   

Return to Index


QB64 on IPad III

by (no login)

Tks

Posted on Nov 15, 2012, 5:27 PM

Respond to this message   

Return to Index


Highly unlikely -- incompatible platforms

by Solitaire (no login)

First of all, QB64 does not install like a normal application. It does not write to the registry. It goes into a folder that must be accompanied by a set of 16 supporting dlls. It can only save files to that folder.

Off the top of my head and to the best of my knowledge, in order to write an app for the Apple iphone or ipad, you need a proprietary language making use of syntax that is compatible with the iphone interface, preferably ON the Macintosh computer. This is not a simple task. It would require a complete rewrite of the program, restricting it to the available interface.

Galleon would have to respond and explain the technicalities, and correct any of my above comments.

Posted on Nov 15, 2012, 6:45 PM

Respond to this message   

Return to Index


Re: Highly unlikely -- incompatible platforms

by (Login MCalkins)
Moderator

The .DLLs are only relevant on Windows.

iOS uses Objective-C, but much of the code can be written in C++.

Android prefers Java, but allows some C++. Galleon has been working on porting QB64 to Android, and still using C++. However, he is busy with other things at the moment.

Regards,
Michael

Posted on Nov 17, 2012, 3:12 AM

Respond to this message   

Return to Index


Qb64 on IPAD III

by (no login)

Tks

Posted on Nov 15, 2012, 7:09 PM

Respond to this message   

Return to Index


*Galleon is planning to support iOS and Android in the future, but he is busy currently.

by (Login MCalkins)
Moderator

Posted on Nov 17, 2012, 2:58 AM

Respond to this message   

Return to Index


FOR/NEXT program question

by Jay (no login)

Im working on two homework assignments at oncce my next assignment is to

Use a FOR/NEXT loop to total the numbers (70,53,57,28,30,77,1,76,81,70) from 1 through 100. Print the numbers on the screen.

Here is the code I've started but I cant figure out how to print the numbers on the screen

'
'
'
s = 0
FOR i = 1 TO 10
INPUT x
s = s + x
NEXT i
PRINT s
END

Can someone please help me?

Posted on Nov 2, 2012, 8:53 PM

Respond to this message   

Return to Index


If I understand you correctly...

by (Login qb432l)
R

...you want to print the value of "s" after each increase. If that's so, you have to put your PRINT statement within the loop, just before "NEXT i".

-Bob

Posted on Nov 3, 2012, 4:29 AM

Respond to this message   

Return to Index


Yes sir, I just emailed my professor

by (no login)

Yes sir,



I just emailed my professor and he gave me what the code for this program is supposed to look like I posted it below, its pretty different then what i originally posted:


DIM X AS INTEGER

CLS

FROM X = 1 TO 100
RANDOMIZE TIMER
PRINT (RND * 100);
NEXT X


The program Im having when i try to run this program is that i get an "expected end-of-statement" error on "TO". Why would this be?

Posted on Nov 3, 2012, 7:55 AM

Respond to this message   

Return to Index


* It should be FOR not FROM

by Solitaire (no login)

Posted on Nov 3, 2012, 10:14 AM

Respond to this message   

Return to Index


*I realized that after I posted it lol oops

by Jay (no login)

Posted on Nov 3, 2012, 10:40 PM

Respond to this message   

Return to Index


READ the DATA and PRINT it inside the loop.

by Solitaire (Login Solitaire1)
S

As Bob said, place the PRINT statement inside the loop.

Since you have a list of specific values to add up, you may want to place them in a DATA list at the end. Include a READ statement followed by the calculation and then a PRINT statement before the end of the loop.

PS: You never responded to the solution I posted about your "LOOP without DO error." Did you fix that program? It would be nice to see how you worked it out, and common courtesy to respond when someone takes the time to offer you some advice and a possible solution.

Posted on Nov 3, 2012, 6:40 AM

Respond to this message   

Return to Index


how about this?

by (no login)

Maybe you like this code to?


s = 0
FOR i = 1 TO 10
INPUT x
r = s + x
PRINT s; " + "; x; " = "; r
s = r
NEXT i

Posted on Nov 10, 2012, 8:11 AM

Respond to this message   

Return to Index


Subscript Out Of Range?

by Jay (no login)

Why am I getting a Subscript Out Of Range error on this line?

IF AnIncome$(N) > AveIncome$ THEN

My code:


' Variables used:
' T1$ H1$, H2$, D1$ Print images
' ST$, TL$ Print images
' PrevTotal Previous Total
' LineCt Line number
' PageCt Page number
' TotHours Total
' IDNum ID Number
' AnnIncome$ Annual Income
' NumPersons Number of Persons


' ***********************************************************************
' * PROGRAM MAINLINE *
' ***********************************************************************

CLS
GOSUB InitializeVariables
GOSUB PrintHeadings
GOSUB ProcessDetail
GOSUB CalculatePovertyLevel
GOSUB CalculateAboveAve
END

' ***********************************************************************
' * INITIALIZE VARIABLES *
' ***********************************************************************

InitializeVariables:
LET PageCt = 0
LET Rate = 0
LET Hours = 0
LET T1$ = " Income Survey PAGE ##"
LET H1$ = ""
LET H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
LET D1$ = " #### $#,###.## #"
LET ST$ = " / \ SUBTOTAL #"
LET TL$ = " TOTAL #"
LET MaxLines = 30
RETURN

' ***************************************************************************
' * LPRINT HEADINGS *
' ***************************************************************************

PrintHeadings:
LET PageCt = PageCt + 1 'Add to page counter
PRINT CHR$(12); 'Advance to tope of page
PRINT USING T1$; PageCt 'Print title line
PRINT
PRINT H1$ 'Print column headings, line 1
PRINT H2$ 'Print column headings, line 2
PRINT
LET LineCt = 0 'Reset line counter
RETURN

' **********************************************************************************
' PROCESS DATA
' ***********************************************************************************
ProcessDetail:

LET TotIncome = TotIncome + AnIncome(N) 'Calc total
LET TotBelowPov = TotBelowPov + BelowPov(N) 'Calc total below pov
LET AveIncome = TotIncome / 14 'Calc average income
LET PercentBelowPov = TotBelowPov / 14 * 100 'Calc % below pov


' *************************************************************************
' * READ DATA *
' *************************************************************************

ReadData:
READ IDNum, AnnIncome$, NumPersons
DATA 2497, 12,500, 2
DATA 3323, 13,00, 5
DATA 4521, 18,210, 4
DATA 6789, 8,000, 2
DATA 5476, 6,000, 1
DATA 4423, 16,400, 3
DATA 6587, 25,000, 4
DATA 3221, 10,500, 4
DATA 5555, 15,000, 2
DATA 0085, 19,700, 3
DATA 3097, 20,000, 8
DATA 4480, 23,400, 5
DATA 0265, 19,700, 2
DATA 8901, 13,000, 3
RETURN


CalculatePovertyLevel:
IF NumPersons(N) <= 2 THEN
PovertyLevel(N) = 8000
ELSEIF NumPersons(N) > 2 THEN
PovertyLevel(N) = 8000 + (2000 * (NumPersons(N) - 2))
END IF
IF AnIncome(N) < PovertyLevel(N) THEN
BelowPov(N) = 1
ELSE
BelowPov(N) = 0
END IF
RETURN

CalculateAboveAve:
FOR N = 1 TO 14
IF AnIncome$(N) > AveIncome$ THEN
AboveAve(N) = 1
ELSE
AboveAve(N) = 0
END IF
NEXT N
RETURN





Posted on Nov 1, 2012, 12:05 PM

Respond to this message   

Return to Index


Have you DIM'd the array AnIncome$? ...

by (Login qb432l)
R

If you don't DIM the array and N is equal to more than 10, you'll get that error. Un-DIM'd arrays can't have more than 10 elements. Estimate the maximum value of any variable that will access the array and DIMension the array accordingly. For example, at the top of your program, put:

DIM AnIncome$(40)

-Bob

Posted on Nov 1, 2012, 12:17 PM

Respond to this message   

Return to Index


Re: Have you DIM'd the array AnIncome$? ...

by Jay (no login)

Ok I was able to fix that, but now i have the same error on the AboveAve(N) = 0 line.. when i tried to set the DIM i got an error

Posted on Nov 1, 2012, 1:50 PM

Respond to this message   

Return to Index


What exactly was the type of error when you tried to DIM it...

by (Login qb432l)
R

...and which line of code did it refer to? If it was an out of range error, it may be that your array was either too small, or perhaps the variable that accessed it was a minus value. It's difficult to say withou further information.

One method of troubleshooting is to insert temporary lines of code that print the values of variables, for example, in the upper left corner of the screen, and that way you'll know if it's a variable-value related problem.

-Bob

Posted on Nov 1, 2012, 4:48 PM

Respond to this message   

Return to Index


Re: Have you DIM'd the array AnIncome$? ...

by Jay (no login)

"identifier cannot end with %, &, !, # or $" when i first added the DIM AnIncome$(40) AS INTEGER
So I took out the $ in "AnIncome" and that worked i believe. I then attempted to add an DIM AboveAve(N) AS INTEGER array to the top of the program but got a message of expected end-of-statement error on AS"

Posted on Nov 1, 2012, 5:29 PM

Respond to this message   

Return to Index


That explains it...

by (Login qb432l)
R

Yes, you only need to identify the data type once. For example:

DIM AnIncome$(100)

or...

Dim AnIncome(100) AS STRING

What you were attempting to do was to create a string array as an integer array (two entirely different data types and definitely an error).

First, decide what type of data you're going to store in your array -- strings or integers.

a$ = "This is a string"

a% = 5

If you want to store number values in your array, then:

DIM AnIncome(100) AS INTEGER

or...

DIM AnIncome%(100)

...where "%" identifies the variable as an integer, just as "$" identifies a variable as a string.

If you want to store strings in your array, then:

DIM AnIncome(100) AS STRING

...or

DIM AnIncome$(100)

String arrays can also be DIMensioned to hold a string of a certain length. For example, if the string array is holding people's names, you probably wouldn't need more than, say, 40 characters for each element, so:

DIM GuysNames(100) AS STRING * 40

Incidentally, I'm only using "100" as a placeholder. The number of actual elements should be determined by you.

Hope that helps.
-Bob

Posted on Nov 2, 2012, 1:06 AM

Respond to this message   

Return to Index


That makes sense, but

by Jay (no login)

That makes sense, but then why would i be getting the subscript out of range error on the AboveAve(N)=0 line? Since i dont have it anywhere else in my code

Posted on Nov 2, 2012, 10:30 AM

Respond to this message   

Return to Index


Print the value of N...

by (Login qb432l)
R

Subscript out of range errors occur when you try to access an array element that doesn't exist. For example, if your array holds 25 elements, and N is worth 26, you'll get a subscript out of range error.

Printing the value of a variable lets you keep track of that value. There may be a line of code that keeps incrementing its value without your knowing. For example, N = N + 1 might be repeated somewhere when you didn't intend it to, in which case when you try to access your array, N might be worth 5000!

LOCATE 1, 1: PRINT N

Put that (temporary) line of code in a section of your program that is constantly active and watch what happens to the value of N. Compare those values to the number of elements you've DIMensioned into your array.

Let me know what happens.

-Bob

Posted on Nov 3, 2012, 4:23 AM

Respond to this message   

Return to Index


I guess N would equal

by (no login)

I did as you said (assuming i put it in the right spot) I still got the say result

I guess N would equal would equal 48 for the total of Number of persons

so would i be right in how i printed the LOCATE and LET statements?


' * PROGRAM MAINLINE *
' ***********************************************************************

CLS
GOSUB InitializeVariables
GOSUB PrintHeadings
GOSUB ProcessDetail
GOSUB CalculatePovertyLevel
GOSUB CalculateAboveAve
END

' ***********************************************************************
' * INITIALIZE VARIABLES *
' ***********************************************************************


LOCATE 1, 1: PRINT N

InitializeVariables:
LET PageCt = 0
LET Rate = 0
LET Hours = 0
LET T1$ = " Income Survey PAGE ##"
LET H1$ = ""
LET H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
LET D1$ = " #### $#,###.## #"
LET ST$ = " / \ SUBTOTAL #"
LET TL$ = " TOTAL #"
LET MaxLines = 30
RETURN

' ***************************************************************************
' * LPRINT HEADINGS *
' ***************************************************************************

PrintHeadings:
LET PageCt = PageCt + 1 'Add to page counter
PRINT CHR$(12); 'Advance to tope of page
PRINT USING T1$; PageCt 'Print title line
PRINT
PRINT H1$ 'Print column headings, line 1
PRINT H2$ 'Print column headings, line 2
PRINT
LET LineCt = 0 'Reset line counter
RETURN

' **********************************************************************************
' PROCESS DATA
' ***********************************************************************************
ProcessDetail:

LET TotIncome = TotIncome + AnIncome(N) 'Calc total
LET TotBelowPov = TotBelowPov + BelowPov(N) 'Calc total below pov
LET AveIncome = TotIncome / 14 'Calc average income
LET PercentBelowPov = TotBelowPov / 14 * 100 'Calc % below pov
LET AboveAve(N) = 48

Posted on Nov 3, 2012, 8:17 AM

Respond to this message   

Return to Index


Clearly, this is not the entire program...

by (Login qb432l)
R

For one thing, you have two GOSUB's without the corresponding subroutines. Putting the PRINT N statement where you have does nothing because it isn't even part of the program flow (after END and before a subroutine label).

You will have to include the entire program. The problem doesn't exist in the code you've given me, except that your arrays aren't DIM'd which may, once again, be the problem. Arrays that aren't DIMensioned have a maximum of 10 elements.

At no time is "N" given any value. The "48" is assigned to the "N" element of an array, it is not the value of "N". As I say, I'd need to see the entire program.

-Bob

Posted on Nov 3, 2012, 11:30 PM

Respond to this message   

Return to Index


Ok Ill email my professor and ask him...

by Jay (no login)

Ok Ill email my professor and ask him about the rest of the program... ill post back when he responds to me

Posted on Nov 4, 2012, 11:06 PM

Respond to this message   

Return to Index


Ok so I emailed my professor, he gave me this part of code:

by (no login)


CalcPoverty:
FOR Index = 0 TO (DataLength - 1)
IF NumPer(Index) <= 2 THEN
IF Income(Index) <= 8000 THEN
LET HousesBelow = HousesBelow + 1
END IF
ELSE
IF Income(Index) <= ((NumPer(Index) - 2) * 2000) + 8000 THEN
LET HousesBelow = HousesBelow + 1
END IF
END IF
NEXT Index
RETURN

CalcAvg:
FOR Index% = 1 TO DataLength
LET IncomeTotal = IncomeTotal + Income(Index%)
NEXT Index%
LET IncomeAvg = (IncomeTotal / DataLength)
RETURN

So how I have this:

DIM AnIncome AS INTERGER


' Variables used:
' T1$ H1$, H2$, D1$ Print images
' ST$, TL$ Print images
' PrevTotal Previous Total
' LineCt Line number
' PageCt Page number
' TotHours Total
' IDNum ID Number
' AnIncome$ Annual Income
' NumPersons Number of Persons


' ***********************************************************************
' * PROGRAM MAINLINE *
' ***********************************************************************

CLS
GOSUB InitializeVariables
GOSUB PrintHeadings
GOSUB CalcPoverty
GOSUB CalcAvg
END

' ***********************************************************************
' * INITIALIZE VARIABLES *
' ***********************************************************************


LOCATE 1, 1: PRINT N

InitializeVariables:
LET TotIncome = TotIncome + AnIncome(N) 'Calc total
LET TotBelowPov = TotBelowPov + BelowPov(N) 'Calc total below pov
LET AveIncome = TotIncome / 14 'Calc average income
LET PercentBelowPov = TotBelowPov / 14 * 100 'Calc % below pov
LET AboveAve(N) = 48
LET PageCt = 0
LET Rate = 0
LET Hours = 0
LET T1$ = " Income Survey PAGE ##"
LET H1$ = ""
LET H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
LET D1$ = " #### $#,###.## #"
LET ST$ = " / \ SUBTOTAL #"
LET TL$ = " TOTAL #"
LET MaxLines = 30
RETURN

' ***************************************************************************
' * LPRINT HEADINGS *
' ***************************************************************************

PrintHeadings:
LET PageCt = PageCt + 1 'Add to page counter
PRINT CHR$(12); 'Advance to tope of page
PRINT USING T1$; PageCt 'Print title line
PRINT
PRINT H1$ 'Print column headings, line 1
PRINT H2$ 'Print column headings, line 2
PRINT
LET LineCt = 0 'Reset line counter
RETURN

' *************************************************************************
' * READ DATA *
' *************************************************************************

ReadData:
READ IDNum, AnIncome, NumPersons
DATA 2497, 12,500, 2
DATA 3323, 13,00, 5
DATA 4521, 18,210, 4
DATA 6789, 8,000, 2
DATA 5476, 6,000, 1
DATA 4423, 16,400, 3
DATA 6587, 25,000, 4
DATA 3221, 10,500, 4
DATA 5555, 15,000, 2
DATA 0085, 19,700, 3
DATA 3097, 20,000, 8
DATA 4480, 23,400, 5
DATA 0265, 19,700, 2
DATA 8901, 13,000, 3
RETURN



CalcPoverty:
FOR Index = 0 TO (DataLength - 1)
IF NumPer(Index) <= 2 THEN
IF Income(Index) <= 8000 THEN
LET HousesBelow = HousesBelow + 1
END IF
ELSE
IF Income(Index) <= ((NumPer(Index) - 2) * 2000) + 8000 THEN
LET HousesBelow = HousesBelow + 1
END IF
END IF
NEXT Index
RETURN

CalcAvg:
FOR Index% = 1 TO DataLength
LET IncomeTotal = IncomeTotal + Income(Index%)
NEXT Index%
LET IncomeAvg = (IncomeTotal / DataLength)
RETURN

PrintDetail:
PRINT USING D1$; IDNum; AnIncome; NumPersons 'Print details
RETURN



I highly doubt this is correct at all, but im stuck out of ideas, i need to create an array of the data.. can someone please point me in the correct direction...

Posted on Nov 13, 2012, 9:23 PM

Respond to this message   

Return to Index


Ok so I emailed my professor, Here is my updated code (NEW POST)

by (no login)

Here is my updated code... is this right at all?

DIM IDNum(14) AS INTERGER
DIM AnIncome AS STRING
DIM NumPersons AS INTERGER


' Variables used:
' T1$ H1$, H2$, D1$ Print images
' ST$, TL$ Print images
' PrevTotal Previous Total
' LineCt Line number
' PageCt Page number
' TotHours Total
' IDNum ID Number
' AnIncome$ Annual Income
' NumPersons Number of Persons


' ***********************************************************************
' * PROGRAM MAINLINE *
' ***********************************************************************

CLS
GOSUB InitializeVariables
GOSUB PrintHeadings
GOSUB CalcPoverty
GOSUB CalcAvg
END

' ***********************************************************************
' * INITIALIZE VARIABLES *
' ***********************************************************************


LOCATE 1, 1: PRINT N

InitializeVariables:
LET TotIncome = TotIncome + AnIncome(N) 'Calc total
LET TotBelowPov = TotBelowPov + BelowPov(N) 'Calc total below pov
LET AveIncome = TotIncome / 14 'Calc average income
LET PercentBelowPov = TotBelowPov / 14 * 100 'Calc % below pov
LET AboveAve(N) = 48
LET PageCt = 0
LET Rate = 0
LET Hours = 0
LET T1$ = " Income Survey PAGE ##"
LET H1$ = ""
LET H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
LET D1$ = " #### $#,###.## #"
LET ST$ = " / \ SUBTOTAL #"
LET TL$ = " TOTAL #"
LET MaxLines = 30
RETURN

' ***************************************************************************
' * LPRINT HEADINGS *
' ***************************************************************************

PrintHeadings:
LET PageCt = PageCt + 1 'Add to page counter
PRINT CHR$(12); 'Advance to tope of page
PRINT USING T1$; PageCt 'Print title line
PRINT
PRINT H1$ 'Print column headings, line 1
PRINT H2$ 'Print column headings, line 2
PRINT
LET LineCt = 0 'Reset line counter
RETURN

' *************************************************************************
' * READ DATA *
' *************************************************************************

DIM IDNum(14)

' Each of these are separate variables:
IDNum(1) = 2497
IDNum(2) = 3323
IDNum(3) = 4521
IDNum(4) = 6789
IDNum(5) = 5476
IDNum(6) = 4423
IDNum(7) = 6587
IDNum(8) = 3221
IDNum(9) = 5555
IDNum(10) = 85
IDNum(11) = 3097
IDNum(12) = 4480
IDNum(13) = 265
IDNum(14) = 8901

PRINT IDNum(1), IDNum(2), IDNum(3), IDNum(4), IDNum(5)



CalcPoverty:
FOR Index = 0 TO (DataLength - 1)
IF NumPer(Index) <= 2 THEN
IF Income(Index) <= 8000 THEN
LET HousesBelow = HousesBelow + 1
END IF
ELSE
IF Income(Index) <= ((NumPer(Index) - 2) * 2000) + 8000 THEN
LET HousesBelow = HousesBelow + 1
END IF
END IF
NEXT Index
RETURN

CalcAvg:
FOR Index% = 1 TO DataLength
LET IncomeTotal = IncomeTotal + Income(Index%)
NEXT Index%
LET IncomeAvg = (IncomeTotal / DataLength)
RETURN

PrintDetail:
PRINT USING D1$; IDNum; AnIncome; NumPersons 'Print details
RETURN

Posted on Nov 13, 2012, 9:40 PM

Respond to this message   

Return to Index


What can I say ...

by (Login qb432l)
R

This is a fairly complex program and you don't seem to understand even the basics, such as program flow, the use of variables, what arrays are and how to use them, etc.. It's very difficult to explain what's wrong if we aren't even speaking the same language.

Is this a program you're trying to adapt for some purpose? You mention your professor. Are you studying programming with this person and if so, what does he/she want you to do with this program?

-Bob

Posted on Nov 14, 2012, 7:16 AM

Respond to this message   

Return to Index


Well....

by (no login)

Its for a BASIC programming class, the first time I've even even seen this language before. My major is Web-page design but thy just thew this class in a a required classes. My professor doesn't really explain things to well, he just gives up part of the code then doesn't answer any questions, so its not just me having trouble with this assignment.

Im supposed to write a program using a single-dimension array to analyze an income survey. And produce a 3-Part report showing

- A listing of the identification number and income for each household exceeding the average income.
- The percentage of households having incomes below the poverty level.

Posted on Nov 14, 2012, 7:45 AM

Respond to this message   

Return to Index


OverFlow Error, Array Program?

by (no login)

Why do I keep getting an OverFlow Error and is this the coorect way to set up an array


DIM IDNum(14) AS STRING
DIM x AS INTEGER

' This program uses an array to analyze an income survey


' IDNum ID Number
' AnIncome$ Annual Income
' NumPersons Number of Persons
' Sum The sum of all the numbers in the array

'Program Control:
GOSUB InitializeVariables
GOSUB LoadArray
GOSUB CalcPoverty
GOSUB CalcAvg

InitializeVariables:
LET TotIncome = TotIncome + AnIncome(N) 'Calc total
LET TotBelowPov = TotBelowPov + BelowPov(N) 'Calc total below pov
LET AveIncome = TotIncome / 14 'Calc average income
LET PercentBelowPov = TotBelowPov / 14 * 100 'Calc % below pov
LET AboveAve(N) = 48
LET PageCt = 0
LET IDNum = 0
LET NumPersons = 0
PRINT T1$ = " Income Survey PAGE ##"
LET H1$ = ""
PRINT H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
PRINT D1$ = " #### $#,###.## #"
PRINT ST$ = " / \ SUBTOTAL #"
PRINT TL$ = " TOTAL #"
LET MaxLines = 30
RETURN

'******************************
' Read numbers into the array
' *****************************

LoadArray:

FOR x = 1 TO 14
PRINT IDNum(x)
NEXT x

CalcPoverty:
FOR Index = 0 TO (DataLength - 1)
IF NumPer(Index) <= 2 THEN
IF Income(Index) <= 8000 THEN
LET HousesBelow = HousesBelow + 1
END IF
ELSE
IF Income(Index) <= ((NumPer(Index) - 2) * 2000) + 8000 THEN
LET HousesBelow = HousesBelow + 1
END IF
END IF
NEXT Index
RETURN

CalcAvg:
FOR Index% = 1 TO DataLength
LET IncomeTotal = IncomeTotal + Income(Index%)
NEXT Index%
LET IncomeAvg = (IncomeTotal / DataLength)
RETURN

' ************************************
' Data statements
' ************************************

DATA 2497, 12,500, 2
DATA 3323, 13,00, 5
DATA 4521, 18,210, 4
DATA 6789, 8,000, 2
DATA 5476, 6,000, 1
DATA 4423, 16,400, 3
DATA 6587, 25,000, 4
DATA 3221, 10,500, 4
DATA 5555, 15,000, 2
DATA 0085, 19,700, 3
DATA 3097, 20,000, 8
DATA 4480, 23,400, 5
DATA 0265, 19,700, 2
DATA 8901, 13,000, 3




Posted on Nov 14, 2012, 2:10 PM

Respond to this message   

Return to Index


Re: OverFlow Error, Array Program?

by lawgin (no login)

The overflow is caused by division by zero in this line:
LET IncomeAvg = (IncomeTotal / DataLength)
DataLength was never assigned a value, hence it is taken as zero.

You have set up a string array, but the data appears to be numeric. Normally this type of data field is loaded like this.

DIM a(14,3) as INTEGER
GOSUB LoadArray
.
.
.
etc.

LoadArray:
FOR x=1 to 14
FOR y=1 to 3
READ a(x,y)
NEXT y
NEXT x
RETURN

Posted on Nov 14, 2012, 3:38 PM

Respond to this message   

Return to Index


Ok so the program would look like this?

by (no login)

DIM a(14, 3) AS INTEGER

GOSUB InitializeVariables
GOSUB LoadArray
GOSUB CalcPoverty
GOSUB CalcAvg


InitializeVariables:
LET TotIncome = TotIncome + AnIncome(N) 'Calc total
LET TotBelowPov = TotBelowPov + BelowPov(N) 'Calc total below pov
LET AveIncome = TotIncome / 14 'Calc average income
LET PercentBelowPov = TotBelowPov / 14 * 100 'Calc % below pov
LET AboveAve(N) = 48
LET PageCt = 0
LET IDNum = 0
LET NumPersons = 0
PRINT T1$ = " Income Survey PAGE ##"
LET H1$ = ""
PRINT H2$ = " ID Number ANNUAL INCOME NUMBER OF PERSONS "
PRINT D1$ = " #### $#,###.## #"
PRINT ST$ = " / \ SUBTOTAL #"
PRINT TL$ = " TOTAL #"
LET MaxLines = 30
RETURN

'******************************
' Read numbers into the array
' *****************************

LoadArray:
FOR x = 1 TO 14
FOR y = 1 TO 3
READ a(x, y)
NEXT y
NEXT x
RETURN

CalcPoverty:
FOR Index = 0 TO (DataLength - 1)
IF NumPer(Index) <= 2 THEN
IF Income(Index) <= 8000 THEN
LET HousesBelow = HousesBelow + 1
END IF
ELSE
IF Income(Index) <= ((NumPer(Index) - 2) * 2000) + 8000 THEN
LET HousesBelow = HousesBelow + 1
END IF
END IF
NEXT Index
RETURN

CalcAvg:
FOR Index% = 1 TO DataLength
LET IncomeTotal = IncomeTotal + Income(Index%)
NEXT Index%
LET IncomeAvg = (IncomeTotal / DataLength)
RETURN

' ************************************
' Data statements
' ************************************

DATA 2497, 12,500, 2
DATA 3323, 13,00, 5
DATA 4521, 18,210, 4
DATA 6789, 8,000, 2
DATA 5476, 6,000, 1
DATA 4423, 16,400, 3
DATA 6587, 25,000, 4
DATA 3221, 10,500, 4
DATA 5555, 15,000, 2
DATA 0085, 19,700, 3
DATA 3097, 20,000, 8
DATA 4480, 23,400, 5
DATA 0265, 19,700, 2
DATA 8901, 13,000, 3




Posted on Nov 14, 2012, 6:09 PM

Respond to this message   

Return to Index


Sorry...

by (Login qb432l)
R

Like I said, it's difficult to explain if you don't understand even basic programming concepts. The very first GOSUB is doing calculations with values that don't even exist; you have DATA that isn't even being used (READ statement); your array is a string array but none of the DATA are strings; you're using NumPer(), AboveAve() and Income() arrays in calculations, yet they have no value, not to mention the variables N and Index (etc., etc.).

Help is available, but we don't teach programming here. Personally, I think your professor should consider another profession.

-Bob

Posted on Nov 14, 2012, 5:12 PM

Respond to this message   

Return to Index


Thats okay.. Im just trying to get through this class

by (no login)

Posted on Nov 14, 2012, 5:27 PM

Respond to this message   

Return to Index


If you have the time

by lawgin (no login)

It looks like that you need a lot more help with programming than you can get on an online forum such as this. I suggest that you get a book on qbasic geared toward beginners. I recommend "Running Qbasic" by Michael Halvorson. There are used copies available for less than $4 at abebooks.com. Good luck.

Posted on Nov 15, 2012, 9:29 AM

Respond to this message   

Return to Index


awnser

by (no login)

Q
Why am I getting a Subscript Out Of Range error on this line?

IF AnIncome$(N) > AveIncome$ THEN

A
1. a $ symbol means you variable is a string of text. You can not calculate with text.

2. I did not see a DIM AnIncome$(x) (where x is a number) in your code.

3. you use AnIncome$ and AnIncome. it is not the same variable. the $ sign makes it a different variable in memory.

Posted on Nov 10, 2012, 8:21 AM

Respond to this message   

Return to Index


LOOP without DO error?

by (no login)

Why am I getting a LOOP without DO error on this program?

My code is below:

DIM MenuIn AS INTEGER 'Numeric for user main menu input


DO
GOSUB MainMenu 'Call the main menu
SELECT CASE MenuIn
CASE 1 '1 Computer Information Systems
GOSUB CompInforSystems
CASE 2 '2 Computer Programming
GOSUB ComProg
CASE 3 '3 Business Economics
GOSUB BusinessEconomics
CASE 4 '4 Photography
GOSUB Photography
CASE 5 '5 quits

LOOP UNTIL MenuIn = 5

CLOSE 'Close any open files
END 'End of program

MainMenu:
CLS
PRINT
PRINT "best colleges by major"
PRINT "**********************"
PRINT "1. Computer Information Systems"
PRINT "2. Computer Programming"
PRINT "3. Business Economics"
PRINT "4. Photography"
PRINT "5. Quit the program"
PRINT
PRINT "Please press the number of your choice..."
PRINT
PRINT "(5 will exit the program)"
PRINT
INPUT "What is your Selection? ", MenuIn
RETURN

CompInforSystems:
DATA University Of Twilight Zone
DATA BOGUS UNIVERSITY
DATA STATE POLYMETRIC UNIVERSITY
DATA COLLEGE OF THE LOAFERS
DATA UNIVERSITY OF THE ATLANTIC
RETURN

ComProg:
DATA CALIFORNIA LONG-TERM COLLEGE
DATA SAN ROSE STATE UNIVERSITY
DATA ROMONA STATE UNIVERSITY
DATA SOUTHERN STATE UNIVERSITY
DATA BOGUS UNVERSITY
RETURN

BusinessEconomics:
DATA CHAMPAIN COLLEGE
DATA GOLDEN BATE UNIVERSITY
DATA HOLY VERBS COLLEGE
DATA UNIVERSITY OF SANDY BEACH
DATA WOODPECKER UNIVERSITY
RETURN

Photography:
DATA ART CENTER COLLEGE
DATA COOKS INSTITUTE
DATA COMA LINDA UNIVERSITY
DATA BILLS COLLEGE
DATA University Of Twilight Zone
RETURN

Posted on Oct 31, 2012, 11:49 PM

Respond to this message   

Return to Index


*Add an: 'END SELECT'

by OPRESION (no login)

¡¡¡
(edited for case - mc)

Posted on Nov 1, 2012, 1:44 AM

Respond to this message   

Return to Index


Re: *Add an: 'END SELECT'

by Jay (no login)

i tried your suggestion and it didnt work....

Posted on Nov 1, 2012, 1:44 PM

Respond to this message   

Return to Index


You need to READ the DATA

by Solitaire (Login Solitaire1)
S

You needed to place END SELECT at the end of your last CASE. However, you did not provide a way to READ or PRINT any of the DATA, nor any way to keep it on the screen before clearing.

The DATA items should not be inside of subs. Remove the RETURN statement from the end of each of the DATA listings. The title followed by the : will be referred to after each CASE.

In order not to reread the same DATA, use the RESTORE statement to start over again from the items after the named title. If you leave out RESTORE, it will simply READ all the DATA items in order, no matter which selection the user makes, until you get an "Out of Data" error.

In order to read all 5 DATA items in each listing, you need to use a FOR-NEXT loop. After the loop is read, you need an INPUT statement to keep the display on the screen before it clears.

Enter the following revised code into your DO loop, and it should work as you intended. Remove all the RETURN statements from the DATA listings, but leave everything else alone.

DO
GOSUB MainMenu 'Call the main menu
SELECT CASE MenuIn
CASE 1 '1 Computer Information Systems
RESTORE CompInforSystems
CASE 2 '2 Computer Programming
RESTORE ComProg
CASE 3 '3 Business Economics
RESTORE BusinessEconomics
CASE 4 '4 Photography
RESTORE Photography
CASE 5 '5 quits
END
END SELECT
PRINT
FOR x = 1 TO 5
READ univ$
PRINT univ$
NEXT x
PRINT
INPUT "Press Enter to continue", wait$
LOOP UNTIL MenuIn = 5

Posted on Nov 2, 2012, 6:46 AM

Respond to this message   

Return to Index


Another issue with your SELECT CASE input

by Solitaire (Login Solitaire1)
S

You declared the input variable as an integer, but you are not doing any math computation with that input. It should be declared as a string. Otherwise, if the user enters a non-numeric input, it will result in a "Redo from start" message.

Declare the variable as a string, and enclose all the numbers between "".

DIM MenuIn AS STRING 'non-numeric for user main menu input
DO
GOSUB MainMenu 'Call the main menu
SELECT CASE MenuIn
CASE "1" '1 Computer Information Systems
RESTORE CompInforSystems
CASE "2" '2 Computer Programming
RESTORE ComProg
CASE "3" '3 Business Economics
RESTORE BusinessEconomics
CASE "4" '4 Photography
RESTORE Photography
CASE "5" '5 quits
END
END SELECT
PRINT
FOR x = 1 TO 5
READ univ$
PRINT univ$
NEXT x
PRINT
INPUT "Press Enter to continue", wait$
LOOP UNTIL MenuIn$ = "5"

Posted on Nov 2, 2012, 8:27 AM

Respond to this message   

Return to Index


Alternative code using PRINT instead of DATA

by Solitaire (Login Solitaire1)
S

You can keep your subs if you replace each DATA statement with PRINT and enclose the items within "". You will still need to use an INPUT statement to display the output before clearing the screen. Here is some sample code:

DIM MenuIn AS STRING 'non-numeric for user main menu input
DO
GOSUB MainMenu 'Call the main menu
SELECT CASE MenuIn
CASE "1" '1 Computer Information Systems
GOSUB CompInforSystems
CASE "2" '2 Computer Programming
GOSUB ComProg
CASE "3" '3 Business Economics
GOSUB BusinessEconomics
CASE "4" '4 Photography
GOSUB Photography
CASE "5" '5 quits
END
END SELECT
PRINT
INPUT "Press Enter to continue", wait$
LOOP UNTIL MenuIn = "5"


CompInforSystems:
PRINT
PRINT "University Of Twilight Zone"
PRINT "BOGUS UNIVERSITY"
PRINT "STATE POLYMETRIC UNIVERSITY"
PRINT "COLLEGE OF THE LOAFERS"
PRINT "UNIVERSITY OF THE ATLANTIC"
RETURN

Posted on Nov 2, 2012, 8:32 AM

Respond to this message   

Return to Index


thanks guys....

by Jay (no login)

I was able to fix the program and get it to run

Posted on Nov 3, 2012, 7:40 AM

Respond to this message   

Return to Index


* Exactly how did you fix it?

by Solitaire (no login)

Posted on Nov 3, 2012, 10:15 AM

Respond to this message   

Return to Index


I print the read data

by Jay (no login)

part of it: I got some help from a fellow classmate

LOCATE 15, 1
PRINT "1. University Of Twilight Zone"
PRINT "2. Bogus University"
PRINT "3. State Polymetric University"
PRINT "4. College of Loafers"
PRINT "5. University of The Atlantic"
RETURN

Posted on Nov 3, 2012, 10:39 PM

Respond to this message   

Return to Index


Illegal Function Call.. QBASIC??

by (no login)

I can't figure out why I'm getting an Illegal Function Call error on this line

PRINT M4$
LOCATE 26, 21

'************************** PROGRAM 9.2 *************************

' THIS IS A MENU-DRIVEN PROGRAM TO CONVERT TO AND FROM U'S',
' EUROPEAN, AND GREAT BRITAIN CURRENCIES

' PROGRAM VARIABLES
'
' CHOICE AND CHOICE$ MENU CHOICES
' M1$, M2$, M3$, M4$, M5$, M6$ AND M7$ USED TO DISPLAY THE MENU
' F1$ F2$, F3$, AND F4$ USED TO PRINT OUT THE FORMULAS
' E$ USED TO DISPLAY AN ERROR MESSAGE
' ANSWER$ CHOICE TO PREFORM A CALCULATION
' USD U.S. DOLLARS
' ERR EURROS
' GBP GREAT BRITAIN POUNDS
' PAUSE$ PAUSE TO READ A MESSAGE

' ***************************** MAIN MODULE **************************

COLOR 14, 3
GOSUB InitializePrintImages
LET CHOICE = 0
DO UNTIL CHOICE = 5 ' 5 IS ENDING VALUE
GOSUB PrintMenu ' PRINT MENU & INPUT CHOICE
SELECT CASE CHOICE
CASE 1 '1 converts US Dollars to Euros
GOSUB CalculateUSDToEUR
CASE 2 '2 converts Euros to US Dollars
GOSUB CalculateEURToUSD
CASE 3 '3 converts US Dollars to British Pounds
GOSUB CalculateUSDToGBP
CASE 4 '4 converts British Pounds to US Dollars
GOSUB CalculateGBPToUSD
CASE 5 '5 quits
CLS
LOCATE 20, 21
PRINT " A penny for you thoughts equals "
LOCATE 22, 21
PRINT " 1 cent in America, "
LOCATE 24, 21
PRINT " 78/100ths of a cent in Europe,"
LOCATE 26, 21
PRINT " and 64/100th of a cent in Great Britain. Good Day!"
LOCATE 36, 21
LOCATE 25, 30
CASE ELSE
LOCATE 18, 25
PRINT E$
LOCATE 30, 47
PRINT " "
INPUT "", CHOICE$
LET CHOICE = VAL(CHOICES$)
END SELECT
LOOP
END

' ************************ INITIALIZE PRINT IMAGES **************

InitializePrintImages:
LET M1$ = "MENU CHOICES"
LET M2$ = "1. CONVERT U.S. DOLLARS TO EUROS"
LET M3$ = "2. CONVERT EUROS TO U.S. DOLLARS"
LET M4$ = "3. CONVERT U.S. DOLLARS TO BRITISH POUNDS"
LET M5$ = "4. CONVERT BRITISH POUNDS TO U.S. DOLLARS"
LET M6$ = "5. END"
LET M7$ = "ENTER MENU CHOICE"
LET F1$ = "1 U.S. DOLLAR (USD) = 0.78 EUROS (EUR)"
LET F2$ = "1 EURO (EUR) 1.28 U.S. DOLLARS (USD)"
LET F3$ = "1 U.S. DOLLAR (USD) = 0.63 BRITISH POUNDS (GBP)"
LET F4$ = "1 BRITISH POUND (GBP) = 1.58 U.S. DOLLARS (USD)"
LET E$ = "INVALID CHOICE. ENTER 1 - 5 ONLY"
RETURN

' ************************** PRINT MENU ******************

PrintMenu:
CLS
LOCATE 15, 34
PRINT M1$
LOCATE 20, 21
PRINT M2$
LOCATE 22, 21
PRINT M3$
LOCATE 24, 21
PRINT M4$
LOCATE 26, 21
PRINT M5$
LOCATE 28, 21
PRINT M6$
LOCATE 30, 28
PRINT M7$
LOCATE 30, 47
INPUT "", CHOICE$
LET CHOICE = VAL(CHOICE$)
RETURN ' TO MAIN MODULE

' *********************** CALCULATE U.S. DOLLARS TO EUROS ***********

CalculateUSDToEUR:
CLS
LOCATE 20, 21
PRINT F1$
GOSUB DesireCalculation
IF UCASE$(ANSWER$) = "Y" THEN
GOSUB PerformUSDToEUR
END IF
RETURN

' ************************ PERFORM USD TO EUR CALCULATION ********

PerformUSDToEUR:
CLS
LOCATE 15, 21
PRINT "CONVERT U.S. DOLLARS TO EUROS"
LOCATE 20, 21
INPUT "ENTER U.S. DOLLAR AMOUNT $", USD
LET EUR = USD * .78
LOCATE 22, 21
PRINT USD; "U.S. DOLLARS EQUALS "; EUR; "EUROS"
LOCATE 30, 21
INPUT "PRESS RETURN TO CONTINUE ", PAUSE$
RETURN

' ********************** CALCULATE EUROS TO U.S. DOLLARS *****************

CalculateEURToUSD:
CLS
LOCATE 20, 21
PRINT F2$
LOCATE 22, 21
PRINT USD; "U.S. DOLLARS EQUALS "; GBP; "BRITISH POUNDS"
LOCATE 30, 21
INPUT "PRESS RETURN TO CONTINUE ", PAUSE$
RETURN


' *********************** CALCULATE BRITISH POUNDS TO U.S. DOLLARS *******

CalculateGBPToUSD:
CLS
LOCATE 20, 21
PRINT F4$
GOSUB DesireCalculation
IF UCASE$(ANSWER$) = "Y" THEN
GOSUB PerformGBPToUSD
END IF
RETURN

' ******************* PERFORM GBP TO USD CALCULATION *******************

PerformGBPToUSD:
CLS
LOCATE 15, 21
PRINT "CONVERT BRITISH POUNDS TO U.S. DOLLARS"
LOCATE 20, 21
INPUT "ENTER BRITISH POUNDS AMOUNT ", GBD
LET USD = GBD * 1.58
LOCATE 22, 21
PRINT GBD; "BRITISH POUNDS EQUALS "; USD; "U.S. DOLLARS"
LOCATE 30, 21
INPUT "PRESS RETURN TO CONTINUE ", PAUSE$
RETURN

' ********************* DESIRE CALCULATION ******************

DesireCalculation:
LOCATE 22, 15
PRINT "PERFORM A CALCULATION USING THIS FORMULA (Y/N)";
INPUT ANSWER$
DO WHILE UCASE$(ANSWER$) <> "N" AND UCASE$(ANSWER$) <> "Y"
LOCATE 22, 63
GOSUB DesireCalculation
IF UCASE$(ANSWER$) = "Y" THEN
GOSUB PerformEURToUSD
END IF
LOOP
RETURN

' ***************** PERFORM EURO TO USD CALCULATION **************

PerformEURToUSD:
CLS
LOCATE 15, 21
PRINT "CONVERT EUROS TO U.S. DOLLARS"
LOCATE 20, 21
INPUT "ENTER EUROS AMOUNT ", EUR
LET USD = EUR * 1.28
LOCATE 22, 21
PRINT EUR; "EUROS EQUALS "; USD; "U.S. DOLLARS"
LOCATE 30, 21
INPUT "PRESS RETURN TO CONTINUE ", PAUSE$
RETURN

' ***************** CALCULATE U.S. DOLLARS TO BRITISH POUNDS **************

CalculateUSDToGBP:
CLS
LOCATE 20, 21
PRINT F3$
GOSUB DesireCalculation
IF UCASE$(ANSWER$) = "Y" THEN
GOSUB PerformUSDToGBP
END IF
RETURN

' ******************* PERFORM USD TO GBP CALCULATION ****************

PerformUSDToGBP:
CLS
LOCATE 15, 21
PRINT "CONVERT U.S. DOLLARS TO BRITISH POUNDS"
LOCATE 20, 21
INPUT "ENTER U.S. DOLLAR AMOUNT $", USD
LET GBP = USD * .63
LOCATE 22, 21
PRINT USD; "U.S. DOLLARS EQUALS "; GBP; "BRITISH POUNDS"
LOCATE 30, 21
INPUT "PRESS RETURN TO CONTINUE ", PAUSE$
RETURN

' ******************* DESIRE CALCULATION ************************


LOCATE 22, 15
PRINT "PERFORM A CALCULATION USING THIS FORMULA (Y/N)";
INPUT ANSWER$
DO WHILE UCASE$(ANSWER$) <> "N" AND UCASE$(ANSWER$) <> "Y"
LOCATE 22, 63
INPUT ANSWER$
LOOP
RETURN
' ************************** END OF PROGRAM ************************


How should I fix this problem?

Posted on Oct 29, 2012, 10:29 PM

Respond to this message   

Return to Index


Locate 26

by David (no login)

This is off the bottom of the screen. Hence the error.
Also it would probably be a good idea to set a screen mode at the top of your program.

Posted on Oct 30, 2012, 4:54 AM

Respond to this message   

Return to Index


Re: Locate 26

by Jay (no login)

That makes sense, How should I fix it?

Posted on Oct 30, 2012, 7:20 AM

Respond to this message   

Return to Index


Change the screen resolution

by Solitaire (Login Solitaire1)
S

Anything higher than LOCATE 24 in the default low-resolution screen will throw off your display or cause an error. The screen is only 40 across and 25 lines down. Without using LOCATE, anything you print after that will cause it to scroll.

You can change the screen size by issuing this command at the beginning:

WIDTH 80, 43

This will allow you to use LOCATE commands up to 42.

I ran your program using that command at the top and it's very impressive. Congratulations on a job well done!

Some comments:

Your code includes a lot of variable assignments using the obsolete LET keyword. I suggest you eliminate them. QB will work very well without them.

You did not declare any of the variables by type. Almost all modern programming languages require type declaration and I would advise you to do so as well.

If the user enters a non-numeric value, you will get a "Redo from start" error. You can avoid that by using a string input and converting it to a number with VAL(). For example:

DIM usds AS STRING
DIM USD AS DOUBLE
INPUT "Enter U.S. dollar amount $", usds$
USD = VAL(usds$)

If the entry is non-numeric, it will return 0 without an error. Or you can even catch the wrong user entry in an IF block, and put it in a subroutine for every instance of a number input:

IF VAL(usds$) = 0 THEN
'tell user to enter a valid amount
'etc
END IF

Also, it appears that you are shouting when you use all uppercase letters to address the user. Please use mixed cases.

Finally, you have a spelling error in your closing remark. You left out the "r" after "you" in "A penny for you thoughts"

Posted on Oct 30, 2012, 8:13 AM

Respond to this message   

Return to Index


Re: Change the screen resolution

by (no login)

I was able to get it to run! Thank you! It's actually a BASIC homework assignment but yes it is cool isn't it

Posted on Oct 30, 2012, 10:09 PM

Respond to this message   

Return to Index


Sketch

by Rick (no login)

Any ideas?

DEFINT A-Z

DECLARE SUB mouse (ax, mb, mx, my)

DIM SHARED m(11) AS LONG
m(0) = &H8BE58955
m(1) = &H48B0C76
m(2) = &H8B0A768B
m(3) = &H8768B1C
m(4) = &H768B0C8B
m(5) = &HCD148B06
m(6) = &HA768B33
m(7) = &H768B1C89
m(8) = &H8B0C8908
m(9) = &H14890676
m(10) = &H8CA5D

TYPE ptype
x AS INTEGER
y AS INTEGER
END TYPE

DIM p(1000) AS ptype
DIM mb, mx, my

SCREEN 9
mouse 1, mb, mx, my
DO
mouse 3, mb, mx, my

FOR j = 0 TO i
d = SQR((mx - p(j).x) ^ 2 + (my - p(j).y) ^ 2)
IF d <= 15 THEN mouse 4, 0, p(j).x, p(j).y
NEXT

IF mb = 1 THEN
DO
mouse 3, mb, mx, my
LOOP UNTIL mb = 0
p(i).x = mx
p(i).y = my
i = i + 1

k = k XOR 1
IF k = 0 THEN
LINE (0, 0)-(639, 349), 0, BF
FOR j = 0 TO i STEP 2
LINE (p(j).x, p(j).y)-(p(j + 1).x, p(j + 1).y)
NEXT
END IF
END IF

IF k = 1 THEN
mouse 3, mb, mx, my
LINE (p(i - 1).x, p(i - 1).y)-(mx, my)

IF ABS(my - p(i - 1).y) <= 15 THEN mouse 4, 0, mx, p(i - 1).y
IF ABS(mx - p(i - 1).x) <= 15 THEN mouse 4, 0, p(i - 1).x, my
END IF
LOOP UNTIL INP(&H60) = 1
SYSTEM

SUB mouse (ax, mb, mx, my)
DEF SEG = VARSEG(m(0))
CALL absolute(ax, mb, mx, my, VARPTR(m(0)))
END SUB

Posted on Oct 26, 2012, 5:50 PM

Respond to this message   

Return to Index


Doesn't seem like INT 33,4 works on qb64

by Ben (no login)

oh well. I wish this forum members all converted to freebasic

Posted on Oct 26, 2012, 9:51 PM

Respond to this message   

Return to Index


does Int 0x33 work in freebasic?

by (Login MCalkins)
Moderator

I'm assuming not, so, I take it that you mean that you wish the that source code were QB64 or FreeBASIC compatible. While I don't completely disagree with the sentiment, this is primarily a QBASIC forum. Yes, Int 0x33 for mouse access is obsolete, but, if you're still going to do it in QBASIC, then this is the proper forum in which to do it. (This forum allows QB64, but is mainly a QBASIC forum. In contrast, other forums might allow QBASIC, but be mainly QB64 or FreeBASIC.) If you want mouse access in QB64, there are better options, and I'm sure that the same goes for FreeBASIC.

While I personally have moved on to QB64 and C++, and rarely use QBASIC 1.1 any more, I recognize that there are still people who use QBASIC 1.1, and that it still has a few advantages over QB64. Even when QB64 fully catches up, QBASIC 1.1 will still have a few die hard fans, and I hope that this forum continues to stay open to them.

If anyone is still running pure DOS, QB64 is not currently an option. (I'm curious if there is any demand for a DOS port of QB64, or at least a subset...)

Regards,
Michael

Posted on Oct 26, 2012, 10:57 PM

Respond to this message   

Return to Index


Setting individual output bits

by Leon Schrecengost (no login)

How can I turn on/off each output bit?
I set output bit 1 by out 888,1
I set output bit 8 by out 888,8
How can I turn off bit 1 with out effecting bit 8?or any other bit.
out 888,0 resets all bits to 0
Leon

Posted on Oct 22, 2012, 5:34 AM

Respond to this message   

Return to Index


well, setting aside the hardware I/O...

by (Login MCalkins)
Moderator

I would recommend OR:

DIM n AS INTEGER
n = INP(888)
n = n OR &h81
OUT 888, n

Because &h81 is (2^7) OR (2^0), binary: 1000 0001. Since a byte doesn't have 9 bits, and numbering starts at 0, I assume you mean bits 0 and 7.

DIM n AS INTEGER
n = INP(888)
n = n AND &h7f OR &h40 XOR 4
OUT 888, n

should clear bit 7, set bit 6, and toggle bit 2. because it is:
'AND &h7f ' binary 0111 1111
''OR &h40 ' binary 0100 0000
'XOR &h04 ' binary 0000 0100

For operator precedence, see:
http://www.qb64.net/forum/index.php?topic=5990.0

However, I'm not experienced enough with hardware I/O to comment on that aspect.

Regards,
Michael

Posted on Oct 22, 2012, 6:22 AM

Respond to this message   

Return to Index


setting bits

by Leon Schrecengost (no login)

I will give it a try. Yes it's bit's 0 thru 7
Leon

Posted on Oct 22, 2012, 9:39 AM

Respond to this message   

Return to Index


Each bit is valued as 2 ^ bitnumber

by (Login burger2227)
R

Bit 0 on adds 2 ^ 0 = 1
Bit 1 on adds 2 ^ 1 = 2
Bit 2 on adds 2 ^ 2 = 4
Bit 3 on adds 2 ^ 3 = 8
Bit 4 = 16
Bit 5 = 32
Bit 6 = 64
Bit 7 = 128

All bits on adds up to 255

number AND 2 ^ 4 '= 16 if the bit is on. If off = 0
number OR 16 'turns bit on. If already on, it stays on
number XOR 16 'turns the bit off if on or on if off.

Posted on Oct 22, 2012, 12:35 PM

Respond to this message   

Return to Index


Setting bits

by Leon Schrecengost (no login)

I've tried several time to write a program to do this with little success.
This is what I would like to do

bit0on= (whatever code )
bit0off = (code)
bit1on =(code)
bit1off=(code)

for all bits without changing the other bits.
Leon

Posted on Oct 23, 2012, 6:06 AM

Respond to this message   

Return to Index


Re: Setting bits

by (Login MCalkins)
Moderator

n = n and &hfc '''''' clear bits 0 and 1
n = n and &hfe '''''' clear bit 0
n = n and &hfd '''''' clear bit 1
n = n and &hfd or 1 ' clear bit 1 and set bit 0
n = n and &hfe or 2 ' clear bit 0 and set bit 1
n = n or 1 '''''''''' set bit 0
n = n or 2 '''''''''' set bit 1
n = n or 3 '''''''''' set bits 0 and 1

&hfc is binary 1111 1100
&hfd is binary 1111 1101
&hfe is binary 1111 1110

Regards, Michael


Posted on Oct 23, 2012, 7:56 AM

Respond to this message   

Return to Index


Turning each bit on in sequence

by David (no login)

is that what you are trying to do?

n=0
n=n+1
out &h378,n 'bit zero on
n=n-1
n=n+2
out &h378,n 'bit one on
n=n-2
....
n=n+128
out &h378,n 'bit 7 on
n=n-128

I generally load up an array with all the bit arrangements I require for the output. This is particularly useful if you intend to use the control and status bytes of the port as some of the bit are not accessible or are inverted.

Posted on Oct 23, 2012, 8:29 AM

Respond to this message   

Return to Index


qbasic line numbers

by Leon Schrecengost (no login)

I've always used line numbers when programming in basic. I would like to learn how to write programs with out them. Does anyone know if there is a book or on line lessons on how to do this? I've looked at several but they just show example programs. I need to know the rules that apply. Most of the examples do not apply to what I want to do. In case you're woundering why I still do this I'm 72 and did not grow up using computers.

Leon

Posted on Nov 13, 2012, 7:38 AM

Respond to this message   

Return to Index


Re: qbasic line numbers

by AlGoreIthm (no login)

All you need to do is not use line numbers.
Try it with a short program. You will need a line number or a 'label' if you use GOTO or GOSUB. A label can be any word not used by QBasic, ending with a colon - it would look like this:

begin:

So instead of writing GOTO 1000 you would write GOTO begin

When you use GOTO with your label, the colon is omitted.

Posted on Nov 13, 2012, 8:30 AM

Respond to this message   

Return to Index


Line numbers

by Leon Schrecengost (no login)

Thank you I was trying to make a project out of it.
Leon

Posted on Nov 13, 2012, 11:15 AM

Respond to this message   

Return to Index


Line Numbers

by Leon Schrecengost (no login)

I tried some simple things and they worked. I'm having trouble converting the pgm I wrote with line numbers to one without.
What I did was write a program to set or turn off bits 0 thru 7 using the parrell port. Address 888. I used the keybord as the input. 1 would turn on bit 0 and a would turn it off. This worked fine using the line numbers.The following is a short sample of the pgm. The pgm would repeat for each bit number.I'm not sure how to handle the if then else statements with out line numbers.

CLS
locate 5,10:print "press 1 to set bit 0"
locate 7,10 : print"press a to turn bit 0 off"
locate 9,10 : press"0 to clear all bits"
out 888,0'sets all bits to 0
flag0=0'keeps track of what the bit is set at
startloop:
i$=inkey$
portstate%=inp(888)
If i$ ="1" andflag0=0 then outnum%=1:flag0=1
gosub outp
if i$ = "a" and flag0 =1 then outnum%=1:flag0=0
gosub outp
if i$ ="q" then end
if i$ ="0" then gosub clearoutput
goto startloop

outp:
portstate% = inp(888)
portnum% = portstate% + outnum%
out 888, portnum
return

clearoutput:
out 888,0
return

Posted on Nov 14, 2012, 8:18 AM

Respond to this message   

Return to Index


You're getting the idea

by AlGoreIthm (no login)


Your code works without line numbers.

I don't see the 'ELSE' you are referring to...?

I played with your code as a revised alternative
mostly the second subroutine is only one line long so it can be removed
and put inside the DO LOOP instead.

========================================================================

CLS

LOCATE 5, 10: PRINT "press 1 to set bit 0"
LOCATE 7, 10: PRINT "press a to turn bit 0 off"
LOCATE 9, 10: PRINT "press 0 to clear all bits"

OUT 888, 0'sets all bits to 0
flag0 = 0'keeps track of what the bit is set at

DO
i$ = INKEY$
portstate% = INP(888)
IF i$ = "1" AND flag0 = 0 THEN outnum% = 1: flag0 = 1
GOSUB outp
IF i$ = "a" AND flag0 = 1 THEN outnum% = 1: flag0 = 0
GOSUB outp
IF i$ = "0" THEN OUT 888, 0
LOOP UNTIL i$ = "q"
END

outp:
portstate% = INP(888)
portnum% = portstate% + outnum%
OUT 888, portnum
RETURN

Posted on Nov 14, 2012, 12:09 PM

Respond to this message   

Return to Index


You can simplify the concept.

by AlGoreIthm (no login)


Because a bit can only be 0 or 1, pressing the key of the corresponding bit can just flip 0 to 1 or vice-versa. Here, the array flag%( ) keeps track of the 8 bits' values, and they are shown when they change.

=============================================================================

CLS

LOCATE 5, 10: PRINT "press 0 to 7 to change the state of the bit"
LOCATE 7, 10: PRINT "press a to clear all bits"
LOCATE 9, 10: PRINT "press q to quit"

OUT 888, 0'sets all bits to 0
' flag array = keeps track of what each bit is set at

DIM flag%(0 TO 7)

DO
i$ = INKEY$
portstate% = INP(888)

outnum% = 0
IF i$ >= "0" AND i$ <= "7" THEN
outnum% = 1
flag%(VAL(i$)) = 1 - flag%(VAL(i$))
portstate% = INP(888)
portnum% = portstate% + outnum%
OUT 888, portnum
END IF

IF i$ = "a" THEN
OUT 888, 0
FOR l% = 0 TO 7
flag%(l%) = 0
NEXT
END IF

FOR l% = 0 TO 7
LOCATE 13 + l%, 2
PRINT l%; flag%(l%)
NEXT

LOOP UNTIL i$ = "q"

END

Posted on Nov 14, 2012, 2:27 PM

Respond to this message   

Return to Index


simplfy

by Leon Schrecengost (no login)

I tried the program you sent last time. I ran into a problem. When I start the pgm it runs the subroutine before pressing 1. I added one line in the subroutine to debug I added print "txt" it prints as soon as the program starts.I have 8 leds on the output to see what happens. Pressing 1 turns on all bits. a does nothing. Any thoughts?They do all go to 0 on start up.
I'll try the new program tomorrow and let you know if it works.
Thanks for the help
Leon

Posted on Nov 14, 2012, 5:09 PM

Respond to this message   

Return to Index


found problem

by Leon Schrecengost (no login)

The problem is that when the if statement is not satisfied it goes to the next line which is the gosub. I'm going to try puting the gosub at the end of the if statement line. If that does not work can the else statement be used to skip the gosub and go to the next if statement? If else is used how do I identify the line with out a line number?
Leon

Posted on Nov 15, 2012, 2:16 PM

Respond to this message   

Return to Index


Please post the code you are using now

by AlGoreIthm (no login)

It's impossible to determine these details without seeing the actual program.

Posted on Nov 16, 2012, 6:10 AM

Respond to this message   

Return to Index

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement