Running old QBasic code in FB

New to FreeBASIC? Post your questions here.
Triopstor
Posts: 93
Joined: Apr 25, 2006 13:11

Running old QBasic code in FB

Post by Triopstor »

I forgot how to run old QBasic code(32 bit) in FreeBasic(64 bit). Some bit of code on the top of the program. I did some searching but could not find the information.

My first error is a suffix % with Upper. Is Z1$ bad too as a variable?

Code: Select all

DECLARE SUB QuickSortValues2 (Upper%)
Thanks.
fxm
Moderator
Posts: 11124
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Running old QBasic code in FB

Post by fxm »

Try first to compile by setting the compiler language to "qb".
To do this, insert the following line at the top of your old QBasic code:
#lang "qb"
marcov
Posts: 3342
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Running old QBasic code in FB

Post by marcov »

Triopstor wrote: May 25, 2022 15:19 I forgot how to run old QBasic code(32 bit)
I didn't know there is a 32-bit QBasic? Which one is that?
Triopstor
Posts: 93
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

fxm wrote: May 25, 2022 15:33 Try first to compile by setting the compiler language to "qb".
To do this, insert the following line at the top of your old QBasic code:
#lang "qb"

I found in the FREEBasic manual: '$lang: "qb"
Does the same as your suggestion: '#lang "qb"
Thank You fxm!

Proceeding...

Now it gets error message with clearing and setting stack. I don't think I need this anymore from QBasic 4.5 so I remmed it out.

Code: Select all

CLEAR , , 6000

Proceeding...

Now it gets error message expecting "=" with DEF

Code: Select all


'  Returns the number of times that a substring is found within a string.
'  ----------------------------------------------------------------------

DEF fnstrn (Search$, LookFor$)

    Count% = 0

    IF Search$ = "" OR LookFor$ = "" THEN
       fnstrn = Count%
       EXIT DEF
    END IF

    x% = INSTR(Search$, LookFor$)

    DO WHILE x% > 0
       Count% = Count% + 1
       last% = x%
       x% = INSTR((last% + 1), Search$, LookFor$)
    LOOP

    fnstrn = Count%

END DEF
Okay I guess the syntax has changed for a function, so I'll work on this...

UPDATE: This is what I tried to do now:

Code: Select all

#lang "QB"

DIM SHARED Search$
DIM SHARED LookFor$
DIM SHARED X1%

'  Returns the number of times that a substring is found within a string.
'  ----------------------------------------------------------------------
FUNCTION fnstrn (Search$, LookFor$)

    Count% = 0

    IF Search$ = "" OR LookFor$ = "" THEN
       fnstrn = Count%
       EXIT FUNCTION
    END IF

    x% = INSTR(Search$, LookFor$)

    DO WHILE x% > 0
       Count% = Count% + 1
       last% = x%
       x% = INSTR((last% + 1), Search$, LookFor$)
    LOOP

    fnstrn = Count%

END FUNCTION

Search$="Cantalope"
LookFor$="a"

X1%=fnstrn
PRINT X1%
SLEEP
But an error occurs - "argument count mismatch" for X1%=fnstrn
Help, I'm stuck.
Last edited by Triopstor on May 25, 2022 18:18, edited 3 times in total.
Triopstor
Posts: 93
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

marcov wrote: May 25, 2022 16:53
Triopstor wrote: May 25, 2022 15:19 I forgot how to run old QBasic code(32 bit)
I didn't know there is a 32-bit QBasic? Which one is that?
Sorry I meant to say DOS not 32-bit QBasic. Been a long time since.

I have seen some dead links for downloading QB64 and QB32 on the internet today.
badidea
Posts: 2525
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Running old QBasic code in FB

Post by badidea »

QB64 (which was named QB32 initially), had some trouble lately, see:
OT - Destruction of QB64 forum and wiki


Freebasic has a 32-bit and 64-bit version.

QBasic and QuickBASIC were both 16-bit I think, but I could be wrong. Too long ago indeed.
Triopstor
Posts: 93
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

badidea wrote: May 25, 2022 21:44
Freebasic has a 32-bit and 64-bit version.

QBasic and QuickBASIC were both 16-bit I think, but I could be wrong. Too long ago indeed.
Thanks for your input badidea
I'm using FREEBasic 64-bit version. My computer won't accept QBasic 4.5 anymore. But I'm not concerned.
paul doe
Moderator
Posts: 1639
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Running old QBasic code in FB

Post by paul doe »

Triopstor wrote: May 25, 2022 16:58 ...
But an error occurs - "argument count mismatch" for X1%=fnstrn
Help, I'm stuck.
Stuck with what? You defined a function that takes two string arguments, and then when calling it you don't pass them:

Code: Select all

#lang "QB"

'DIM SHARED Search$
'DIM SHARED LookFor$
'DIM SHARED X1%

'  Returns the number of times that a substring is found within a string.
'  ----------------------------------------------------------------------
FUNCTION fnstrn (Search$, LookFor$)

    Count% = 0

    IF Search$ = "" OR LookFor$ = "" THEN
       fnstrn = Count%
       EXIT FUNCTION
    END IF

    x% = INSTR(Search$, LookFor$)

    DO WHILE x% > 0
       Count% = Count% + 1
       last% = x%
       x% = INSTR((last% + 1), Search$, LookFor$)
    LOOP

    fnstrn = Count%

END FUNCTION

Search$="Cantalope"
LookFor$="a"

X1%=fnstrn( Search$, LookFor$ )
PRINT X1%
SLEEP
Triopstor
Posts: 93
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

paul doe wrote: May 26, 2022 16:21
Stuck with what? You defined a function that takes two string arguments, and then when calling it you don't pass them:
Thank You paul doe! That works! Simple now. Problem solved.

Code: Select all

X1%=fnstrn( Search$, LookFor$ )
Triopstor
Posts: 93
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

Moving on in translating my old QBasic 4.5 program to FreeBasic I have a problem with REDIM

Line 421:

Code: Select all

REDIM SortArray#(Upper%, 2)  ' Dimension 1 = Values  Dimension 2 = Index
Line 421 Error nr 4 Duplicated Definition, SortArray

Above this is Line 162 where SortArray is defined in QBasic 4.5

Code: Select all

COMMON SHARED SortArray#()         ' Sort Array
I used to know how to fix this. I think the way used is to write a FOR/NEXT loop to clear the array to null/zero instead of a REDIM.
.
Doesn't seem to be good in QBasic 4.5 to define an array without assigning dimension sizes.

So I will work on this problem now and let you guys/gals know what happened in an UPDATEI


UPDATE: I found the problem. Line 380 has another REDIM SortArray#(Upper%, 2) ' Dimension 1 = Values Dimension 2 = Index
It's interesting that you can have multiple SAME REDIMs in QBasic 4.5 and the program runs but not in FreeBasic.
fxm
Moderator
Posts: 11124
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Running old QBasic code in FB

Post by fxm »

Yet the following code works under FreeBASIC:

Code: Select all

#lang "qb"
'.....
COMMON SHARED SortArray#()         ' Sort Array
'.....
REDIM SortArray#(Upper%, 2) ' Dimension 1 = Values Dimension 2 = Index
'.....
REDIM SortArray#(Upper%, 2)  ' Dimension 1 = Values  Dimension 2 = Index
'.....
Triopstor
Posts: 93
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

fxm wrote: May 27, 2022 11:46 Yet the following code works under FreeBASIC:

Code: Select all

#lang "qb"
'.....
COMMON SHARED SortArray#()         ' Sort Array
'.....
REDIM SortArray#(Upper%, 2) ' Dimension 1 = Values Dimension 2 = Index
'.....
REDIM SortArray#(Upper%, 2)  ' Dimension 1 = Values  Dimension 2 = Index
'.....

I tried this:

Code: Select all

#lang "qb"

DIM SHARED Upper as Integer
DIM SHARED SortArray(2,2) as Integer         ' Sort Array

Upper=1
'.....
REDIM SortArray(Upper, 2) ' Dimension 1 = Values Dimension 2 = Index
'.....
REDIM SortArray(Upper, 2)  ' Dimension 1 = Values  Dimension 2 = Index
'.....

Print __FB_Version__:Sleep
I'm using 0.23.0 version of FreeBASIC I get an error - duplicated definition, SortArray on line 8
Is that why it will not work for me?

But I'll keep that in mind fxm. Thank You. I'm glad FreeBASIC is still around with support.
Last edited by Triopstor on May 27, 2022 12:44, edited 1 time in total.
fxm
Moderator
Posts: 11124
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Running old QBasic code in FB

Post by fxm »

Your version of the compiler is almost 11 years old!
Update it to avoid other types of problems in the future (last official release: 1.09.0).
(your issue above was fixed in version 0.24.0: "#3474348: Multiple REDIMs on COMMON array were disallowed")
Triopstor
Posts: 93
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

fxm wrote: May 27, 2022 12:37 Your version of the compiler is almost 11 years old!
Update it to avoid other types of problems in the future (last official release: 1.09.0).
(your issue above was fixed in version 0.24.0: "#3474348: Multiple REDIMs on COMMON array were disallowed")

Sort of. I installed 1.08.0 or the such months ago but I didn't change the complier path to the almost 11 year-old one - thinking that I had the latest one.

I downloaded 1.09.0 then extracted with app "7-Zip File Manager" and then I with FBIde 0.4.6 went to menu items
"View" then...
"Setting" then...
Tab "FreeBASIC" then...
set "Compiler Path" to D:\FreeBasic\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\fbc64.exe

I now have 1.09.0 and it works as you said fxm. Thanks fxm. Cool!
Triopstor
Posts: 93
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

Okay, now that I have the latest version 1.09.0 FreeBASIC and put #lang "QB" on top of program I get this error...

Line 150:

Code: Select all

DIM SHARED Sp, Sp$, v, Clor1, CLOR2, P, L
error nr 47 Use of reserved global or backend symbol, Sp

I wonder what Sp is used for as a reserved word in FreeBASIC? So I'll change this by REPLACING(Ctrl + R) Sp to Sp2

It's good coding practice to have a number in the variable so that it's easier to REPLACE or FIND a variable instead of damaging REM comments
Such as diSplay, correSponding and other English words.

I fixed that part.


Next problem is: D:\QB45\FBIDETEMP.c: in Function 'INITIALIZATION':
D:\QB45\FBIDETEMP.c:1923:2: error: label 'label$19' used but not defined
1923 | fb_ErrorSetHandler ( &&label$19 );
| ~~~~~~~~~~~~~~~~~


I don't have a FUNCTION INITIALIZATION but I do have a Subroutine in line 111

Code: Select all

DECLARE SUB Initialization ()
Post Reply