Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DIM - AS - VARIABLE TYPE likely bug
#11
(05-03-2024, 02:00 PM)bartok Wrote:
(05-03-2024, 12:59 PM)bplus Wrote:
Quote:but we incur into a "Name already in use" error if we write:

DIM A AS INTEGER
DIM A AS STRING

ah, there is no suffix for qb64 to tell the differenece between the 2 a's

this lets you define everything as a type unless you explicitly say something different
DefInt A-Z
Dim A As String

I have understood. 
IMO, QB could have been programmed in a way in which the suffix of the varible "A" definied with "DIM A AS INTEGER" was "%", as it is in the case of "DIM A%", considered that in both the ways we define exactly the same variabile. But QB is conceived so that we can have:
DIM A%
DIM A!
DIM A$
DIM A&
etc,
but we cannot have
DIM A AS INTEGER
DIM A AS SINGLE
DIM A AS STRING
DIM A AS LONG
etc.


The only reason I found for this, is that if we use "AS" instead of the suffixes, then in the code is possible to use variable name without having to add the suffix each time and, in order to be able to do that, only one "A" must be allowed.

But finally, even if at first this could seem a simplification, actually I prefer to use suffixes for 2 reasons:
1. We could have variables that actually are exactly the same thing and therefore should have the same name. For example a coordinate X, that it is integer(%) or single(!) depending if we are on a view port coordinate or in physical screen coordinate. So, using (AS) it will be compulsory to use different variable name, but I don't find anything clearer than the possibility of using X% and X!;

2. I find that presence of the suffixes actually makes the code more readable.

So, I think is preferable to DIM variables and arrays with suffixes, avoiding the use of AS.

QB is conveieved so that you can have a shortcut and reduce repetitive typing injuries to yourself.

There is absolutely nothing stopping you from doing the following:

DIM A AS INTEGER
DIM A!, A#, A%%

Now, there is absolutely nothing stopping you from using A, A%, A!, A#, and A%% all in your program.

Code: (Select All)
Dim a As Integer
Dim a!, a#, a%%

a% = 1
a! = 2
a# = 3
a%% = 4

Print a%
Print a!
Print a#
Print a%%

Print
Print
Print a

No issues whatsoever with the above.  All are DIMMED.  All are usable.

The only thing that DIM A AS INTEGER is, is telling the compiler that A -- without any suffix -- is going to be an integer and thus represent the same thing as A%, saving you the need to type that % symbol everytime you use A alone.

And A, with no suffix, can't be INTEGER, SINGLE, DOUBLE, BYTE all at the same time!!  It can only be one of them.  By default, it's SINGLE.  By using a DIM, you make it whatever you want.

That's all there is to it!
Reply


Messages In This Thread
DIM - AS - VARIABLE TYPE likely bug - by bartok - 05-03-2024, 06:59 AM
RE: DIM - AS - VARIABLE TYPE likely bug - by SMcNeill - 05-03-2024, 07:48 PM



Users browsing this thread: 14 Guest(s)