PDA

View Full Version : FreeBasic QB Mode



primo
30-03-2022, 16:44
if you want to use freebasic to run quick basic programs, you must add this '$lang: "qb" to the top of the code
yes there is " ' "
only '$lang: "qb" will work to enable QB mode albeit there are several suggestions in the forums but does not work
examples:
C:\FreeBASIC\examples\manual\control\gosub.bas

'' Compile with -lang qb
'$lang: "qb"
GoSub message
End
message:
Print "Welcome!"
dim s as string
input "press enter to exit ", s
Return

example 2:

'$lang: "qb"
DECLARE FUNCTION Add! (num1!, num2!)
PRINT Add(10, 7)
INPUT "Press ENTER to exit", C$

FUNCTION Add (num1, num2)
Add = num1 + num2
END FUNCTION

the above examples will work from within the fbide. but i can't make it to run from inside thinbasic #Compiled #Endcompiled . thinbasic seems confused by the '$lang: "qb"

example 3:
caesar cipher CIPHER1.BAS from page 46 of the book Learn Encryption Techniques with BASIC and C++ ( 1998 ) the basic examples are for QB with many nice Goto and Gosub functions.
https://archive.org/details/LearnEncryptionTechniquesWithBasicAndC/page/n46/mode/2up

REM PROGRAM CIPHER1.BAS
' Compile with -lang qb

'$lang: "qb"
DIM PLAINTEXT$(25), CIPHERTEXT$(25)
GOSUB INITIALIZE
1 INPUT "Enter UPPERCASE Alphabetic Shift Key: ", K$
FOR I = 0 TO 25
IF K$ = PLAINTEXT$(I) GOTO 2
NEXT I
PRINT "You must enter a letter from A to Z"
GOTO 1
2 REM Position I represents shift key letter
GOSUB FORMCIPHER
GOSUB PRTOUT
INPUT "Press ENTER ", C$
STOP
INITIALIZE:
REM Initialize plaintext values
FOR I = 0 TO 25
READ PLAINTEXT$(I)
NEXT I
DATA "A","B","C","D","E","F","G","H","I","J","K","L","M","N"
DATA "O","P","Q","R","S","T","U","V","W","X","Y","Z"
RETURN
FORMCIPHER:
REM Routine to form CIPHERTEXT alphabet based upon defined shift key
J = I + 1
FOR K = 0 TO 25
CIPHERTEXT$(K) = PLAINTEXT$((K + J) MOD 26)
NEXT K
RETURN
PRTOUT:
REM Print results
FOR I = 0 TO 25
PRINT CIPHERTEXT$(I);
NEXT I
PRINT
RETURN
END