Qbasicnews.com
April 10, 2020, 04:05:07 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2] 3
  Print  
Author Topic: SELECT CASE, or something  (Read 8910 times)
qbiscool
Member
*
Posts: 56


« Reply #15 on: March 15, 2004, 07:27:23 PM »

or if you realy want to you could use goto's

Quote

input "hit a key"; j$
if j$ = "w" then
print "you hit w"
else if j$ = "r" then print "you hit r"
else print "you hit "j$
end if



or
Quote

on error goto goterror
print "hit a key or esc to exit"
do
key$ = inkey$
do
loop until key$ <> ""
print key$
if key$ <> chr$(27) then loop else system
system

goterror:
print "found error"
do
print "[r]etry, gnore, [f]ail"
do
key$ = inkey$
if key$ = "r" then resume
if key$ = "i" then resume next
if key$ = "f" then system
loop until key$ <> ""
loop
Logged

pen your other eyes.........
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #16 on: March 16, 2004, 07:46:41 AM »

/me thinks aga is insane =P

Qbiscool. goto statements are dangerous at the hands of a newbie =(. So I would rather advice him to use gosub.
Logged
Neo
Na_th_an
*****
Posts: 2150



« Reply #17 on: March 16, 2004, 09:42:12 AM »

Quote from: "TheBigBasicQ"
Qbiscool. goto statements are dangerous at the hands of a newbie =(. So I would rather advice him to use gosub.

So... you discriminate people on their knowledge and then say either 'YOU SHOULD USE SUBs' (experienced) or 'YOU SHOULD USE GOSUB' (newb)... Wink


Quote from: "Moneo"
Ah, yes, I like Aga's example. It reads so much better. Some people may not like multiple statements on one line, but they sure make the code look nice. You can see the whole thing with one glance.

I'd really like it though if it had some identing... Wink
Logged
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #18 on: March 16, 2004, 09:45:19 AM »

No, i wasnt discriminating =P. I was just saying that goto is dangerous. I dont like GOSUB(personally) so I suggested SUB =).
Logged
Neo
Na_th_an
*****
Posts: 2150



« Reply #19 on: March 16, 2004, 09:48:02 AM »

*Inproper* use of GOSUB: Out of stack space
GOTO: Spaghetti code (sometimes causing stack error as well)
SUBS: Optimal procedural programming.

I think I agree with you Wink

Btw, why, why, why does ON ERROR only support GOTO and not CALL SUB or so... Sad
Logged
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #20 on: March 16, 2004, 09:49:48 AM »

How how how should I know =P? But I dont find it inconvinient =P.
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #21 on: March 16, 2004, 09:50:02 AM »

Simple. My program modified to have tabs:

Code:

DO                                                      '7 tabs
INPUT "Enter the !#$!@#$@#$ key already!!", ikey        '1 tab
SELECT CASE ikey                                        '5 tabs
CASE "1": key1: EXIT DO                                 '5 tabs
CASE "2": key2: EXIT DO                                 '5 tabs
CASE ......
CASE ELSE: PRINT "INVALID!"                             '4 tabs
END SELECT                                              '6 tabs
LOOP                                                    '7 tabs
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #22 on: March 16, 2004, 09:51:15 AM »

Quote from: "Agamemnus"
Simple. My program modified to have tabs:

Code:

DO                                                      '7 tabs
INPUT "Enter the !#$!@#$@#$ key already!!", ikey        '1 tab
SELECT CASE ikey                                        '5 tabs
CASE "1": key1: EXIT DO                                 '5 tabs
CASE "2": key2: EXIT DO                                 '5 tabs
CASE ......
CASE ELSE: PRINT "INVALID!"                             '4 tabs
END SELECT                                              '6 tabs
LOOP                                                    '7 tabs


I dont get the relevance?
Logged
Neo
Na_th_an
*****
Posts: 2150



« Reply #23 on: March 16, 2004, 09:52:36 AM »

Quote from: "Agamemnus"
Simple. My program modified to have tabs:

Hrmmm... where are the tabs?

I meant something like this:
Code:

DO
   INPUT "Enter the !#$!@#$@#$ key already!!", ikey
   SELECT CASE ikey
      CASE "1":
         key1: EXIT DO
      CASE "2":
         key2: EXIT DO
      CASE ......
      CASE ELSE:
         PRINT "INVALID!"
   END SELECT
LOOP
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #24 on: March 16, 2004, 11:49:08 PM »

Neo, I have a feeling that Aga doesn't waste time indenting or formating sample code. I guesss he figures if you like it you'll adopt it and format it to your taste.
*****l
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #25 on: March 17, 2004, 12:16:42 AM »

tBBQ: in response to Neo.
In regards to GOSUBs, I think that they're usually not necessary, but they still have use. I think that there could have been a lot more done with QB4.5's GOSUB/SUB thing, such as multiple layers:

1) Commands in one SUB don't respond to labels in other SUBs, but the label namespace is global not local. (ie. only one "blah:" per program)

2) GOSUBs are a nice organizational tool when you have a lot of SUBs or very few SUBs. Could make the IDE a lot cooler if you could see GOSUBs in a SUB, and maybe SUBs in SuperSUBs. (ie modules)

Neo: After the code and before the comments.

Moneo: Yup, yup, very sensible...
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
qbiscool
Member
*
Posts: 56


« Reply #26 on: March 17, 2004, 08:51:02 PM »

hey for that ON ERROR GOTO goterror could i use two ON ERROR's
like this:

Quote

ON ERROR GOTO 1
bload "",d,3

on error goto 2
open "" for output as #1
close #1

1
resume next

2
system
Logged

pen your other eyes.........
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #27 on: March 17, 2004, 11:33:22 PM »

Like this?
Code:
CLS
ON ERROR GOTO 1
OPEN "aBaBaB1" FOR INPUT AS #1
ON ERROR GOTO 2
OPEN "aBaBaB2" FOR INPUT AS #1
CLOSE #1
END
1
PRINT 1
RESUME NEXT

2
PRINT 2
RESUME NEXT


hmm, guess so. it prints 1 and 2.
(and if you remove one of the OPENs it only prints one number so...)
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Blitz
I hold this place together
*****
Posts: 853



WWW
« Reply #28 on: March 18, 2004, 09:12:41 AM »

QBs error handling is the crappiest evarrr.
Logged

oship me and i will give you lots of guurrls and beeea
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #29 on: March 18, 2004, 12:11:03 PM »

Nope you put only one ON ERROR statement. In order to check which error actually caused your error handler to be called you would use ERR command. Like this:

Code:
CLS
ON ERROR GOTO errhandler

CHDIR "e:"

END
errhandler:
IF ERR = 71 THEN
   PRINT "ErrorHandler: device not ready"
ELSEIF ERR = 76 THEN
   PRINT "ErrorHandler: Invalid drive specification"
END IF

RESUME NEXT


Change the drive letter to a non existing one and you will trap the second error while change it to "a:" and dont put any floppy into it and you will have it catch the first error =)
Logged
Pages: 1 [2] 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!