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



Create sequential data file

by basicstudent (no login)

I am not sure why my program is not running correctly. This is the question: Write two programs: one to create a sequential data file, and the second to read the file and calculate commission amounts.

Input: Input from the keyboard the salesperson's number, name, commission rate, and amount of sales.

Output: Create a sequential file that contains all input data.

Program 2

Input: Theinput data will be the sequential file created in the first program. Input fields are the salesperson's number, name, commission rate, and amount of sales.
Output: Print a report with a title and column headings. One detail line will be printed for each salesperson (each input record). The fields on the detail line are to be the salesperson's number, name, sales amount, commission rate, and amount of sales.


Output: Print a report with a title and column headings. One detail line will be printed for each salesperson (each input record). The fields on the detail line are to be the salesperson's number, name, sales amount, commission rate, and commission amount.

Calculations: Compute the commission amount as the sales amount multiplied by the commission rate.

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

Posted on Jul 26, 2014, 9:34 PM

Respond to this message   

Return to Index


Re: Create sequential data file

by Pete (Login The-Universe)
Admin

You need to include the PrintReport as part of your main program. Right now, it isn't being called at all.

I switched your order in the PrintReport. You have to INPUT first, then print, Also, you are printing to the screen, not the file again, which wouldn't work anyway, as the file is open for input, not read and write, and it is sequential, not binary.


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

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

Anyway, just some casual observations, I did not try to run the code.

Pete

Posted on Jul 27, 2014, 12:17 AM

Respond to this message   

Return to Index


read data single dimension arrays

by best (no login)

Write a program using single dimension arrays to analyze and income survey. The Statistics for each home include an identification code, the number of members in the household, and the yearly income. I want to make sure I did this right

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 Jul 26, 2014, 9:22 PM

Respond to this message   

Return to Index


For/next loop

by newbie (no login)

For this homework, I have to use a FOR/NEXT loop to total numbers from 1 through 100. Print the numbers on the screen.
This is what I did. Is this correct?
REM ***** USING FOR-NEXT*********
CLS
FOR A = 1 TO 100
PRINT A
NEXT A

Posted on Jul 26, 2014, 7:52 PM

Respond to this message   

Return to Index


Re: For/next loop

by SMcNeill (no login)

Half there. You've printed the numbers, but where's the total of them? You still need to keep a running total and display it as you go.

Posted on Jul 26, 2014, 8:26 PM

Respond to this message   

Return to Index


Total not shown

by Solitaire (Login Solitaire1)
S

You printed the numbers, but haven't totaled them.
Use an accumulator variable for the total. Initialize it to 0 before starting the loop. Inside the loop, assign the previous total to itself and add on the current number. Then print the value of the accumulator.

Posted on Jul 27, 2014, 9:46 AM

Respond to this message   

Return to Index


QBasic on Android

by Pete (Login The-Universe)
Admin

For those who don't mind running their QB apps in DOSBox, it is worth noting that there is an aDOSBox version out, that will run your QB programs on an Android device.

I anticipate experimenting with some mobile apps, soon, and converting some to an appropriate language for Android, but it will be nice to make an install of aDOSBox to test what I rewrite against what already will run on an emulator.

Pete

Posted on Jul 24, 2014, 6:43 AM

Respond to this message   

Return to Index


Re: QBasic on Android

by Jim (no login)

Do you think QBasic on Android is worth it? An android mobile computer seems quite different from a IBM personal computer of sort. Perhaps a sewing machine for a glass sculpture.

Posted on Jul 24, 2014, 9:36 PM

Respond to this message   

Return to Index


Re: QBasic on Android

by SMcNeill (Login SMcNeill)
R

I've been thinking on this as well. Exactly how well would most QBasic programs port over to a mobile device?

How does QB handle device rotation?
How about a 2 finger pinch to zoom?
Or a 3 finger swipe to switch apps?
Will font sizes be readable? If you write a program for a tablet, will the fonts remain readable for a phone?
Will input on the device be worthwhile? A lot of QB programs deal with text, and text entry is a PITA for most tablets.
And most importantly, is there an existing app that was created already under a different platform that would be able to do what you need, and do it better?

Personally, I don't see what the big deal is with wanting to use QBasic to make mobile apps. It seems to me that any project completed would look and feel half-assed no matter what, and wouldn't be suitable for any commercial products. And if I don't need an app for a commercial product, I find that writing it for my PC and then simply using my tablet to remote desktop connect and run it is more than sufficient for my needs.

I hope someone out there can prove me wrong and show us a working example of something amazing that was written in BASIC and ran on a mobile device, but I really think just about anything wrote in QBasic-type languages is going to be a hackjob at best.

Posted on Jul 25, 2014, 3:41 AM

Respond to this message   

Return to Index


Sure it will be if you do it! *

by Clippy (Login burger2227)
R

Posted on Jul 25, 2014, 8:03 AM

Respond to this message   

Return to Index


Valid points Steve, however...

by TheBOB (Login qb432l)
R

...since when has QBasic programming ever been valued for its practical or commercial potential? I'm thinking that Pete probably wants to write simple programs that keep track of his son's progress in golf and the like. Plus, it would be just plain fun.

-Bob

Posted on Jul 25, 2014, 9:10 AM

Respond to this message   

Return to Index


Bob nailed it. QB64'ers are also getting it bassackwards.

by Pete (Login The-Universe)
Admin

Bob BASICally has what I'm getting at figured out.

You guys are too worried about the project being a "toy" language. I successfully used that toy language to run a profession. So know you want to make it a professional language, and for what? To make toys!

Take a lesson from PowerBasic. They made a version for DOS that is very QBasic compatible, but then designed something pretty foreign to QB, called PowerBasic for Windows. Port some OOP up that version, and people like me won't care. They also have two discussion forums, so people who don't want to do the Windows version can still be expert helpers in the DOS version.

In the time it would take QB64 to be what I see posted its futures list, I could learn Python, and already have everything I want running. There is no innovation here. You are now at the point of creating a bloated translator, that doesn't accomplish anything new, and by the time it is near ready, will probably be lagging behind whatever else develops over the next 5 years. That is not professional, that's called a hobby, still.

Now if yo do get other developers on board, you can make a clear cut path forward, and keep everybody on that path to completion, you actually do stand a chance of this working out as a community project, and good for you if that becomes the new reality. If not, you are following someone's personal project. Unfortunately, I believe to get others involved will take cleaning up and organizing the source code a ton, and that will take a fair amount of time, too.

Pete



    
This message has been edited by The-Universe on Jul 25, 2014 9:56 AM
This message has been edited by The-Universe on Jul 25, 2014 9:42 AM

Posted on Jul 25, 2014, 9:36 AM

Respond to this message   

Return to Index


* Well at least your Android journey has not gone too far away...

by Clippy (Login burger2227)
R

[linked image]

Posted on Jul 25, 2014, 10:57 AM

Respond to this message   

Return to Index


Read Data Statement is not working

by Benjamin (no login)

I wrote a program to list the best colleges for a particular major where the user must select a particular are of study and a list of colleges must appear. I have to use Data statements to show the list's of colleges, but for some reason its not working out. Please help.

My Program:

CLS
'********** Program to find Best Colleges **********
' Variables
' Choice, Selection
' Nam$ Names of colleges

'**********Program Mainline **********

DO
GOSUB DisplayMainMenu
PRINT
PRINT
PRINT TAB(16); "Enter Choice";
INPUT Choice

SELECT CASE Choice
CASE 1
GOSUB FirstItem
CASE 2
GOSUB SecondItem
CASE 3
GOSUB ThirdItem
CASE 4
GOSUB FourthItem
END SELECT
LOOP UNTIL Choice = 5 '5 is ending value
PRINT "End of Program"
END


'********** Display Main Menu **********
DisplayMainMenu:
PRINT
PRINT
PRINT
PRINT TAB(25); "Best colleges for majors in"
PRINT
PRINT
PRINT TAB(20); "1. Computer Information Systems"
PRINT TAB(20); "2. Computer programming"
PRINT TAB(20); "3. Business Economics"
PRINT TAB(20); "4. Photography"
PRINT TAB(20); "5. Quit"
PRINT
RETURN

'********** Initialize Choices **********
FirstItem:
READ NAM$
DATA 1. COMPUTER INFORMATION SYSTEMS
DATA a. College of Technology
DATA b. Computer Tech College
DATA c. Technical College of Illinois
DATA d. Marshall University
DATA End
INPUT "Enter to continue", E$
RETURN

SecondItem:
READ NAM$
DATA 2. COMPUTER PROGRAMMING
DATA a. Technical College of Dupage
DATA b. IT Tech College
DATA c. University of Illinois
DATA d. Kalgon University
DATA End
INPUT "Enter to continue", E$
RETURN

ThirdItem:
READ NAM$
DATA 3. BUSINESS ECONOMICS
DATA a. College of Dupage
DATA b. Berkshire College
DATA c. University of Illinois
DATA d. Kelvin University
DATA End
INPUT "Enter to continue", E$
RETURN

FourthItem:
READ NAM$
DATA 4. PHOTOGRAPHY
DATA a. Art Institute of Dupage
DATA b. Harrison College
DATA c. Art College of Illinois
DATA d. University of Akron
DATA End
INPUT "Enter to continue", E$
RETURN

Thanks

Posted on Jul 22, 2014, 8:19 PM

Respond to this message   

Return to Index


you need to call read in a loop

by qbguy (no login)

For firstitem:


firstitem:
RESTORE firstitem:
nam$ = ""
DO
PRINT nam$
READ nam$
LOOP WHILE nam$ <> "End"
DATA 1. COMPUTER INFORMATION SYSTEMS
DATA a. College of Technology
DATA b. Computer Tech College
DATA c. Technical College of Illinois
DATA d. Marshall University
DATA End
INPUT "Enter to continue", E$
RETURN

and the other items are similar

Posted on Jul 22, 2014, 9:06 PM

Respond to this message   

Return to Index


Scheme interpreter

by qbguy (no login)

http://www.network54.com/Forum/190883/message/1406081532/Scheme+Interpreter

This code runs a Scheme interpreter. The environment is initially EMPTY -- no functions are included, not even arithmetic and CONS, so it is not very useful, but arithmetic and list functions should be easy to add.

Example: at the prompt, type

(define twentyseven 27)

This defines the variable twentyseven to be 27. If you type twentyseven, you get 27, since that is the value of the variable twentyseven.

Since functions are first-class objects, you can do some interesting things. For example, you can define pairs yourself:

(define cons (lambda (x y) (lambda (f) (f x y))))

(define car (lambda (n) (n (lambda (x y) x))))

(define cdr (lambda (n) (n (lambda (x y) y))))

CONS creates an ordered pair object; CAR takes the first element, CDR takes the second element.

Posted on Jul 22, 2014, 7:32 PM

Respond to this message   

Return to Index


Updated version

by qbguy (no login)

http://pastebin.com/fQaZG4Ze

I added the functions +, *, CAR, CDR, CONS to the interpreter as primitive functions.

Posted on Jul 22, 2014, 7:53 PM

Respond to this message   

Return to Index


Updated version

by qbguy (no login)

So it turns out that you can make programs that work in FreeBASIC (-lang qb) but not QB64

differences:

- line numbers / labels in QBASIC are NOT per FUNCTION / subroutine
- you can NOT put parenthesis when using a function that takes no arguments

So I fixed it:

http://www.network54.com/Forum/190883/message/1406154984/Update+2

Posted on Jul 23, 2014, 3:40 PM

Respond to this message   

Return to Index


Advice to Students: Subs and variables

by Solitaire (Login Solitaire1)
S

Question: Why do we need subs?
Answer: 1) Reusable code and
2) Separating large programs into manageable units

We certainly don't need subs the way I've seen student assignments that were posted here. I understand that the simple assignments were used just for students to learn the syntax for starting and ending a sub. But you also need to understand the reason for doing it.

The main purpose of a sub is that it is reusable. It's meant to save having to repeat the same group of instructions several times during the course of a large program. So a sub is useful when it is called more than once. This is not the same as a loop which keeps repeating. A sub can be called from different parts of a program.

Think of a real-life example for building a house. After putting up the outside wall, you need to add the windows (or doors). Each window is identical. The "code" for each window is the same, but it needs to be placed in different parts of the wall. When you come to an opening in the wall for a window, you can then call the sub for placing a window in that location, using the same code.

In a computer program, when you come to the part that requires code that would need to be repeated elsewhere, it is more efficient to call a sub. That way you only need to write the code once, and it is easier to debug it once when needed, instead of searching for the same code elsewhere in your program and making mistakes.

Another purpose of using a sub is to separate parts of a larger program and make it more manageable. When working with a team of programmers, each person would be assigned a different part of the program to develop.

The difference between a subroutine (using GOSUB) and a subprocedure (using the optional CALL keyword) is that with GOSUB, all the variables used in the main program are recognized by the code in all the subs and vice versa. This may work for a small program used by a single person. But for a larger program, it is very error prone and can be difficult to debug.

When you have a team of programmers, each should be able to use his/her own variables without interfering with those used by other members of the team. This is why subprocedures are preferred. Each sub is isolated from the rest of the program and the variables used are local to that subprocedure. If you need to share the variables, they can be passed via arguments and parameters, or by using the SHARED keyword. Alternatively, function procedures can be used to return values.

The use of subprocedures or function procedures with arguments & parameters is a more advanced topic for beginning students. Check out the QB Help file for some basic information.

More important, it is necessary to understand how to declare variables by type using the DIM keyword, and this should be done early in your programming experience. Variable declarations should be placed at the beginning of your code for every program. If your instructor hasn't done so, you should urge him to introduce this topic right away.

Your instructor may be using an outmoded textbook. For example, the LET keyword is obsolete and isn't needed. Encourage your instructor to teach outside of the textbook or skip around to the chapter that introduces the DIM keyword with variable declaration. This is especially important if you are serious about programming and intend to use a different programming language (such as C++ or Java) later on, where variable type declaration is required.

Good luck and happy programming!




    
This message has been edited by Solitaire1 on Jul 21, 2014 10:47 AM

Posted on Jul 21, 2014, 10:39 AM

Respond to this message   

Return to Index


Nice, clear explanation, Solitaire...

by TheBOB (Login qb432l)
R

Regarding instructors teaching outside the textbook, I wonder sometimes--seeing the kind of work these students are assigned--if the teachers have more than a rudimentary knowledge of programming themselves. The "LET" example seems to indicate this.

Naturally, if we're talking about a computer science teacher at a university level, they would be well qualified, but isn't computer science at a high school level really just an aspect of math class?

-Bob

Posted on Jul 21, 2014, 7:51 PM

Respond to this message   

Return to Index


* Thanks for the positive comment, Bob.

by Solitaire (Login Solitaire1)
S

Posted on Jul 21, 2014, 11:35 PM

Respond to this message   

Return to Index


Pros and Cons...

by Pete (Login The-Universe)
Admin

Students who are taking BASIC as an intro course to other languages should be taught that BASIC allows for a lot of shortcuts not possible when programming in most other languages. Students just wishing to learn BASIC, on the other hand,should be taught the shortcuts are great productivity tools for writing fast efficient applications.

Solitaire really needed to make her post 10 years ago, so Galleon could have seen it. QB64 is an example of writing quick code that doesn't have the structure for team development. Big projects usually require team development to get anywhere fast enough to amount to any meaningful good in this industry. Could you imagine a single developer trying to make FireFox? It would probably be called SmolderFox and so far behind the competition that the only one running it would be the developer, and if he needed any help, he would probably have to install Opera to Google it.

So yes, very good read for students looking to go from BASIC to other more industry used languages. I always stated the smartest thing QB64 did was translate BASIC to C/C++ as I believed those would be two very long-lived stable languages, and so far, I've been correct in my assessment.

Pete

- QB64 Procedural = QB64Pro. QB64 Object Oriented Programming System = QB64Oops



Posted on Jul 23, 2014, 11:16 PM

Respond to this message   

Return to Index


I'm no longer associating with QB64

by Pete (Login The-Universe)
Admin

The QB64 SDL release, which isn't finished, Galleon's trade mark, apparently, is really good, but no longer supported. Instead, the project moved to Glut, which after about 2 years still is not up to where SDL left off. The project did have Android support, if you could call a toothpick under a Mercedes support. Apparently only Hello World works on it, on odd numbered Tuesdays, if you run it somewhere off the coast of Kentucky.

Anyway, lack of developing a real mobile platform in favor of Glut was bad enough, but coupled with that is talk of adding OOP to the project. Anyone remember RealBASIC? probably not. It had OP and was a colossal failure. Dragged and dropped right of the face of the Internet. BASIC was never meant to be OOP in nature, period.

So my rant about keeping BASIC BASIC, from over 10 years ago seems to be lost on the present state of mind of the developer. QB64 is his brainchild, and he can do exactly as he likes with it, but I don't have to endure the ride the rest of the way. Something is pretty odd, anyway, when he tells the community he is developing QB64 as a tool for him to make applications. He can already program in C/C++, so why would anyone who could do that take the extra time to develop a way to translate BASIC to what you could already code more efficiently in C/C++? My hunch is this is like some OCD disorder, and he just can't call it quits after achieving a 95+ percent compatibility with QuickBASIC. I mean that was a pretty amazing achievement, even without an interpreter. Wow, that reminds me how nice it would have been to stop making all those additional keywords, and instead developed an interpreter. The ability to debug code fast was lost on that project. Slow IDE, no interpreter, and now no appreciable support for mobile. sad.gif

I still endorse the SDL QB64 version as the best QB clone for modern operating systems.

If you want QuickBASIC to run on an Android, you can get the aDOSBox app to do it. Isn't that ironic?

PowerBASIC and FreeBASIC won't be seeing mobile anytime, soon. Their structure makes that move pretty difficult.

Thankfully, I found an Android development language that I think I like. Worth a try, and it isn't OOP. Hopefully not too difficult to convert my QB stuff to.

Pete









Posted on Jul 20, 2014, 11:20 PM

Respond to this message   

Return to Index


Re: I'm no longer associating with QB64

by Michael Calkins (Login MCalkins)
Moderator

It is/was a big project for mainly one unpaid person. He certainly accomplished a lot.

I think that most of us would wish that we had more time to devote to our pet projects. But it's a question of time and priorities.

I know that several qualified people have started interpreter and/or debugger projects, and most of them would be capable of finishing them with infinite time and motivation. I know that I could write an interpreter, and part of me wants to, but I just don't have the time. There are other things more important in my life.

In a language like C++, the object oriented stuff is optional. It's there if you want it, but the language lets you choose whether to use it or not. You can even use a mix of procedural and OOP style.

Regards,
Michael

Posted on Jul 21, 2014, 12:31 AM

Respond to this message   

Return to Index


OOP killed the QBasic Star

by Pete (Login The-Universe)
Admin

Actually, a great line stolen from mennonite when he posted FreeBasic Killed the QBasic Star. Parody on music video called Video Killed the Radio Star.

Have a look at BASIC4Android. So OOP ridden that the only thing BASIC about it is the first 5 letters of its name. OOP takes over, and attracts people who are not in the least bit procedural coders.

Somewhere around my last birthday, I quit cutting people slack, or maybe better put, started reducing my tolerance level. I think they call it becoming set in your ways, anyway, it's a new life experience, and one I'm learning to appreciate. Maybe it has something to do with at my age you realize you don't have infinite time anymore. You can still want everything, but that's called a pipe dream. QB64 has become a disorganized pipe dream. It was supposed to be QB for modern operating systems. It lacks an interpreter, it is just a crappy IDE and a compiler. The QB IDE is superior. But with some modifications, and a lot of work if you made multi-modular programs, which QB64 does not support, you can convert your complex QB programs. That is a milestone, and a stunning achievement.

I'll probably rant for a couple of days about it, just because I'm upset with myself for not jumping ship sooner. The signs were all there. Galleon quits his part time job (teacher) and goes to work in private sector. That is a tell, as teaching gives you lots of time to devote to hobbies, but a new job in the private sector chews away most of your time. The SDL the original QB64 uses works fine, compiles faster, and works on Android, now has hardware acceleration capabilities, etc., but the project jumps to OpenGL. Contradictions began to multiply. The developer considers it a toy language, which must go forward to become a professional language. The problem is his coding style is a toy coding style. King of GOTO, as it turns out. Poorly described variables. I never went GOTO happy, but to save space, I would use those single letter variables, a lot. Just wrote a variable table. Anyway, the point is, most people who could help the project take a look at the code and RUN. But that's OK, it's just for him, but he needs others, or does he? Grrrr. There isn't infinite time, so all these contrary issues just bottleneck the project. Same with what is left of the community. No rules, people claim to want moderation, but they don't report posts. Rules are needed for that, but half of them don't want rules. They claim to be able to take a few shots, but then want something done about it. Yes Steve, I'm thinking of you here. Galleon wants a forum, but doesn't want the responsibility of a forum, because it takes time away from the project. Again, a disorganized mess. And the final straw, of course, I found myself in agreement with Clippy on the Android issue. I'm starting therapy for that, tomorrow.

You've contributed a lot over the years to BASIC, Michale, so don't beat yourself up over not taking on a marathon project like an interpreter, especially for a yank you around language like QB64 has turned into. Programming is great, but it is like an obsession, which can rob you of your life if you are not careful. The industry changes so fast, even your greatest accomplishments can become yesterdays news.

Pete

Posted on Jul 21, 2014, 8:59 AM

Respond to this message   

Return to Index


Re: OOP killed the QBasic Star

by SMcNeill (Login SMcNeill)
R

"They claim to be able to take a few shots, but then want something done about it. Yes Steve, I'm thinking of you here."

I tend to take everything that's tossed at me personally, as I just ignore it. Where I have issues is when it comes to the people who can't handle it being baited back and forth, and then spilling over into everything else. Such as the whole silly mess with Hacker saying "I'm leaving" and Clippy just pushing his buttons to harass him. It's those cases where moderation was needed, and honestly Galleon never really gave you the authority to actually do anything. What exactly could you do? Edit a post? Maybe delete one? You couldn't move them if they needed to go elsewhere. You couldn't actually tell anyone to stop doing what they were doing -- or else what?? You'd send them a strongly worded message to quit? :P

I can absolutely understand your frustration, but to jump ship over something that hasn't even happened yet? And may never happen? You've been on a rant about OOP being added, but why now? Galleon mentioned that it was his goal to add OOP functionality a long time ago. Here's a post about it over a month ago which clearly says that's one of his goals for the future of QB64:http://www.qb64.net/forum/index.php?topic=11941.msg103254#msg103254 (And I think it was mentioned well before that, but I'm lazy and don't want to try and dig through the posts to see when it was first mentioned.)

"My goal is to implement things like OOP and variable references then use these to improve other areas of QB64 source code."

Like a lot of goals Galleon sets, I don't know if they'll ever bare fruit. He works on the project on a current-needs priority system, and focuses on the things he needs added into it for whatever he's currently working on. OOP is one of those things that can help make coding easier, but it also often can be worked around. If he can work around without it, by his usual coding style I don't think it's going to be something we see added anytime soon.

As far as SDL being better, the question remains: WHY??

We've finally begun to sort out how to add things ourselves and help expand the language, and here in the last month or so we've came a long ways towards fixing all the SDL-incompatibilities. Add in hardware acceleration for images and now _MAPTRIANGLE (which is used for rotations and movements a lot), and GL has now unlocked new potential benefits that far surpass SDL's capabilities. Of course, you only need SCREEN 0 for yourself, but for the rest of us it's a big deal. happy.gif

What is it about SDL that makes you think it's a better tool? You have to include all the library files if you ever want to share something you write. You'll never have hardware acceleration, or access to the new commands. (I try and add what I can if you grab the versions I put up so that code will stay relevant between the versions as much as possible, but some things are GL/glut/GL-library dependent and don't port over.) SDL does a good job of letting you run the same code you ran back in 1995, but it lacks a lot of the things which are nice here 20 years later. The _MEM system isn't half developed, and ANYTHING added after that time isn't "officially" supported.

It's going the way of the dinosaur, and it gets a little more out of date all the time. What is it that has you hanging onto it and not making the switch over to GL?

Posted on Jul 21, 2014, 11:13 AM

Respond to this message   

Return to Index


Two things I am wondering about Pete.

by Clippy (Login burger2227)
R

1) What coast of Kentucky?

2) How do teachers have any more FREE TIME to do projects than anybody else? Seems like typical conservative clap trap!

Posted on Jul 21, 2014, 11:40 AM

Respond to this message   

Return to Index


*Maybe during summer vacation.

by Michael Calkins (Login MCalkins)
Moderator

Posted on Jul 21, 2014, 4:28 PM

Respond to this message   

Return to Index


And while they are vacationing off the coast of Kentucky.

by Pete (Login The-Universe)
Admin

Nice job of humor by pointing out the obvious.

Pete happy.gif



    
This message has been edited by The-Universe on Jul 22, 2014 3:08 AM

Posted on Jul 21, 2014, 4:56 PM

Respond to this message   

Return to Index


Small Problem

by BWare (no login)

I wrote this program that allows you to convert currency. The program looks and works well but I am having a small problem getting the main screen to re-appear after the converted currency is displayed. Please help!

My Program-

'********** Program to covert currency **********
' Variables
' Choice, Selection

'**********Program Mainline **********

GOSUB DisplayMainMenu
PRINT
PRINT
PRINT TAB(16); "Enter Choice";
INPUT Choice

DO
SELECT CASE Choice
CASE 1
GOSUB FirstItem
CASE 2
GOSUB SecondItem
CASE 3
GOSUB ThirdItem
CASE 4
GOSUB FourthItem
END SELECT
LOOP UNTIL Choice = 5 '5 is ending value
PRINT "End of Program"

'********** Display Main Menu **********
DisplayMainMenu:
PRINT
PRINT
PRINT
PRINT TAB(35); "Convert Currency"
PRINT
PRINT
PRINT TAB(20); "1. Convert U.S. dollars to British pounds"
PRINT TAB(20); "2. Convert British Pounds to U.S. dollars"
PRINT TAB(20); "3. Convert U.S. dollars to Canadian dollars"
PRINT TAB(20); "4. Convert Canadian dollars to U.S. dollars"
PRINT TAB(20); "5. End the program"
PRINT
RETURN

'********** Initialize Choices **********
FirstItem:
CLS
INPUT "Enter U.S.dollars"; US
Brit = US * 1.1330
PRINT "The amount is"; Brit
END
RETURN

SecondItem:
CLS
INPUT "Enter British pounds"; Brit
US = Brit * .8826
PRINT "The amount is"; US
END
RETURN

ThirdItem:
CLS
INPUT "Enter U.S.dollars"; US
Can = US * .7531
PRINT "The amount is"; Can
END
RETURN

FourthItem:
CLS
INPUT "Enter Canadian dollars"; Can
US = Can * 1.3277
PRINT "The amount is"; US
END
RETURN

Thanks,
BWare

Posted on Jul 20, 2014, 5:01 PM

Respond to this message   

Return to Index


Fix your code

by Solitaire (Login Solitaire1)
S

May I suggest:

Place CLS at the top of your program to clear the screen.

Put the DO loop just before GOSUB DisplayMainMenu and remove the one after INPUT Choice.

You only need one END and it should be placed after the LOOP ends, right after you PRINT "End of Program"

Remove the rest of the ENDs in the subs, and replace them with an input to keep the screen display until the user presses a key to continue. For example:
INPUT "Enter to continue", E$

Posted on Jul 20, 2014, 6:18 PM

Respond to this message   

Return to Index


Thanks

by BWare (no login)

That worked out fine.

Posted on Jul 20, 2014, 7:04 PM

Respond to this message   

Return to Index


* Yea! Actual no-nonsense BASIC programming. Ah, I feel better now!

by Pete (Login The-Universe)
Admin



    
This message has been edited by The-Universe on Jul 20, 2014 9:38 PM

Posted on Jul 20, 2014, 9:05 PM

Respond to this message   

Return to Index


Thanks to the mods and those who post here...

by Pete (Login The-Universe)
Admin

I may be going away for awhile. No, the guys in the little white coats haven't caught up with me yet, but I ma going to be spending some of the time I don't have looking into a mobile BASIC language I discovered online.

As for the forum, mods, you are doing a great job. I see we still get the occasional QBasic help requests, and some interesting topics for discussion, as well as the free for all in the Community Discussion Forum, which I hope everyone appreciates, because I have every intention of keeping it up, even though some of the time people don't completely get along. :P

I have to admit I am loosing some interest in QB64. It seems to be going off in a more and more non-BASIC direction. I enjoy procedural coding, and I think that's what I will look for when I look into mobile applications.

I will certainly be reachable if anyone needs me for anything that cannot be handled or addressed without my consent, I just cannot, or maybe just don't want to imagine what that would be. As far as posts deleted, edited, and advice goes, all the mods have done a great job, and I greatly appreciate each of you taking your time for the sake of this community. This place is a true historic time line of BASIC programming.

- Pete

Posted on Jul 19, 2014, 11:06 PM

Respond to this message   

Return to Index


Let us know how it works out.

by Clippy (no login)

For some reason I will miss you... :-)

Posted on Jul 20, 2014, 6:22 AM

Respond to this message   

Return to Index


REMLINE.BAS : the program that wouldn't die

by billy gates (no login)

The Program That Wouldn’t Die

Bruce: As you know, this is my first work as a professional programmer—although at this point I’m only a sample programmer. This is also my introduction to parsing. I was assigned to fix REMLINE.BAS as a sample program for QuickBasic.

Joe: What the heck is a sample programmer?

Bruce: Well, there are real programmers, and there are sample programmers. I’m just a sample.

Mary: Bruce has been hired by the documentation department as a programmer. In the past, all the sample programs in the manuals and on the disk have been just thrown together by whoever happened to have time. Coding style and quality varied a lot. Bruce’s job is to make all the samples use a consistent style and have consistent quality.

Joe: Well, if he works for documentation, why don’t the documenters review his code?

Mary: We thought it’d be good experience for him to have his code reviewed by programmers from Basic development. A sort of baptism by fire.

Jane: It might also be nice for C programmers writing the Basic language to see what it’s like in the trenches. How long has it been since you tried to write serious code in Basic?

Joe: Serious code in Basic? Hmph! Can’t be done.

Bruce: We’ll see. Back to REMLINE. I didn’t write it, and I don’t know the original author. The version I got was lightly commented, had a clumsy user interface, didn’t take full advantage of new Basic features, and had undocumented limitations that some people might call design bugs. My job was to clean up this private code for public consumption.

Joe: So this isn’t even your code?

Bruce: Well, what we’re going to talk about today is mine. I revised it heavily, and I take responsibility for it. Now, the purpose of REMLINE is to remove all unnecessary line numbers from GW-BASIC and BASICA programs so that they look semi-structured. In theory, you can then go through and change the remaining line numbers to labels as a first step toward making the code readable by humans as well as by modern versions of Basic.

Joe: You’re better off just throwing away your BASICA code and starting over from scratch.

Jane: Oh, sure! That’s a good marketing line. Put that on the box. "QuickBASIC: Now you can rewrite all your old code."

Bruce: When I started on REMLINE, I thought it was a pretty cool program, and I had all kinds of ideas for making it even cooler. Now I tend to agree with Joe. Dump your BASICA code in the trash. In any case, we’re not reviewing REMLINE; we’re reviewing the parsing code in it.

REMLINE is a very simple compiler that tokenizes a source file. It recognizes certain Basic keywords associated with line numbers—Goto, Gosub, Then, Else—and indexes each one with its target line number. When it’s finished indexing, it strips out all the line numbers that haven’t been targeted by a keyword. A good portion of the code deals with tokenizing keywords, variables, and line numbers. REMLINE does this with imitations of the C parsing functions strtok, strspn, and strcspn.

Joe: This is crazy. I don’t have time to review sample code that no one will see. Even if you ship this crap, no one will pay any attention to it, and you won’t bother to ship it with the next version.

Mary: You don’t have to like this assignment, but you do have to do it. Try to have a positive attitude.

StrSpan and StrBreak

Bruce: In C, the basic building blocks of parsing are strspn and strcspn. My Basic names for them are StrSpan and StrBreak. To use StrSpan, you pass it the string you want to parse and a list of separator characters—space, tab, and comma—and line-break characters if the string can span multiple lines. StrSpan returns the position of the first character that is not a separator. You pass StrBreak the same arguments, and it returns the position of the first character that is a separator.

You can probably guess how to use these functions. Find the start of a token with StrSpan, find the end of the token with StrBreak, cut out the token, find the start of a token with StrSpan, find the end of the token with StrBreak…and so on to the end of the string. That’s pretty much what GetToken does, but first let’s take a look at StrSpan:

Function StrSpan1(sTarget As String, sSeps As String) As Integer

Dim cTarget As Integer, iStart As Integer
cTarget = Len(sTarget)
iStart = 1
' Look for start of token (character that isn’t a separator)
Do While InStr(sSeps, Mid$(sTarget, iStart, 1))
If iStart > cTarget Then
StrSpan1 = 0
Exit Function
Else
iStart = iStart + 1
End If
Loop
StrSpan1 = iStart

End Function
StrBreak is identical except that the loop test is reversed:

' Look for end of token (first character that is a separator)
Do While InStr(sSeps, Mid$(sTarget, iStart, 1)) = 0

Joe: If they’re identical except for one line, why have two functions? Why not have one function—say, StrScan—with a flag argument that can be either Span or Break? Put the loop test in a conditional. That should save some code.

Jane: Yeah, but at what cost? You might loop through these functions hundreds of times if you’re parsing a big file. Is the size cost of duplicating tiny functions worth the cost of adding an extra test in a loop that will be called in a loop? Besides, the interface feels better with separate functions.

Joe: I don’t care what "feels" better, but I guess I’ll buy your performance argument. Let’s stick with two functions.

Mary: Any other comments?

Jane: The length cTarget is calculated just once, outside the loop. That’s good. The body of the loop looks pretty clean. The loop test with Mid$ called inside InStr looks messy.

Joe: It’s taking one character at a time off the test string and searching for it in the separator list. Kind of an unusual use of InStr. You don’t care where you find the character, only whether you find it. I can’t think of a better way to do it, short of rewriting it in a real language, like C.

Bruce: Well, if StrSpan is OK, StrBreak is also OK because it’s the same except backward. Let’s move on to GetToken.

Bruce: The original GetToken in REMLINE worked exactly like the C strtok function. It follows a classic design for iteration functions that have to be called repeatedly until they report no more items to iterate. In this type of function, you call it with one set of arguments the first time, and then you call it with another set of arguments each subsequent time.

GetToken works the same way. The first time, you pass the string to be parsed; after that, you pass an empty string. It goes like this:

sSeparator = ", " & sTab & sCrLf
sToken = GetToken(sCommand, sSeparator)
Do While sToken <> sEmpty
' Do something with sToken
sToken = GetToken(sEmpty, sSeparator)
Loop
That’s the philosophy. Here’s the code:

Function GetToken1(sTarget As String, sSeps As String) As String

' Note that sSave and iStart must be static from call to call
' If first call, make copy of string
Static sSave As String, iStart As Integer
If sTarget <> sEmpty Then
iStart = 1
sSave = sTarget
End If

' Find start of next token
Dim iNew As Integer
iNew = StrSpan1(Mid$(sSave, iStart, Len(sSave)), sSeps)
If iNew Then
' Set position to start of token
iStart = iNew + iStart - 1
Else
' If no new token, return empty string
GetToken1 = sEmpty
Exit Function
End If

' Find end of token
iNew = StrBreak1(Mid$(sSave, iStart, Len(sSave)), sSeps)
If iNew Then
' Set position to end of token
iNew = iStart + iNew - 1
Else
' If no end of token, set to end of string
iNew = Len(sSave) + 1
End If
' Cut token out of sTarget string
GetToken1 = Mid$(sSave, iStart, iNew - iStart)
' Set new starting position
iStart = iNew

End Function



Trouble in Paradise

Bruce: This function always works on the same string. Notice how the first block of code saves the sTarget argument in the static sSave variable for later iterations. The rest of the code uses sSave and ignores sTarget. The next block of code uses StrSpan to get the start of the token, and then the next block uses StrBreak to get the end. Once you have the start and the end, you cut out the token and return it.

Joe: What the heck are you doing with that Mid$ in your StrSpan call? And there it is again in StrBreak. Why are you passing the string length?

Bruce: Well, the first argument is the string, the second argument is the starting position—it’s a static that gets updated each time through—and the last argument is the string length….

Joe: And the string length never changes. You’re calculating it again and again. Furthermore, it’s wrong. If you’re halfway through the string, you’re giving the whole length of the string. I’m surprised this works at all.

Jane: It’s legal. If you give a length that goes past the end of the string, it just takes the characters to the end. But it is kind of ugly. You can drop that whole argument:

iNew = StrSpan1(Mid$(sSave, iStart), sSeps)
Bruce: Will that make it any faster?

Joe: I don’t remember the Mid$ code exactly, but I doubt that it will make much difference. The main point is that it will be right instead of working by accident.

Bruce: Embarrassing. I knew better than that.

Joe: You should be embarrassed.

Jane: Oh, come on. It’s the kind of mistake anybody might make.

Joe: I wouldn’t make it.

Mary: Joe, we don’t need this kind of negative attitude.

Joe: All right. So maybe anybody could make a slip. But the real problem with this code is deeper. It comes from coding C in Basic.

Bruce: What do you mean?

Joe: Look what you’re doing every time you call StrSpan or StrBreak. You’re cutting off the remaining part of the string and passing it as an argument. That would work fine in C because C just passes pointers to strings. The whole string stays put in memory, but you’re pointing only to the tail end of it. But in Basic, when you pass the result of Mid$ to a function, you create a new temporary string. It’s a separate string that has to be created for the function it’s passed to and then destroyed when the function leaves. You don’t want to create any more new strings than you need.

Bruce: Well, OK, but how do I keep from creating new strings?

Joe: You just pass one string—sSave—but you also pass the current position.

Jane: But that means changing the design of StrSpan and StrBreak.

Joe: Yeah. So the call changes from

iNew = StrSpan1(Mid$(sSave, iStart), sSeps)
to

iNew = StrSpan2(sSave, iStart, sSeps)
Then your StrSpan implementation changes to this:

Function StrSpan2(sTarget As String, ByVal iStart As Integer, _
sSeps As String) As Integer

Dim cTarget As Integer
cTarget = Len(sTarget)
' Look for start of token (character that isn’t a separator)
Do While InStr(sSeps, Mid$(sTarget, iStart, 1))
If iStart > cTarget Then
StrSpan2 = 0
Exit Function
Else
iStart = iStart + 1
End If
Loop
StrSpan2 = iStart

End Function

Jane: But you’re making StrSpan and StrBreak harder to use. They get a confusing extra argument. I mean, who’d guess how to use these things from the arguments?

Joe: That’s just how Basic works. Nothing but GetToken will call them anyway. If anybody else did use them, they’d have to deal with the same efficiency problem. If you don’t like Basic, use C.

Mary: Joe, sometimes I wonder why a guy who hates Basic so much chooses to work on it. You just like to criticize, and Basic is an easy target.

Jane: He’s not as tough as he acts. Actually, he has a soft spot for Basic.

Bruce: Instead of criticizing the language, you ought to fix it. Look how I have to use this stupid Mid$ function just to get a character out of a string:

Do While InStr(sSeps, Mid$(sTarget, iStart, 1))
In most languages, you access a character in a string the same way you access an element in an array of bytes—maybe something like this:

Do While InStr(sSeps, sTarget(iStart))
I hope that, internally, you’re at least optimizing the special case of extracting a single character.

Joe: Well, I’m not sure….There might not be anything we could do. A one-character string is no different from any other string in Basic.

Mary: Maybe you should make sure. Check the code.

Bruce: OK, so we’ve optimized this code, and we’re going to get a giant performance benefit. Anything else?

Jane: What happens if you pass GetToken an empty string?

Bruce: Why would you do that?

Joe: Maybe just out of orneriness.

Jane: Or maybe you’re parsing a file a line at a time, and some lines are blank. I just want to know whether you’re handling boundaries.

Bruce: I guess I’m not sure what would happen. I suppose a user might also pass an empty string for the separators. What else could go wrong?

Bruce: OK, so we end up with this:

Function GetToken5(sTarget As String, sSeps As String) As String

' Note that sSave and iStart must be static from call to call
' If first call, make copy of string
Static sSave As String, iStart As Integer, cSave As Integer

' Assume failure
GetToken5 = sEmpty
If sTarget <> sEmpty Then
iStart = 1
sSave = sTarget
cSave = Len(sSave)
Else
If sSave = sEmpty Then Exit Function
End If

' Find start of next token
Dim iNew As Integer
iNew = StrSpan2(sSave, iStart, sSeps)
If iNew Then
' Set position to start of token
iStart = iNew
Else
' If no new token, return empty string
sSave = sEmpty
Exit Function
End If

' Find end of token
iNew = StrBreak2(sSave, iStart, sSeps)
If iNew = 0 Then
' If no end of token, set to end of string
iNew = cSave + 1
End If

' Cut token out of sTarget string
GetToken5 = Mid$(sSave, iStart, iNew - iStart)
' Set new starting position
iStart = iNew

End Function
Bruce: But isn’t this error-handling code going to slow us down?

Joe: So what?

Jane: I never thought I’d hear you say that.

Joe: Well, speed is important, but it isn’t everything. If all I wanted was speed, I could write GetToken like this:

Function GetToken(sTarget As String, sSeps As String) As String
GetToken = sEmpty
End Function
That would really be fast. I could parse huge files in no time at all.

Bruce: But it doesn’t work.

Joe: It works as well as the original if you pass it invalid arguments—better, in some cases.

Mary: OK, OK. We get the point.

Joe: It doesn’t matter how fast your code is if it doesn’t work.

Posted on Jul 19, 2014, 6:12 PM

Respond to this message   

Return to Index


* I'll wait for the Cliff Notes.

by Pete (Login The-Universe)
Admin

Posted on Jul 19, 2014, 9:05 PM

Respond to this message   

Return to Index


Nice read

by PhyloGenesis (no login)

I enjoyed that. Is there more to come? What's that from?

Posted on Jul 23, 2014, 12:08 PM

Respond to this message   

Return to Index


* It seems to be from the book "Hardcore Visual Basic"

by a (no login)

Posted on Jul 23, 2014, 3:48 PM

Respond to this message   

Return to Index


Glider Simulator

by Ben (no login)

you move the mouse to change direction of the glider: dive and take off. I wrote this 'game' I guess 4 or so years ago and back then I have never taken a physics mechanics course. I never had any clue on newtonian mechanics, vectors, acceleration, zero knowledge and the trigoromery was completely self taught. This makes me want to cry I am so fried and dying these days,

DEFINT A-Z

DATA &H8BE58955,&H78B0C5E,&HD88933CD,&H890A5E8B
DATA &H85E8B07,&H5E8B0F89,&H5D178906,&H8CA
DATA &H8EA800B8,&H31FF31C0,&H36B0B9C0,&HCBABF3
DIM m(11) AS LONG
FOR i = 0 TO UBOUND(m)
READ m(i)
NEXT
DEF SEG = VARSEG(m(0))

DIM mb, mx, my

pie! = 3.1415926#

SCREEN 9, , 1, 0

CALL absolute(2, mb, mx, my, VARPTR(m(0)))

y = 50

DO
T! = TIMER + .04
CALL absolute(3, mb, mx, my, VARPTR(m(0)))

i = (175 - my) 35
x = COS(i * .1) * 100
y1 = SIN(i * .1) * 100

IF y1 > 0 THEN
s = s + 2 + (i 10)
y = y + s
ELSE
IF s > -1 THEN s = s - 1
y = y + 1 - (s * -i 4)
END IF

LINE (0, 0)-(639, 349), 0, BF
LINE (x1, y - 10)-STEP(0, 20)
LINE (-x + x1, -y1 + y)-(x + x1, y1 + y)

x1 = x1 + ABS(s) + 5
x1 = x1 - (-x1 * (x1 > 640) + 1)

m = m + 1
IF y > 325 THEN
c = 12
SCREEN 9, , 0, 0
FOR r = 1 TO 10
c = c XOR 2
FOR j = 0 TO 70 STEP 3
x = COS(j * 2 * pie! / 8) * 50 * r + x1
y1 = SIN(j * 2 * pie! / 8) * 50 * r + y
LINE -(x, y1), c * ((j > 0) * -1)
NEXT
NEXT
PRINT m
SLEEP
SYSTEM
END IF

PCOPY 1, 0
WAIT &H3DA, 8
WAIT &H3DA, 8, 8

1 IF TIMER < T! THEN 1
LOOP UNTIL INP(&H60) = 1

SYSTEM

Posted on Jul 18, 2014, 3:22 PM

Respond to this message   

Return to Index


Helicopter

by Ben (no login)

And this one I wrote probably about the same time. This is a clone of some flash game I saw. Now there's an extremely popular version of this same concept game for iphone android and the author made $50k a day or something from game downloads. I mean the game concept is probably at least a decade old though.

I can't believe this was me 4 years ago this is so painful and i feel full of dread

DEFINT A-Z
RANDOMIZE TIMER
DIM mb, mx, my
DATA &H8BE58955,&H78B0C5E,&HD88933CD,&H890A5E8B
DATA &H85E8B07,&H5E8B0F89,&H5D178906,&H8CA
DATA &H8EA800B8,&H31FF31C0,&H36B0B9C0,&HCBABF3
DIM m(11) AS LONG
FOR i = 0 TO UBOUND(m)
READ m(i)
NEXT
DEF SEG = VARSEG(m(0))

x = 80
y = 1
y1! = 12
DIM c AS SINGLE, b AS LONG
cl = 1
fl = 25

SCREEN 0, , 1, 0
DO
t! = TIMER + .0003
b = b + 1
CALL absolute(3, mb, mx, my, VARPTR(m(0)))

IF b MOD 250 = 0 THEN
cl = cl + 1
fl = fl - 1
END IF
IF fl - cl = 7 THEN
COLOR 15
DO
PRINT "VICTORY!"
LOOP UNTIL INP(&H60) = 1
END IF
IF mb = 1 THEN y1! = y1! - .2 ELSE y1! = y1! + .3
IF x > 1 THEN x = x - 1 ELSE a = -1
IF a THEN
r = INT(RND * 5)
IF r = 2 THEN
a = 0
x = 80
y = INT(RND * 20) + 1
END IF
END IF

CLS
LOCATE y, x
PRINT CHR$(219)
LOCATE y + 1, x
PRINT CHR$(219)
LOCATE y + 2, x
PRINT CHR$(219)
LOCATE y + 3, x
PRINT CHR$(219)
LOCATE y + 4, x
PRINT CHR$(219)
LOCATE cl, 1
PRINT STRING$(80, "*");
LOCATE fl, 1
PRINT STRING$(80, "*");
COLOR 15
LOCATE y1!, 35
PRINT "_/0";
COLOR 7

IF x = 40 THEN IF INT(y1!) > (y - 1) AND INT(y1!) < (y + 5) THEN EXIT DO
IF y1! < cl + 1 OR y1! > fl - 1 THEN EXIT DO
PCOPY 1, 0
WAIT &H3DA, 8
WAIT &H3DA, 8, 8
1 IF TIMER < t! THEN 1
LOOP UNTIL INP(&H60) = 1
LOCATE y1!, 35
COLOR 12
PRINT "*BREAKDOWN*";
COLOR 7
LOCATE 1, 1
PRINT b
PCOPY 1, 0
SLEEP
SYSTEM

Posted on Jul 18, 2014, 3:25 PM

Respond to this message   

Return to Index


* GET HELP!

by Clippy (Login burger2227)
R

Posted on Jul 18, 2014, 3:29 PM

Respond to this message   

Return to Index


** no worries just messing around

by Ben (no login)

time is just scary

Posted on Jul 18, 2014, 3:45 PM

Respond to this message   

Return to Index


Pong Prick Preaker

by Ben (no login)

And this is my variation of the brick breaker game in screen 0. Damn this is so painful I can't believe 4 years passed why must we have to exist for so long please let me go back 4 years ago and end it there

DEFINT A-Z
DIM c(7, 25), d
DIM t AS SINGLE
DIM m(8) AS LONG, mb, mx, my
m(0) = &H8BE58955
m(1) = &H78B0C5E
m(2) = &HD88933CD
m(3) = &H890A5E8B
m(4) = &H85E8B07
m(5) = &H5E8B0F89
m(6) = &H5D178906
m(7) = &H8CA
DEF SEG = VARSEG(m(0))
SCREEN 0
CLS

INPUT "NUMBER OF ROWS YOU WANT!!", d
d = d - 1
x = 1
y = 2 * (d + 1)
a = 1
b = 1

SCREEN , , 2, 0
CLS
PRINT
PRINT SPACE$(3);
FOR j = 0 TO d
FOR i = 0 TO 7
IF b(i, d) = 0 THEN PRINT STRING$(8, 177) + " ";
NEXT
PRINT
PRINT
PRINT SPACE$(3);
NEXT

SCREEN , , 1, 0
VIEW PRINT 1 TO 25
CALL absolute(2, mb, mx, my, VARPTR(m(0)))
DO
t = TIMER
CALL absolute(3, mb, mx, my, VARPTR(m(0)))
mx = mx 8 + 1

x = x + a
y = y + b

a = a XOR (2 * ((x > 79) XOR (x < 2)))
b = b XOR (2 * (y < 2))
FOR j = 0 TO d
IF y = 2 * (j + 1) + 1 THEN
FOR i = 0 TO 7
IF b(i, j) = 0 AND x >= 4 + (i * 9) AND x <= 11 + (i * 9) THEN
b(i, j) = &HFFFF
SCREEN , , 2, 0
LOCATE 2 * (j + 1), 4 + (i * 9)
PRINT SPACE$(8)
SCREEN , , 1, 0
b = b XOR -2
l = l + 1
END IF
NEXT
END IF
NEXT

IF y < 25 THEN 2
IF mx <= x AND (mx + 7) >= x THEN b = b XOR -2 ELSE SYSTEM
2 PCOPY 2, 1

LOCATE y, x
PRINT CHR$(2);
LOCATE 25, mx
IF mx > 74 THEN LOCATE , 74
PRINT STRING$(7, 8);
PCOPY 1, 0
1 IF TIMER < t + .01 THEN 1
LOOP UNTIL INP(&H60) = 1
SYSTEM

Posted on Jul 18, 2014, 3:28 PM

Respond to this message   

Return to Index


QBASIC

by HIRA (no login)

I AM TRYING TO MAKE A PROGRAM THAT
WRITE A PROGRAM THAT WILL REQUEST THE LENGTH AND WIDTH OF RECTANGLE UNTIL 0 IS ENTERED FOR EITHER THE LENGHT OR THE WIDTH ,YOU WILL THEN PRINT THE AREA AND PERIMETER FOR EACH SET OF INPUTS
INPUT:LENGTH AND WIDTH WILL BE INPUT
OUTPUT:THE AREA AND PERIMETER WILL BE PRINTED WITH APPROPERIATE LABELS
PROCESSING:
1.AREA +LENGTH * WIDTH
2.PERIMETER = (LENGTH+WIDTH)*2


I MADE THIS PROGRAM
CLS
GOSUB INPUTDATA
GOSUB CALCDATA
GOSUB PRINTDATA
REM****** INPUT DATA ******
INPUTDATA:
INPUT "ENTER A NUMBER"; NUMB
INPUT "ENTER A LENGTH"; LENG
INPUT "ENTER A WIDTH"; WID

REM*****CALCULATE DATA******
CALCDATA:
DO
AREA = LENG * WID
PMETER = (LENG + WID) * 2
LOOP
UNTILNUM = 0
REM******PRINT DATA*****
PRINTDATA:
PRINT "THE AREA IS "; AREA
PRINT "THE PERIMETER IS "; PMETER
END


CAN SOMEONE HELP TO CORRECT ME WHAT I AM DOING WRONG
THANKS

Posted on Jul 18, 2014, 7:47 AM

Respond to this message   

Return to Index


Stop shouting!!!

by Solitaire (no login)

Please do NOT enter your post using all uppercase letters. This is the same as shouting and is very impolite.

Regarding your code:

You only need one loop which should include the 2 inputs (not 3) for the length and width. The loop should end when either of the inputs is 0.

You do NOT need a loop for the calculation. Simply call the calculation sub after the inputs have been made in the main loop. Then call the sub to print the result, while still inside the loop.

Also, please print your strings using mixed case, not all uppercase. That would make it a lot more presentable.

Posted on Jul 18, 2014, 9:05 AM

Respond to this message   

Return to Index


Sorry

by Hira (no login)

I am new to posting online and did not realize that all caps was shouting. Sorry for that. Here are my changes, how does it look?

CLS
DO UNTIL UCASE$(ANS$) = "0"
GOSUB INPUTDATA
GOSUB CALCDATA
GOSUB PRINTDATA
LOOP
REM****INPUT DATA****
INPUTDATA:
INPUT "ENTER THE LENGTH"; LENGTH
INPUT "ENTER THE WIDTH"; WIDTH
REM****CALCULATE DATA *****
CALCDATA:
LET AREA = LENGTH * WIDTH
LET PERIMETER = (AREA * PERIMETER) * 2
REM******PRINT DATA*****
PRINTDATA:
PRINT "AREA IS "; AREA
PRINT "PERIMETER IS "; PERIMETER

Posted on Jul 18, 2014, 8:00 PM

Respond to this message   

Return to Index


Don't feel too bad

by Donald Foster (no login)

My wife uses CAPS for everything she types. She feels it's easier for her to read. Not everyone knows that all CAPS is shouting. I choose not to use all caps, but not for that reason, it just looks better to me.

Donald

Posted on Jul 18, 2014, 8:42 PM

Respond to this message   

Return to Index


Code needs corrections

by Solitaire (no login)

You have quite a few mistakes in your code.

You cannot use WIDTH as a variable since it's a reserved word.

Your loop will never end since you don't have an input named ANS$. It should be the input variable for the length or the width.

You don't have the proper formula for the perimeter. You are trying to use the same variable in the formula to assign to itself, which results in a 0.



    
This message has been edited by Solitaire1 on Jul 19, 2014 10:07 AM

Posted on Jul 19, 2014, 9:58 AM

Respond to this message   

Return to Index


Finished Product...

by Pete (Login The-Universe)
Admin

You came close, and I have to love it when someone codes in all caps! Incidentally, in QB6, you can use width as a variable. Just in case this is a QBasic project, length and width variables were changed to xlength and xwidth. Just one mistake needed to be corrected on the formula for the perimeter. Look it over, it should be clear.

- Pete

CLS
DO UNTIL UCASE$(ANS$) = "0"
GOSUB INPUTDATA
GOSUB CALCDATA
GOSUB PRINTDATA
LOOP
REM****INPUT DATA****
INPUTDATA:
INPUT "ENTER THE LENGTH"; XLENGTH
INPUT "ENTER THE WIDTH"; XWIDTH
REM****CALCULATE DATA *****
CALCDATA:
LET AREA = XLENGTH * XWIDTH
LET PERIMETER = XLENGTH * 2 + XWIDTH * 2
REM******PRINT DATA*****
PRINTDATA:
PRINT "AREA IS "; AREA
PRINT "PERIMETER IS "; PERIMETER

Posted on Jul 19, 2014, 10:43 PM

Respond to this message   

Return to Index


Wrong. This is NOT a finished product.

by Solitaire (Login Solitaire1)
S

First of all, the policy is to provide assistance to students, but not to do the homework assignment for them.

Mainly, there is a serious error -- the program never ends.

As pointed out in my previous post, there is an endless loop because there is no user input for the ANS$ variable. Where is there an ANS$ ?

This line:

DO UNTIL UCASE$(ANS$) = "0"

is meaningless. The length and width variables are numbers, not strings. The loop should end when either of them is 0. There is no such thing as UCASE$() for a number.

Posted on Jul 20, 2014, 9:02 AM

Respond to this message   

Return to Index


It works just fine... for one loop.

by Pete (Login The-Universe)
Admin

More loops require he puts some RETURN statements in it, and adds an END statement. Also I wish schools would teach better methods of ending a routine, rather than blank input of some nature. This one requires EXIT DO's or a "Continue" routine.

And it is a finished product. The math part to multiply now works, which results in a finished "product."

Pete

Posted on Jul 20, 2014, 10:02 AM

Respond to this message   

Return to Index


Re: It works just fine... for one loop.

by SMcNeill (Login SMcNeill)
R

Actually, I find it so hard to believe that we'd need to write something like this to use GOSUB routines to start with.

Here's a version that I think is soooo much simpler to read, follow, and understand, and it does't use a single GOSUB. The whole thing is 8 lines long:

DO
INPUT "ENTER THE LENGTH"; XLENGTH
IF XLENGTH > 0 THEN INPUT "ENTER THE WIDTH"; XWIDTH
IF XLENGTH > 0 AND XWIDTH > 0 THEN
PRINT "AREA IS "; XLENGTH * XWIDTH
PRINT "PERIMETER IS "; XLENGTH * 2 + XWIDTH * 2
END IF
LOOP UNTIL XLENGTH = 0 OR XWIDTH = 0

Now since this doesn't look anything like the original, I'm hoping no one will say that it's violating the homework policy. Use of the GOSUBS and all are probably required for the class as it seems they're trying to teach the concept of a Main Loop with calls to all your routines to be outside the loop.

I just thought this might be a nice example of how simple something like this could actually be. Sometimes it seems to me as if we're making the learning process a whole lot more complicated for our kids than it has to be.

(And Pete, if you or one of the other mods think this violates the homework policy, feel free to edit or delete it. It just seems odd to me that we'd take a simple 8 line program and drag it out into 20+ lines with subroutines that we don't need at all really! )

Posted on Jul 20, 2014, 4:49 PM

Respond to this message   

Return to Index


GOSUBs are totally outmoded.

by Solitaire (Login Solitaire1)
S


There is no equivalent in modern programming languages. The only reason for using GOSUB rather than calling a subprocedure is that the variables are all part of the entire program.

What should be done and is sorely neglected in QBASIC courses is teaching students how to declare variables by type. Any modern programming language requires this, and leaving it out just reinforces bad programming habits.

When I taught QBASIC, I NEVER used GOSUB, only subprocedures and function procedures (using arguments and parameters for passing variables when needed). But the first thing I introduced was variable type declarations. Furthermore, I never allowed input of variables other than strings. If a number was needed for math computation, conversion of the string input into a number had to be done. That would prepare the student for advancing into a stricter programming language.

Strictly speaking, ALL input and ALL output is done with strings (actually characters). If math computation is needed, it is done internally after converting the string into a number, and then converting the result back into a string for output.

Posted on Jul 20, 2014, 5:54 PM

Respond to this message   

Return to Index


Screw modern programming languages. This is a BASIC Forum.

by Pete (Login The-Universe)
Admin

GOSUB is a quick and easy way to use procedural programming to an end. That is what BASIC is all about. I am so fed up with brainwashed people who have forgotten what BASIC programming is, and think just because Microsoft invest millions in some crap language like .Net that it is an absolute better way to code. It is just a different way to code, better for some apps, not so for others.

Pete

Posted on Jul 20, 2014, 9:02 PM

Respond to this message   

Return to Index


*GOSUB is also useful for small routines within Subs/Funcs.

by Michael Calkins (Login MCalkins)
Moderator

Posted on Jul 20, 2014, 10:19 PM

Respond to this message   

Return to Index


"all modern programming languages require type declarations"

by xnuft (no login)

Nope:
Haskell has static typing and implicit typing (type inference).

Example: http://pastebin.com/yq88iMdX

The types of lesser and greater are inferred by the compiler. O'Caml and SML have this feature as well.

no type declarations on "lesser" and "greater" -- it is inferred that they are lists of a.

and of course dynamic languages like LISP, Python, etc. don't have type declarations.

And of course Fortran 95+ still has implicit typing based on the first letter just old versions of FORTRAN (variables I-N are integer) but IMPLICIT NONE is recommended.

I agree that you should use generally real subroutines and functions instead of GOSUB but for a really short subroutine it might be useful. Like in chess.bas we have

3 REM
IF id <> SGN(BOARD(Y, X)) THEN
ndx = ndx + 1
XX(ndx) = X
YY(ndx) = Y
END IF
RETURN

to add a pair of coordinates into a passed by reference array.

Putting this in a gosub seems better than copy-pasting it multiple times.


Posted on Jul 21, 2014, 7:56 PM

Respond to this message   

Return to Index


Programming language types

by Solitaire (Login Solitaire1)
S

I was referring to most imperative type programming languages (such as C++, Java, Basic, etc.), not functional or dynamic languages (such as Haskel, Lisp, Python, Ruby, etc.)

Posted on Jul 22, 2014, 10:52 AM

Respond to this message   

Return to Index


MY WHOLE SITE IT'S UPPERCASE (URL)*

by OPRESION (no login)

HTTP://WWW.QBASIC.PHATCODE.NET/

BYE.

Posted on Jul 20, 2014, 10:43 PM

Respond to this message   

Return to Index


* I needed a good LOL today. Thanks!

by Pete (Login The-Universe)
Admin

Posted on Jul 20, 2014, 10:45 PM

Respond to this message   

Return to Index


*WELCOME*

by OPRESION (no login)

AAAAAAAAAA

Posted on Jul 22, 2014, 9:13 PM

Respond to this message   

Return to Index


String command not working in my program

by qbasic newbie (no login)

I am trying to right a program for this homework. Below is my work. I am struggling with how to use the string command. I can't figure out how to use the string command with my program.

Write a program using the STRING$ funciton to produce the following output. Erase the screen when a key is pressed.

**

****

*******

********

**********

************

**************

****************



My program

REM ***** TO UTILIZE THE STRING$ FUNCTION *****
CLS
LET STAR$ = STRING$(16, "*")
LET COUNT = 1
DO WHILE COUNT <= 12
PRINT STRING$(16, "*")
LET COUNT = COUNT + 3
LOOP
END

Posted on Jul 15, 2014, 9:11 PM

Respond to this message   

Return to Index


This should help...

by TheBOB (Login qb432l)
R

In the STRING$ command, there is an argument to indicate the number of times a character is printed. In your example it is "16".

You could also use a variable to indicate the number of instances of "*" you wish to print.

The value of a variable in a FOR loop changes with every iteration.

You can use a STEP value in a FOR loop, for example STEP 2

Hope that does it for you,
-Bob

Posted on Jul 16, 2014, 3:04 AM

Respond to this message   

Return to Index


* I already showed him at Pete's Site. Nice to see you Bob!

by Clippy (Login burger2227)
R

[linked image]

Posted on Jul 16, 2014, 5:05 PM

Respond to this message   

Return to Index


STRING$ EXAMPLE

by Donald Foster (no login)

' STRING$ EXAMPLE

SCREEN 11

DATA 2,4,7,8,10,12,13,16

CLS

FOR Z=1 TO 8
READ A
PRINT STRING$(A,"*")
PRINT: PRINT
NEXT

WHILE A$=""
A$=INKEY$
WEND

CLS

Posted on Jul 16, 2014, 6:57 PM

Respond to this message   

Return to Index


Thank You

by qbasic newbie (no login)

Thank You, your example helped me out!

Posted on Jul 16, 2014, 9:07 PM

Respond to this message   

Return to Index


Both of you, if you want a counter loop use FOR

by Clippy (Login burger2227)
R

FOR count = 2 TO 12 STEP 3
PRINT STRING$(count, "*")
NEXT

With clever LOCATE values you could PRINT a Christmas tree too!



    
This message has been edited by burger2227 on Jul 17, 2014 12:24 AM
This message has been edited by burger2227 on Jul 16, 2014 10:34 PM

Posted on Jul 16, 2014, 10:30 PM

Respond to this message   

Return to Index


* Shouldn't that be STEP 2 ?

by Solitaire (no login)

Posted on Jul 17, 2014, 9:54 AM

Respond to this message   

Return to Index


Number of asterisks is incorrectly pictured

by Solitaire (no login)

qbasic newbie:

In your initial post, you pictured the number of asterisks as:
2
4
7
8
10
12
14
16

It looks like the third row should have been 6 instead of 7 stars. In that case, you should be using a FOR NEXT loop from 2 to 16 with STEP 2. I don't know where you got the 3 from. If you haven't learned the FOR loop yet and were trying to solve the problem with a DO WHILE loop, then you needed to start with 2 and add 2 to the count, not 3.

A much more challenging problem would be to add 1, then 2, then 3 stars to the next rows, and repeating that pattern. I don't think you're ready for that yet.

Since this is a homework assignment, the policy of this forum is not to do the homework for you, but to point you in the right direction. However, it looks like some people already did that for you, and I tried to make a correction on the assumption that the number of stars had to increase by 2 with each new row.

I hope you learned something from it and will be able to apply this knowledge to future assignments.

Posted on Jul 17, 2014, 2:03 PM

Respond to this message   

Return to Index


Response to Clippy

by Donald Foster (no login)

Clippy,

No all the asterisks increased by 3. that is why I didn't use a STEP in my FOR NEXT loop.

Donald

Posted on Jul 17, 2014, 7:08 PM

Respond to this message   

Return to Index


Steps

by Solitaire (no login)

Clippy was right. If you need to increase the number of asterisks by 3 with each iteration, then you DO need to use STEP 3 with a FOR-NEXT loop.

You need to present a clearer explanation of your problem.

Posted on Jul 18, 2014, 9:08 AM

Respond to this message   

Return to Index


What am I doing wrong

by BWare (no login)

Can anyone help me with another problem I'm having? I wrote a program to calculate a workers weekly pay according to the number of pieces produced during a given week. For some reason my final list is coming out kind of jumbled and the calculations look kind of odd. Can you help?

My Program:

' Program to initialize a report to show weekly piecework earned

' Variables Used

' Nam$ Worker's name
' Pieces Number of pieces
' Pay Amount earned
' TotPieces Total pieces
' TotPay Total Pay
' T1$, H1$, D1$ TL$ Print images

'********** Program Mainline **********

GOSUB InitializePrintImages
GOSUB PrintHeadings
GOSUB ProcessDetail
GOSUB PrintTotals
END

'********** Initialize Print Images **********

InitializePrintImages:
T1$ = " PIECEWORK WEEKLY REPORT"
H1$ = " Name Pieces Pay"
D1$ = " ## ###"
TL$ = " Totals ###"

RETURN

'********** Print Headings **********

PrintHeadings:
PRINT
PRINT T1$
PRINT
PRINT H1$
PRINT
PRINT
RETURN

'********** Process Detail **********

ProcessDetail:
CLS
GOSUB InputWorker
DO UNTIL UCASE$(Nam$) = "END"
GOSUB CalculateTotals
GOSUB PrintDetailLine
GOSUB InputWorker
LOOP
RETURN

'********** Input Worker **********

InputWorker:
READ Nam$, Pieces
DATA Johnny Begood, 265
DATA Sally Great, 650
DATA Sam Klutz, 177
DATA Pete Precise, 400
DATA Fannie Fantastic, 399
DATA Morrie Mellow, 200
DATA END, 0, 0
RETURN

'********** Calculate Totals **********

CalculateTotals:
PAY = PIECES * .50
IF Pieces < 199 THEN
PAY = PIECES * .55
ELSEIF Pieces > 199 AND Pieces< 399 THEN
PAY = PIECES * .60
ELSEIF Pieces > 399 AND Pieces< 599 THEN
PAY = PIECES * .65
ELSEIF Pieces > 600 THEN
END IF

RETURN

'********** Print Detail Line **********

PrintDetailLine:
PRINT
PRINT T1$
Print
PRINT H1$

PRINT USING D1$; Nam$, Pieces, Pay
RETURN

'********** Print Totals **********

PrintTotals:
PRINT
PRINT USING TL$; Pieces, Pay
RETURN

Thanks again,
BWare


Posted on Jul 12, 2014, 9:23 AM





Respond to this message

Return to Index

Posted on Jul 12, 2014, 6:19 PM

Respond to this message   

Return to Index


it's a couple of things

by AlGoreIthm (no login)

for one thing, you need to use greater / equal and lesser / equal signs
in the CalculateTotals subroutine - the way you have it now, you will have problems when the values are 199, 399 and 599 - test it yourself and see what's happening.

Next, your print images D1$ at TL$ need to be worked on.

Good Luck

Posted on Jul 12, 2014, 7:24 PM

Respond to this message   

Return to Index

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