Help with basic QBasic subroutines

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Dan
Newbie
Posts: 1
Joined: Thu Feb 26, 2009 11:19 am

Help with basic QBasic subroutines

Post by Dan » Thu Feb 26, 2009 11:21 am

Ok so I need to write a program using subroutines, which I really don't understand... These are the directions:

"Write a program that asks the user to enter 3 numbers and then adds them, multiplies them, or adds the first two and divides the sum by the third. Use three subroutines, one for each process.

Enter 3 numbers? 45, -12, 7
Enter S)um, M)ultiply, D)ivide? D
(45 + -12) / 7 = 4.714286"

It would be really appreciated if you guys could code this program for me and it would help me with subroutines a little better. Thanks!

User avatar
burger2227
Veteran
Posts: 2385
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Thu Feb 26, 2009 11:43 am

Since you already asked at the N54 Qbasic Forum, you should know that we don't do homework here either!

Submit your code and we can then help you........

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

iamdenteddisk
Veteran
Posts: 185
Joined: Mon Jun 30, 2008 4:10 pm

write the program

Post by iamdenteddisk » Tue Mar 10, 2009 6:49 am

OK, I bite what school still teaches Qbasic?
I might like to attend..

"write the program yourself man there are plenty of tutorials and program snipits available on petes site read them to figure it out I will give a hint though".

'begining the program******
'make sure you declare your subs at the begining of the main program
declare sub walk() 'declaring your sub

use

gosub walk 'for calling your sub

or

walk 'calling your sub differently

'to use your sub from the main program


end 'ending your main program


then you use a lable such as

walk:

'write your sub code
'then close the sub with

end sub

your done!

User avatar
burger2227
Veteran
Posts: 2385
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Tue Mar 10, 2009 11:46 am

WRONG!

SUBs made in the main module use LINE LABELS like Mysub:
They can be placed anywhere in the module code, but I usually prefer to place them after the main module code.

To end the SUB, you can use RETURN, GOSUB or GOTO. NOT END SUB! Module subs need to return eventually to the place they were called or you may skip some valuable code.

END SUB is only used by Qbasic generated SUBs made using the EDIT Menu. You could write one yourself using SUB name and your code with an END SUB line to end the SUB code. These kind of subs may require that parameters are passed unlike module Subs. They automatically return to the module calling code line.

Qbasic can DECLARE those SUB programs for you once the new SUB is called and the program is saved.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

iamdenteddisk
Veteran
Posts: 185
Joined: Mon Jun 30, 2008 4:10 pm

try reading

Post by iamdenteddisk » Wed Mar 11, 2009 6:13 am

try reading the post, "extract and understand the information", form opinnion, post acordingly..



Q: If my post is wrong burger, why did you just repeat what I said?

A: to do it your way.

>SUBs made in the main module use LINE LABELS like Mysub:
>They can be placed anywhere in the module code, but I usually prefer to >place them after the main module code.

the only difference in what you and I said was the label name.

>To end the SUB, you can use RETURN, GOSUB or GOTO. NOT END SUB! >Module subs need to return eventually to the place they were called or >you may skip some valuable code.

the RETURN is a part of the subcode which is optional relitive to if you want to return and there for I didn't comment on it. If you want to see the end sub command in your code try opening it in notepad..
you will see it will look like this.

walk:
"subcode"
Return ' optional relitive to program flow
END SUB

or this

walk:
"subcode"
system ' optional relitive to program flow
END SUB

in every case the end sub is there though you cant see it in some cases because it might not be displayed in the qb envionment.

Now we see the root cause of the behavior, depending on Qb environment to Auto declare subs for you "ah hah", for the enviroment to behave automaticly you have to use the automation and write in a way that is required.

But to write "your own code" top down and feed it to the compiler you learn code optomization techniqes by "reading working source" that make not your source not only readable but also reusable in future projects too. you also declare the sub before writing it's code too.
"your self"


Goto's are slow and use to much time, usualy end up freezing wrecking programs it is much simpler to use the gosub if-then's or just the label itself to call your subs and "call" wont work unless you have it included in a library.



P.S carefull your doing someone's homework too.

one last question what is wrong in this post?

User avatar
burger2227
Veteran
Posts: 2385
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Wed Mar 11, 2009 11:30 am

Oh, I see! The old invisible END SUB that you followed your examples with? That SURE makes sense!

That is why you CAPITALIZED them too I gather. A beginner would think that was a QB statement, but WHO CARES! You sure don't dummy!

Are you retarded? The Original Poster came back to the other QB site and said that we were all buttheads for not doing it for him. NEXT time I'll just send the SLACKER jerks here to learn how not to code from you, lol.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

iamdenteddisk
Veteran
Posts: 185
Joined: Mon Jun 30, 2008 4:10 pm

LMAO

Post by iamdenteddisk » Wed Mar 11, 2009 11:50 pm

What is asumed is our conflict here, you are asuming your way is the only way and are dogging myself and other's who are wanting to contribute to petes site.

Sure doing everything one solitary way as a standard, is optpmized and effecient "I give you that" but it isn't exactly inviting to member's and contributers to the site is it?

A simple suggestion is this, post your answer and allow others to post their's too. without being dogged and let pete decide what forum a discussion belongs in..odds are only the good answers get saved to the forum.

it wouldn't hurt either if you ask a question from time to time even if it is compleatly off topic too, so others dont get discouraged by God fear..

one of the best teaching methods I know is to provide certian information and lead the pupil into submitting the correct answer for them selves.

Look at the trafic time marks on the post, with many to stop by time to time and ask a single question and only one to answer it "don't show comfy atmosphere" GET THAT and you will see petes site start to hop again like it used to .

As to the do it you own way thing that is best for tutorials and can be uploaded.

Please understand burger I thuroghly appreciate your post and all you do to answer the difficult questions to the best of ability, all I am asking for is for that feeling to be mutual..

Even if a post is badly wrong it is a visitor to the site and that is a good thing..for you,me,pete,QB.
Aslong as sombody gives a right answer it stays on track right!

Thanks

User avatar
burger2227
Veteran
Posts: 2385
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Thu Mar 12, 2009 12:48 am

Listen, I am NOT trying to chase you or anybody else away! I saw a need to get involved because some new programmers might be misled.

Work with me here and try to add useful stuff when you feel the need. Some of your posts go off subject or repeat things in another way. I had no intention of EVER posting in this thread anymore! I don't help CHEATERS.

I had to come back when I saw you trying to explain SUBs. I think that you know how to do that, but I thought your explanation was confusing to someone that might just stop to read the thread. Understand?

Like I said before, think about what you answer first. You can always come back to Edit if you need to.

Ted

PS: Every QB site is slow now that many kids are not taught QB anymore.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

Post Reply