Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with menu in QBasic
#11
use goto.

Code:
1print"choose er die"
print"1.yo"
print"2.yo?!?!?"
print"3. im a cow."

input choice
if choice="1" then print"j0" else goto 2
2 if choice="2" then print"j02" else goto 3
3 if choice="3" then print" your a cow??" else goto 1
-yah
Reply
#12
I'm very thankful for the help i have gotten here...now i've got a new problem thought...I wonder if there is any way to access other files than *.bas through QB?

example:
Code:
PRINT "click y to play 'deep purple - child in time' "
IF inkey$ = Chr$ (49) THEN RUN "c:\media\deep purple - child in time"

is anything like that possible? (with other commands ofcourse :bounce: ). plz help
color=darkred]Imperishable flames are mine to controll![/color]
Reply
#13
you'll probably need to specify the extension, maybe not. but i would to be safe. you can run external progs using SHELL

Code:
SHELL "dir *.*"

also, the path you showed has spaces and long pathnames. you'll need to enclose the command in quotes.

" is chr$( 34 ), so... to show whats in c:\program files\...

Code:
SHELL "dir " + CHR$(34) + "c:\program files\" + CHR$(34)
Reply
#14
You can't really play music in QB... unless you use a lib, and most of those don't work properly in a windows xp environment. FreeBasic makes playing music pretty simple though...

I'm assuming that Deep Purple is a band and that "child in time" is a song title...

So basically if you want to play music, you should either not try in QB or switch to FB...
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#15
Quote:use goto.

Code:
1print"choose er die"
print"1.yo"
print"2.yo?!?!?"
print"3. im a cow."

input choice
if choice="1" then print"j0" else goto 2
2 if choice="2" then print"j02" else goto 3
3 if choice="3" then print" your a cow??" else goto 1

WTF!? I strongly advise against the use of GOTO. I see you have also used line numbers. In both QB and FB these are obselete. As modular programming methods were introduced.

Yes, Deep Purple is a band, but not anywhere on my list of favourites.
Screwing with your reality since 1998.
Reply
#16
Quote:WTF!? I strongly advise against the use of GOTO.
Why? More importantly, why in this particular case?

For one, the first two GOTO statements are completely unnecessary. If choice isn't "1", then execution will proceed to the next IF statement anyway; same for the next one. Also, it's very troublesome to insert/remove/reorder menu options; you must make sure to update your GOTO statements and labels to make sure you're don't GOTO the wrong line.

The last GOTO displays the menu again. Since the logic of the code is:

Quote:- display menu
- ask for input
- do something based on that input
- repeat indefinitely

it is much clearer to write code that says exactly that:

Code:
dim menuOption as integer              '/ menuOption is a non-decimal numeric
                                              '/ variable
do
    print "menu"                            '/ display menu options
    print "1. option 1"
    print "2. option 2"
    print "3. option 3"

    input menuOption                      '/ get user input and place it in menuOption
    
    if (menuOption = 1) then print "op1"    '/ decide what to do based on
    if (menuOption = 2) then print "op2"    '/ user input
    if (menuOption = 3) then print "op3"
loop                                          '/ repeat indefinitely

Using GOTO makes it harder to easily make modifications to your code if your needs change.
stylin:
Reply
#17
Sorry if I hurt your fealings for using obsolete GOTO. How sick of me.

But what I can say is I agree with cha0s on using the SHELL command. Its realy usefull, because it lets you copy, paste, anything you can do in DOS. I also use it to show the time in some programs, things like that. Using shell to get to other things through QB is the only way I know of... Also, you cant play music in QB, but you can make bleeps and bloops via the play command.

Code:
PLAY"O3 L32 ababa" 'O=octave L=length then you do the notes.
'There is some more advanced features that I recomend looking into.
-yah
Reply
#18
Quote:also, the path you showed has spaces and long pathnames.
lol, i was just giving an example, so that people would understand

Quote:I'm assuming that Deep Purple is a band and that "child in time" is a song title...
....are u kidding? have u not heard of 'Deep Purple'????
color=darkred]Imperishable flames are mine to controll![/color]
Reply
#19
"beeps and bloops" are hardly music, they are more of a monoreproduction of tonal vibrations...

You could also use a SELECT CASE in this instance... I'm finding them more usefull each and every day.

Code:
CLS
PRINT "please select one of the numbers"
PRINT "1...right"
PRINT "2...this works"
PRINT "3...yahoo"

DO
P$ = INKEY$
LOOP UNTIL P$ = "1" or P$ = "2" or P$ = "3"

SELECT CASE P$

CASE "1":
     PRINT "RIGHT!"
CASE "2":
     PRINT "THIS WORKS!"
CASE "3":
     PRINT "YAHOO!"

END SELECT

EDIT: Yes I've heard of Deep Purple, I was just making sure you were talking about the same Deep Purple I was talking about :rotfl:
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#20
GOTO can be useful for bypassing a certain aspect of your code. I don't use it at all except for:

Code:
ON ERR GOTO linelabel

Which would in turn terminate execution anyway because at that point I want an error shown and then have it do nothing more so I can debug freely.

Just saying there are far better ways to code other than using GOTO, as we have shown.

You can play music in QB, using a 100% SB compatible sound device. QB alone does not have this support, but v4.5 and PDS (7.1) have support for libraries to be invoked at QB startup. One in particular I find handy is BWSB. There is also a Windows-based slave program which requires a DirectX compatoble sound card. It's called DS4QB and there are a few variations. I use the full package, well used to use it... DS4QB2++ which has CD player support, MOD tracking, MP3... a few more. That's a pretty full list. Smile
Screwing with your reality since 1998.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)