Variable not explicitly defined

Previous topic - Next topic

pnunbe

 Hi,
I have a program where, before the game loop, there is the following statement:
DIM classe$[2][2]
When I compile the program the following message appears:
----------------------------------------
Random.gbas"(32) error : variable is not explicitly defined : classe$
----------------------------------------
The strangest thing is that in one of the sample programs (The First Game) the same structure does not give rise to any problem.
What did I miss?
Best regards


kanonet

You either need to define the variable 1st, by using using LOCAL/GLOBAL/STATIC, or turn of explicit declarations in the project options. Please use the search funtions if you need more informations about this issue, there are many threads about this.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

bigsofty

Make sure the variable is not locally defined in a function elsewhere.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Schranz0r

Hehe, ok :)
Like kanonet say:

Code (glbasic) Select


LOCAL classe$
DIM classe[2][2]



@ Gernot( if you read this) :

Is there any way to do something like ( v11 :P ):

Code (glbasic) Select

GLOBAL DIM classe[2][2]


?? ;)
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

BdR

In the GLBasic menu, go to "Project" -> "Options" and there is a checkbox "Explicit declarations". If this is checked, you must declare all your variables. You can uncheck it and you won't get the error message. However, I would recommend you always have this option enabled (checked).

For example, look at the following code:
Code (glbasic) Select
mystring$ = "test"
PRINT mysting$, 10, 10


With "Explicit declarations" enabled, you'll get an error and you'll quickly notice the typo "mysting$" instead of "mystring$". When it's disabled it will just compile, automatically create 2 variables "mysting$" and "mystring$" and the code doesn't print anything, and then you have to go find the mistake yourself. ;)

doimus

Quote from: BdR on 2013-Feb-04

With "Explicit declarations" enabled, you'll get an error and you'll quickly notice the typo "mysting$" instead of "mystring$". When it's disabled it will just compile, automatically create 2 variables "mysting$" and "mystring$" and the code doesn't print anything, and then you have to go find the mistake yourself. ;)

Oh yeah... makes me think of Python... Beautiful, powerful scripting language. But all hell breaks loose if you have a typo in variable name or wrongly placed whitespace indent.  =D

Then there are C style languages where you spend more time writing declarations than actual implementations.

And GLBasic once again sits in the golden middle!  :good: