Running old QBasic code in FB

New to FreeBASIC? Post your questions here.
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Running old QBasic code in FB

Post by paul doe »

Triopstor wrote: May 27, 2022 15:31 ...
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.
SP is an assembly register. Since FB doesn't mangle 64-bit code, it causes all sort of weird behavior. Thus, such an error was introduced to prevent this. Most editors have a 'whole word' setting when finding/replacing text, to avoid the mishaps you describe.
...
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 ()
A sub and a function are the same thing. Think of subs as 'functions that return no value' and thus cannot be used in expressions (they need to be used as statements).

The error means that there's probably a goto that points to a label that wasn't defined. Most likely an error handler (via ON ERROR GOTO), judging from the error message.
Triopstor
Posts: 106
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

paul doe wrote: May 27, 2022 16:03 SP is an assembly register. Since FB doesn't mangle 64-bit code, it causes all sort of weird behavior. Thus, such an error was introduced to prevent this. Most editors have a 'whole word' setting when finding/replacing text, to avoid the mishaps you describe.
Thank You paul doe for telling me that SP is an assembly register. I did some searching on the Internet. SP could be a Stack Pointer(SP) register which is an internal memory storage to speed up the processor operations.
A sub and a function are the same thing. Think of subs as 'functions that return no value' and thus cannot be used in expressions (they need to be used as statements).
I thought they would make a distinction but yes I can think of a subroutine(SUB) and a function(FUNCTION) as the same thing.
The error means that there's probably a goto that points to a label that wasn't defined. Most likely an error handler (via ON ERROR GOTO), judging from the error message.
Yes you are right! I have a ON ERROR GOTO in the subroutines that are getting errors. And OPENing files that don't exist because the file path needs to be updated/changed. I think I can solve this in time. I wonder how long this will take. Thank You.
Last edited by paul doe on May 27, 2022 17:14, edited 1 time in total.
Reason: Fixed formatting issues
Triopstor
Posts: 106
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

I now have to translate a shelled file and I found this interesting bit of code in QBasic 4.5:

Code: Select all

'*** "VERIFY" GLOBAL VARIABLES ***
DIM COL(5), ROW(5), V$(5), D$(5), I$(5), R$(5, 1)
COMMON SHARED COL(), ROW(), V$(), D$(), I$(), R$()
COMMON SHARED SP2, SP2$, V, CLOR1, CLOR2, P, L
When run in FreeBASIC a duplicated definition error occurs for COL on the 3rd line.

So when I put the DIM after the COMMON SHARED the order as following:

Code: Select all

'*** "VERIFY" GLOBAL VARIABLES ***
COMMON SHARED COL(), ROW(), V$(), D$(), I$(), R$()
COMMON SHARED SP2, SP2$, V, CLOR1, CLOR2, P, L
DIM COL(5), ROW(5), V$(5), D$(5), I$(5), R$(5, 1)
The code now runs in FreeBasic fine!

Why was this change made? Better structured code?

But looking at the code from another file this works in FreeBASIC:

Code: Select all

#Lang "QB"
'  **********************
'  ** Global variables **
'  **********************
'  Verify
'  ------
DIM SHARED Col(10), Row(10), v$(10), D$(10), I$(10), R$(10, 1)
DIM SHARED Sp2, Sp2$, v, Clor1, CLOR2, P, L

print _FB_VERSION_: Sleep
Interestingly the _FB_VERSION_ is now "0"(zero) because of #Lang "QB" I guess. I guess there is an alternate SUB when it complies.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Running old QBasic code in FB

Post by fxm »

Not:
_FB_VERSION_
but:
__FB_VERSION__
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Running old QBasic code in FB

Post by fxm »

With QB45, COMMON allows sharing static (fix-len) or dynamic (var-len) arrays between modules.
Static arrays must be defined (by DIM) before the COMMON line while dynamic arrays must be defined (by REDIM) after.

With FB, COMMON always shares dynamic arrays. They must therefore be defined (by DIM or REDIM) always after the COMMON line.
Triopstor
Posts: 106
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

fxm wrote: May 29, 2022 11:56 Not:
_FB_VERSION_
but:
__FB_VERSION__
The simple things... Okay 2 underscore then FB then 1 underscore and VERSION and then 2 underscore(Shift + -)
Turns purple in FBIde 0.4.6 so one can know.

Thanks fxm
Triopstor
Posts: 106
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

fxm wrote: May 29, 2022 12:24 With QB45, COMMON allows sharing static (fix-len) or dynamic (var-len) arrays between modules.
Static arrays must be defined (by DIM) before the COMMON line while dynamic arrays must be defined (by REDIM) after.

With FB, COMMON always shares dynamic arrays. They must therefore be defined (by DIM or REDIM) always after the COMMON line.
I will remember this. Thank You fxm. I'm glad you spelled this out for me and for others.

La vie est bonne. Et il est bon de comprendre toutes choses.
Life is good. And it is good to understand all things.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Running old QBasic code in FB

Post by fxm »

Triopstor wrote: May 29, 2022 12:49 The simple things... Okay 2 underscore then FB then 1 underscore and VERSION and then 2 underscore(Shift + -)
Turns purple in FBIde 0.4.6 so one can know.
FBIde is from 2006, so recognized keywords stop at that date.
You can complete them using the 'View/Settings/Keywords' menu, or directly editing the '.....\IDE\fbfull.lng' file.
Triopstor
Posts: 106
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

fxm wrote: May 29, 2022 13:03
FBIde is from 2006, so recognized keywords stop at that date.
You can complete them using the 'View/Settings/Keywords' menu, or directly editing the '.....\IDE\fbfull.lng' file.
Thank You. I wonder what keywords to add?
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Running old QBasic code in FB

Post by coderJeff »

This list may help: keywords.lst
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Running old QBasic code in FB

Post by fxm »

OK for the "fb" dialect.
But for the "qb" dialect, there are also keywords specific to "fb" but prefixed with "__". Is there such a list too?
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Running old QBasic code in FB

Post by coderJeff »

I don't think there is any list on record that shows all the prefixed keywords in QB.

It should be approximately:
__ABSTRACT __ACOS __ASIN __ASM __ATAN2 __BASE __BOOLEAN __BYTE __CAST __CBOOL __CBYTE __CLASS __CLNGINT __CONSTRUCTOR __CONTINUE __CPTR __CSHORT __CSIGN __CUBYTE __CUINT __CULNG __CULNGINT __CUNSG __CUSHORT __CVA_ARG __CVA_COPY __CVA_END __CVA_START __CVLONGINT __CVSHORT __DEFBYTE __DEFLONGINT __DEFSHORT __DEFUBYTE __DEFUINT __DEFULNG __DEFULONGINT __DEFUSHORT __DELETE __DESTRUCTOR __ENCODING __EXPLICIT __EXPORT __EXTENDS __EXTERN __FALSE __FRAC __IIF __IMAGECREATE __IMPLEMENTS __IMPORT __INSTRREV __LONGINT __MKLONGINT __MKSHORT __NAMESPACE __NEW __OPERATOR __OVERLOAD __POINTER __PRIVATE __PROCPTR __PROPERTY __PROTECTED __PTR __PUBLIC __SCOPE __SCREEN __SHL __SHORT __SHR __SIZEOF __THREADCALL __TRIM __TRUE __TYPEOF __UBYTE __UINTEGER __ULONG __ULONGINT __UNION __UNSIGNED __USHORT __VAR __VA_FIRST __VIRTUAL __WCHR __WINPUT __WITH __WSTR __WSTRING __ZSTRING __ALLOCATE __BIN __CALLOCATE __CURDIR __DEALLOCATE __DIR __DYLIBFREE __DYLIBLOAD __DYLIBSYMBOL __ERFN __ERMN __EXEC __EXEPATH __FLIP __GETJOYSTICK __GETKEY __GETMOUSE __IMAGECONVERTROW __IMAGEDESTROY __IMAGEINFO __INKEY __LEFT __MULTIKEY __POINTCOORD __REALLOCATE __RIGHT __SCREENCONTROL __SCREENCOPY __SCREENEVENT __SCREENGLPROC __SCREENINFO __SCREENLIST __SCREENLOCK __SCREENPTR __SCREENRES __SCREENSET __SCREENSYNC __SCREENUNLOCK __SETMOUSE __SLEEP __VAL __VALINT __VALLNG __VALUINT __VALULNG __WBIN __WHEX __WINDOWTITLE __WOCT __WSPACE
The difference between the above list and words in keywords.lst will give the words that don't change between dialects.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Running old QBasic code in FB

Post by fxm »

Weird:
It seems to me that __OBJECT is also allowed in the "qb" dialect, but that seems unnecessary because everything it allows in the "fb" dialect is forbidden in the "qb" dialect.
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Running old QBasic code in FB

Post by coderJeff »

All of the keywords get defined when the parser starts. The keywords that are in fb/fblite dialects but not qb dialect get prefixed with "__" so the new words don't get in the way of symbol names in qb source. The feature that is implemented by the keyword (and if it is allowed or not) is decided and reported later when the source code is actually parsed.

Seems I missed a few:
__RGB __RGBA __VA_ARG __VA_NEXT __ASSERT __ASSERTWARN __OFFSETOF __BITRESET __LOWORD __HIWORD __LOBYTE __HIBYTE __BIT __BITSET __BITRESET
Triopstor
Posts: 106
Joined: Apr 25, 2006 13:11

Re: Running old QBasic code in FB

Post by Triopstor »

Hello Again!

I've isolated a problem with Error Handling.

Code: Select all

#lang "QB"

DECLARE SUB Initialization ()
'DECLARE SUB ErrorHandler3'()

OPTION BASE 1

DIM SHARED Col(10), Row(10), v$(10), D$(10), I$(10), R$(10, 1)
DIM SHARED DR$

DR$="InptFile"


CALL Initialization

ErrorHandler3:
      'print "Debug line - Were here ErrorHandler3":Sleep:STOP
   IF ERR = 53 THEN 'ERR = 53 File Not Found
      BEEP
      R$(1, 1) = DR$ + ".ZIP"
      A1 = INSTR(1, R$(1, 1), ".")
      OPEN MID$(R$(1, 1), 1, A1 - 2) + ".DAT" FOR INPUT LOCK WRITE AS #1
      RESUME NEXT
   ELSE
      'some other error, so print message and abort
      PRINT "Unrecoverable error--"; ERR
      'ON ERROR GOTO 0
      STOP: RESUME
   END IF


SUB Initialization
'  Calculate number of records of file to extract
'  ----------------------------------------------
RecNum = 0
ON ERROR GOTO ErrorHandler3
OPEN MID$(R$(1, 1), 1, A1% - 2) + ".DAT" FOR INPUT LOCK WRITE AS #1
DO
  C$ = "": LINE INPUT #1, C$
  IF MID$(C$, 23, 3) <> "," + CHR$(34) + "S" THEN RecNum = RecNum + 1
LOOP UNTIL EOF(1) = -1
CLOSE #1
END SUB


Running the above code gives an error of "error label - used but not defined" This is line 36 in SUB Initialization "ON ERROR GOTO ErrorHandler3

Can't get it right. I've tried a few things -remming out this, changing order of code for ErrorHandler3, putting SUB in front of ErrorHandler3 . Maybe I need to compile with the suffix -ex I don't know. I need a better example in the help guide. Appreciate the help
Post Reply