Converting QBASIC program into FreeBASIC

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
Posts: 17
Joined: Nov 09, 2008 19:53

Converting QBASIC program into FreeBASIC

Postby zzo38 » Nov 11, 2008 18:31

There a few differences of QBASIC and FreeBASIC.

Here is a list of a few things to do:
  • Type #lang "qb" at the beginning of the program.
  • COMMAND$ does not automatically convert it to uppercase in FreeBASIC, you have to use UCASE$(COMMAND$) if you want that.
  • QBASIC uses column-major order for arrays and FreeBASIC uses row-major order. You can make an array act like column-major order by doing something like #define Images(x,y) Images_(y,x)
  • A fixed-length string in a TYPE structure takes up 1 extra cell in FreeBASIC.
  • SCREEN 1 in FreeBASIC isn't actually a 4-colors mode, it just fakes it, so you need to calculate the color depth differently in FreeBASIC. You also need to calculate GET/PUT graphics array dimensions corresponding differently for this reason, and you also need to know this for patterns painting using PAINT command.
  • In QBASIC, ? could be used as a shortcut for PRINT only in the interpreter, not in the compiler. In FreeBASIC it is accepted to use ? in the compiler.
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Postby Antoni » Nov 11, 2008 20:24

Posts: 17
Joined: Nov 09, 2008 19:53

Postby zzo38 » Nov 11, 2008 21:52

Antoni wrote:
There is all sorts of stuff listed there but some of the stuff I listed isn't there.
Posts: 8
Joined: Mar 21, 2012 9:30

Re: Converting QBASIC program into FreeBASIC

Postby stealth » Mar 21, 2012 13:54

Dear Forum members

I've a (large) project in QBasic 4.5 which I'm converting to FreeBASIC. Since this is a task with a lot of manual labor I wondered if someone was able to convert QBasic projects to FreeBasic on an easy way? Please share your experiences/thoughts.

Thanks in advance for sharing .
Posts: 3038
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Converting QBASIC program into FreeBASIC

Postby Richard » Mar 21, 2012 21:35

You might consider using the lang -qb compiler option, or make the first line of your old qb program #lang "qb".
FreeBASIC will then use the old QB syntax.
Posts: 8
Joined: Mar 21, 2012 9:30

Re: Converting QBASIC program into FreeBASIC

Postby stealth » Apr 04, 2012 20:31

Dear forum members,

Thanks for your responses so far. The QBasic 4.5 project contains open file code like this. In my perception Freebasic doesn't support this at all (lang -qb included)

FIELD #1, 7 AS XXX$, 30 AS YYY$, 1 AS ZZZ$, 3 AS BBB$

More suggestions are very welcome

Best regards
Posts: 1156
Joined: May 08, 2006 21:58
Location: Crewe, England

Re: Converting QBASIC program into FreeBASIC

Postby jevans4949 » Apr 19, 2012 11:05

You are right, FB doesn't support this. You will have to re-write this using a TYPE.

While doing so, note that QB-type Fixed-length Strings are not easily supported in FB. In FB, a STRING*n has an actual length of n+1, and is a null-terminated string, not padded with blanks. If you need to read one, define it as a ZSTRING*n in your type and use LEFT$(sourcestring,LEN(sourcestring)) to get something FB-friendly. Also, if writing it back, append spaces to the in-program version and use STRNCPY to move it to the record. (There are other solutions, but this is MY preferred one.)

STRNCPY is in the "crt/" include, and documented in the Wiki / Help under "C Standard Library Functions"
Posts: 9990
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Converting QBASIC program into FreeBASIC

Postby fxm » Apr 19, 2012 11:34

At this documentation page:
Read especially the paragraph 'Warning' and the examples.
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe

Re: Converting QBASIC program into FreeBASIC

Postby petan » May 21, 2012 17:05

A bit learning, I did such thing 2 years back. As answered you must use UDT via Type command.
Best way - see example "Working with random files " or similar named somewhere on Petesqbsite.
Then you will have changed command like

Code: Select all

OPEN <Filename> FOR RANDOM  AS #nf1 LEN = len(yourType)
"Field"  will be Type in declarations/definitions (module - if more source files)
TYPE yourType
   yourVar1 as string
   yourVar2 as ubyte
etc, etc

The big change in FB is - you work with one buffer, not with group of separate variables.


Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 5 guests