Hi guys
thanks to all you to read this post...
I have tried to emulate an ASCII screen in 32bit to create a light moving with arrows...
here isCode: QB64: [Select]
Setup CalculateRows col = 1 row = 10 min = 1 max = 44 up = 1 down = 23 MoveLight row, col, 10, 1, 1 _LIMIT 15 outputs row, col, min, max, -steps outputs row, min + col, max, min, steps outputs row + 1, col, min, max, -steps outputs row + 1, min + col, max, min, steps outputs row + 2, col, min, max, -steps outputs row + 2, min + col, max, min, steps LOCATE row, col SUB Setup r = 255 b = 255 g = 255 counter = 1 NEXT counter SUB CalculateRows NEXT x SLEEP 3
Hi Tempodi,
I just started using QB64. Regarding your SUB version, how about using this as the first line in the code:
DEFINT A-Z
I believe that would automatically define all variables as integers unless otherwise DIM'ed as longs.
Then the line:
SUB MoveLight (row AS INTEGER, col AS INTEGER, min AS INTEGER, max AS INTEGER, steps AS INTEGER)
could be simplified as:
SUB MoveLight (row, col, min, max, steps)
It would also negate the need for the lines:
DIM row AS INTEGER, col AS INTEGER
DIM min AS INTEGER, max AS INTEGER, up AS INTEGER, down AS INTEGER
and just use:
col = 1
row = 10
min = 1
max = 44
up = 1
down = 23
I'm new to QB64 so I'm not sure if doing the above has any cons when most variables are integers.
PS: I'm learning from your code as a clean example of how to use SUBS.
I just started using QB64. Regarding your SUB version, how about using this as the first line in the code:
DEFINT A-Z
I believe that would automatically define all variables as integers unless otherwise DIM'ed as longs.
Then the line:
SUB MoveLight (row AS INTEGER, col AS INTEGER, min AS INTEGER, max AS INTEGER, steps AS INTEGER)
could be simplified as:
SUB MoveLight (row, col, min, max, steps)
Personally, I prefer to make SUBs with the variables explicitly defined, such as in the original.
The reason?
I prefer modular coding techniques and want to make my subs and functions as simple as possible to move from one program to another.
Let’s say I have a program like this:
DEFINT A-Z
..... stuff
SUB Whatever (x, y)
.....more stuff
END SUB
Now, x and y are integers and everything runs just fine...
BUT....
What if I want to reuse that sub in other code that starts with _DEFINE A-Z AS _FLOAT? Will it still function and work as intended? Will it generate rounding errors over time? Can I now get edge-case exceptions where 3.2 + 4.4 = 7.6, which might round to 8??
By explicitly defining SUB Whatever (x AS INTEGER, y AS INTEGER), it can be ripped out and reused in another program, with fewer concerns and issues.
DIM SHARED A AS LONG, whites(1 TO 50) AS LONG, Black AS LONG
DIM SHARED r AS INTEGER, g AS INTEGER, b AS INTEGER, counter AS INTEGER
2. the second reason is that also if you use DEFINT or DEFSTR or someother definition, you must DIM SHARED or COMMON variables
Quote
DIM SHARED A AS LONG, whites(1 TO 50) AS LONG, Black AS LONG
DIM SHARED r AS INTEGER, g AS INTEGER, b AS INTEGER, counter AS INTEGER
2. the second reason is that also if you use DEFINT or DEFSTR or someother definition, you must DIM SHARED or COMMON variablesI'm trying to say that also if I use DEFINT (or another definition type of data) when I need Global variables I must declare them also if the type has been declare before with the command of type definition...