New to GLbasic but used to older lsanguages

Previous topic - Next topic

shaf

I think I'm going to write a Help file as soon as I get more familiar with GLBasic -comparing GLBasic to Basic.

Obviously arrays are handled slightly differently, as well as data calls.
I think I can Replace the Basic LEFT$ & RIGHT$ commands with MID$
Command separators are different Basic uses : and GLBasic uses ;

Is there an way to do this in GLBasic

ON C1 GOTO 1000,1000,1000,1000,1000,1100,1200,1300,1400

I'm thinking
IF C1 GOTO 1000, 1000 ... but GOTO only allows one call. Should I turn C1 into an array and do the following
For N = 1 to 9
IF C1[1} goto 1000
IF C1[2} goto 1000
IF C1[3} goto 1000
IF C1[4} goto 1000
IF C1[5} goto 1000
IF C1[6} goto 1100
IF C1[7} goto 1200
IF C1[8} goto 1300
IF C1[9} goto 1400
next

bigsofty

You dont need to turn N into an array or put it into a loop, the SELECT statement will select your correct value for c1 and ignore the other lines, hence its a lot quicker... so...

Code (glbasic) Select
SELECT c1
  CASE 0 GOTO 100
  CASE 1 GOTO 100
  CASE 2 GOTO 200
  CASE 3 GOTO 200
  CASE 4 GOTO 500
ENDSELECT
Not used in this example but the SELECT statement has extra commands for handling certain situations...

Code (glbasic) Select
CASE 6 TO 99 GOTO 200 // if C1 was between 6 and 99or

Code (glbasic) Select
CASE >100 GOTO 100 // if C1 was greater then 100or

Code (glbasic) Select
DEFAULT GOTO 300 // If C1 has a value that SELECT does not handle (eg... -10), same ELSE in an IF
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Schranz0r

sorry, but thats a bad coding style!
I'll never use GOTO !
That looks like spagetticode, if you know what it is?!

GOTO is my last choose...
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

BumbleBee

GOTO is unpopular and still from the Basic-Stone Age.;) I usually don't use GOTO with the exception of

Code (glbasic) Select
 IF hungry=TRUE THEN GOTO McDonalds;)

Cheers
The day will come...

CPU Intel(R) Core(TM) i5-3570k, 3.4GHz, AMD Radeon 7800 , 8 GB RAM, Windows 10 Home 64Bit

bigsofty

I'm not commenting on coding style, this is just a question of syntax.

For the record, I don't use GOTO either, but Shaf's original code is so old, he may have no option if he wishes to avoid a major rewrite.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

shaf

Bigsofty is correct,
Ordinarily I wouldn't use goto but since I'm rewriting some very old Basic Programs (1983) unless I totally Restructure and rewrite the Program it's the only way to do it. Unfortunately I didn't save my Programming Flowcharts. If you think that's bad you should see some of my Assembler Coding I used to program ML for 8008, 1802, 6502 and 68000.

Shaf

shaf

BumbleBee

Although I have Children If Hungery & MCDonalds can't be used in the same statement.
;}

Shaf

shaf

Bigsofty,
I tried using the Select Method and got a syntax error immediately in the debugger.
CASE 0 GOTO Line100

OK I found the error GOTO doesn't work it preceeded by THEN
So CASE 0 THEN GOTO Line100 works

Schranz0r

Or:

Code (glbasic) Select
SELECT Var
    CASE 0
        GOTO Line100
    CASE 1
        GOTO Line101
ENDSELECT
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

CASE xxxx ; DoSomething()
The CASE line must be terminated by a newline (or ; charakter)

Kitty Hello


shaf

GernoT,

Thanks this will be a huge help to people trying to convert old code into GLBasic. Now where is my old Star Trek program  done on the C64.

Thanks

Shaf