Converting program from QBasic to FreeBasic help

New to FreeBASIC? Post your questions here.
Post Reply
Ed Davis
Posts: 37
Joined: Jul 28, 2008 23:24

Converting program from QBasic to FreeBasic help

Post by Ed Davis »

I'm converting some (working) code from QBasic, and have a
question:

This works:

Code: Select all

if 1 then print "? " else print "2"
But these generate syntax errors:

Code: Select all

if 1 then print "? ", else print "2"
if 1 then print "? "; else print "2"
fbc -lang qb test2.bas
test2.bas(2) error 4: Duplicated definition, else
if 1 then print "? ", else print "2"
^
test2.bas(3) error 4: Duplicated definition, else
if 1 then print "? "; else print "2"
^

I'm using:

FreeBASIC Compiler - Version 0.18.5 (04-17-2008) for win32 (target:win32)
Copyright (C) 2004-2008 The FreeBASIC development team.
Configured as standalone


Is this intentional behavior?

Note that I realize that I can convert this to a multiline if,
and that solves the problem. But I was just curious as why the
former didn't work
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

Hmm... No, I don't think that's intentional, and I'm not sure why it's happening in lang qb...
But if you want a workaround for now, you don't have to go multiline; just put a colon at the end of the print statement, e.g:

Code: Select all

If 1 Then Print "? "; : Else Print "2"
toml_12953
Posts: 27
Joined: Jul 07, 2005 12:37
Location: Malone, NY
Contact:

Syntax Errors

Post by toml_12953 »

Try upgrading to .20

Code: Select all

If 1 Then Print "? ", Else Print "2"
If 1 Then Print "? "; Else Print "2"
seems to work in the latest version.
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Post by coderJeff »

Yeah, cha0s went through the forums and posted several bugs on the sf.net bug tracker so this one actually got noticed and should be fixed in the 0.20.0 release.

The problem was with symbol lookups in the qb dialect .. which weren't taking the suffix in to consideration:

For example, qb allows this:

DIM CHR, ELSE$
IF CHR THEN PRINT ELSE$, ELSE PRINT CHR$(1),

And fbc was seeing the ELSE as a variable only.
Post Reply