Author Topic: The revolutionary guide to QBASIC-Is it OK to share my BCX adaptations here?  (Read 1565 times)

djsb

  • Full Member
  • ***
  • Posts: 130
    • View Profile
I've just bought myself a copy of The Revolutionary guide to QBASIC. Hoping to have some fun with trying out the code in the book, and wanted to ask if it's OK to share my efforts at trying out the examples from the book here? The code will obviously need to be adapted in some way, but I'm hoping not too much. Is it OK to post the source code here? I have copied the source code from the book's floppy disk. Is anyone aware of this book or has anyone read it? Thanks.
« Last Edit: May 10, 2024, 02:45:00 AM by djsb »

morgan

  • Newbie
  • *
  • Posts: 29
    • View Profile
it will be fun, thanks.

djsb

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Here attached is the original code (13 examples in total for this chapter) for Chapter 1 of the book. On a casual inspection of the first chapter "Specifying a data block - record" in chapter 1 example 3 may be a problem. Maybe there is a way around it?

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2392
    • View Profile
BCX requires that you dimension all variables - see DIM, RAW, LOCAL, GLOBAL, STATIC in the BCX Help file

You will need to change any QB code that uses reserved BCX keywords as variables, like PI, HEX, and so on.

BCX variables are case sensitive but keywords are not. 

I haven't looked at all the QB source code but it's also possible that the QB code might also have variable names or
CONST names that conflict with c/c++ and Windows API names, so those might need to be tweaked also.

All in all, it's a good exercise (for you) to acquaint yourself with both languages and especially the BCX Help file.


djsb

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Thanks  :)

I'm having problems with this TYPE (or DATA block) example

Code: [Select]
REM Specifying a data block - record
REM \CHAP_1\CH1_3.BAS

CLS
TYPE vb
DIM s AS STRING * 10
DIM n AS INTEGER
DIM dn AS LONG
DIM x AS SINGLE
DIM dx AS DOUBLE
END TYPE

DIM VarBlock AS vb
VarBlock.s = "QWERTY"
vb.n = 3
vb.dn = 123456789
vb.x = VB.DN
vb.dx = 1 / VB.N
PRINT VarBlock.s, vb.n, vb.dn
PRINT vb.x, vb.dx

PAUSE

END

I'm getting the following error messages

Code: [Select]
BCX BASIC to C/C++ Translator (c) 1999-2024 by Kevin Diggins
Version 8.0.8 (12/27/2023) Compiled using MS Visual C++ for 64-bit Windows Systems
[Lines In: 25] [Lines Out: 326] [Statements: 19] [Time: 0.02 Sec's]
BCX translated [Ch1_3_Bcx.Bas] to [Ch1_3_Bcx.C] for a C Compiler
**************************************************************************
Pelles C is compiling [ "C:\BCX\REVQB\CHAP1\CH1_3_BCX".c ] as a 64-bit CONSOLE application.
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(325): error #2001: Syntax error: expected ';' but found '.'.
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(325): error #2048: Undeclared identifier 'n' (did you mean: ?).
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(326): error #2001: Syntax error: expected ';' but found '.'.
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(326): error #2048: Undeclared identifier 'dn' (did you mean: ?).
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(327): error #2001: Syntax error: expected ';' but found '.'.
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(327): error #2048: Undeclared identifier 'x' (did you mean: ?).
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(327): error #2048: Undeclared identifier 'VB' (did you mean: ?).
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(327): error #2113: Left operand of '.' has incompatible type 'int'.
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(328): error #2001: Syntax error: expected ';' but found '.'.
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(328): error #2048: Undeclared identifier 'dx' (did you mean: ?).
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(328): error #2113: Left operand of '.' has incompatible type 'int'.
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(329): error #2066: Invalid use of type name 'vb'.
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(329): error #2066: Invalid use of type name 'vb'.
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(330): error #2066: Invalid use of type name 'vb'.
C:\BCX\REVQB\CHAP1\CH1_3_BCX.c(330): error #2066: Invalid use of type name 'vb'.
POLINK: fatal error: File not found: 'C:\BCX\REVQB\CHAP1\CH1_3_BCX.obj'.


Can anyone help? Thanks.

David.

jcfuller

  • Sr. Member
  • ****
  • Posts: 415
    • View Profile
Try this.

James

Code: [Select]
'REM Specifying a data block - record
'REM \CHAP_1\CH1_3.BAS

CLS
TYPE vb
DIM s AS STRING * 10
DIM n AS INTEGER
DIM dn AS LONG
DIM x AS SINGLE
DIM dx AS DOUBLE
END TYPE

DIM VarBlock AS vb
VarBlock.s = "QWERTY"
VarBlock.n = 3
VarBlock.dn = 123456789
VarBlock.x = VarBlock.dn
VarBlock.dx = 1 / VarBlock.n
PRINT VarBlock.s, VarBlock.n, VarBlock.dn
PRINT VarBlock.x, VarBlock.dx

PAUSE

END
[code]

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2392
    • View Profile
This is also valid:

TYPE vb
    s AS STRING * 10
    n AS INTEGER
    dn AS LONG
    x AS SINGLE
    dx AS DOUBLE
END TYPE

djsb

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Thanks  :)

djsb

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Here is Chapter 1 example 4

Code: [Select]
'REM Demonstration of character extracting functions
'REM \CHAP1\CH1_4.BAS
 
CLS
DIM V$ = "OneTwoThree"
PRINT LEFT$(V$, 3)
PRINT MID$(V$, 4, 3)
PRINT RIGHT$(V$, 5)

PAUSE

END

I get the following errors

Code: [Select]
BCX BASIC to C/C++ Translator (c) 1999-2024 by Kevin Diggins
Version 8.0.8 (12/27/2023) Compiled using MS Visual C++ for 64-bit Windows Systems
[Lines In: 13] [Lines Out: 346] [Statements: 8] [Time: 0.02 Sec's]
BCX translated [Ch1_4_Bcx.Bas] to [Ch1_4_Bcx.C] for a C Compiler
**************************************************************************
Pelles C is compiling [ "C:\BCX\REVQB\CHAP1\CH1_4_BCX".c ] as a 64-bit CONSOLE application.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(248): warning #2099: Missing type specifier; assuming 'int'.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(248): warning #2095: Missing type specifier for parameter 2; assuming 'int'.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(248): error #2001: Syntax error: expected ')' but found 'string constant'.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(248): error #2119: Redeclaration of 'strcpy', previously declared at C:\PellesC\Include\intrin.h(89).
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(291): error #2140: Type error in argument 1 to 'strcpy'; expected 'char' but found 'char *'.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(291): error #2140: Type error in argument 2 to 'strcpy'; expected 'int' but found 'const char *'.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(291): error #2060: Invalid return type; expected 'char *' but found 'int'.
POLINK: fatal error: File not found: 'C:\BCX\REVQB\CHAP1\CH1_4_BCX.obj'.

I'd try to solve this myself but I've looked at the help file and there arent any examples for LEFT$. There is one example fro MID$ and I've not looked at RIGHT$. Being full of a cold doesn't help. Thanks.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2392
    • View Profile
From Bcx Help:

LOCAL quoted literal string initialized declarations inside a SUB or FUNCTION can be made. This will not work for GLOBAL strings. Neither will it work for dynamic strings that are created using any of the memory allocation functions: malloc/calloc/realloc. String functions and concatentations are not allowed -- only plain quoted string literals will work, like in the examples below:


 $BCXVERSION "7.7.2"
 
 CALL OnlyInProcedures()
 
 SUB OnlyInProcedures()
   DIM A$     = "This is handy!"
   DIM RAW B$ = "This is too!"
   LOCAL C$   = "This also works!"

 
   PRINT A$
   PRINT B$
   PRINT C$
END SUB

Result:

 This is handy!
 This is too!
 This also works!

=======================================

So, as this pertains to your problem, you must do this:


' REM Demonstration of character extracting functions
' REM \CHAP1\CH1_4.BAS

CLS
DIM V$
V$ = "OneTwoThree"

PRINT LEFT$(V$, 3)
PRINT MID$(V$, 4, 3)
PRINT RIGHT$(V$, 5)

PAUSE

END
« Last Edit: May 18, 2024, 02:34:18 PM by MrBcx »

djsb

  • Full Member
  • ***
  • Posts: 130
    • View Profile
Thank you again.