QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: Dimster on May 21, 2019, 02:45:27 pm
-
I'm running into a situation where I think OPTION BASE 1 may help however the wiki seems to suggest that OPTION BASE affects ALL the Dimensioned arrays. Is there a way to have it apply to only 1 of many arrays? It doesn't look like it can be contained within a subroutine.
-
You can DIM an array to any lower to upper index.
-
Hi bplus . If you run the following code, there is no error, Text( 1 to 10) does in fact have a Text(0) = 0.
DIM Test(1 TO 10)
FOR x = 1 TO 10
Text(x) = x + 1
NEXT x
PRINT
PRINT "The value of Text(0) is "; Text(0)
If I code OPTION BASE 1 before that Dim line I do get an error.
In the 2nd example (Dim Test2(-10 to 5), here again Test2(0) will have a value no matter if OPTION BASE 1 is stated or not.
So what I'm looking to do would be something like this
DIM Test2(-10 TO 5)
OPTION BASE 1
DIM Test(1 TO 10)
Where the OPTION BASE 1 would apply only to the Array which would not have a (0). This small example would suggest that all arrays Dimensioned prior to the OPTION BASE statement would have a (0) whereas all arrays Dimensioned after the OPTION BASE 1 statement would not have a (0). I have oh so many Dimensioned Arrays in my program. I never thought about partitioning them into BEFORE and AFTER an Option statement.
-
Hi bplus . If you run the following code, there is no error, Text( 1 to 10) does in fact have a Text(0) = 0.
DIM Test(1 TO 10)
FOR x = 1 TO 10
Text(x) = x + 1
NEXT x
PRINT
PRINT "The value of Text(0) is "; Text(0)
If I code OPTION BASE 1 before that Dim line I do get an error.
In the 2nd example (Dim Test2(-10 to 5), here again Test2(0) will have a value no matter if OPTION BASE 1 is stated or not.
So what I'm looking to do would be something like this
DIM Test2(-10 TO 5)
OPTION BASE 1
DIM Test(1 TO 10)
Where the OPTION BASE 1 would apply only to the Array which would not have a (0). This small example would suggest that all arrays Dimensioned prior to the OPTION BASE statement would have a (0) whereas all arrays Dimensioned after the OPTION BASE 1 statement would not have a (0). I have oh so many Dimensioned Arrays in my program. I never thought about partitioning them into BEFORE and AFTER an Option statement.
There is a difference between words Test and Text. I do that all the time too! :)
Also arrays up to length 10 don't need to be DIM.
[ This attachment cannot be displayed inline in 'Print Page' view ]
-
Ya, I caught that typo right after I posted. Dim MyArr (1 to 100) does eliminate the (0) index. So far it also appears I can place the OPTION BASE 1 statement just before all those arrays where I want the (0) index to be gone. All arrays declared before the OPTION BASE 1 do keep the (0) index. Here's hoping this change not only doesn't crash the program but is in fact what I'm looking for ... oh those damn unintended consequences. I appreciate the help bplus, thanks.
-
Yeah, next time pay attention to your typing instead of staring at Eliza's TTS.
Pete :D
-
{imagines someone asking Eliza are you married? What are you doing tonight? Would you like to go out for drinks? come back to my place?}
-
What's this Eliza you speak of?
-
What's this Eliza you speak of?
https://www.qb64.org/forum/index.php?topic=88.msg423#msg423
https://en.wikipedia.org/wiki/ELIZA
And latest reincarnation here:
https://www.qb64.org/forum/index.php?topic=1361.0
On the subject of OPTION BASE, I think it is only needed in QB64 to keep compatible to old QB4.5 code as you can now set the lower bound of an array to any integer you need. I wouldn't use it for any new code, don't see any advantage.
-
Ah, thanks.
I used Eliza as a kid, was pretty fun at the time. Later, on a 286 IBM PC, I found a program called "Babble" that was really amazing. It learns word patterns as it goes, I believe it uses Markov chains, and over time improves its responses. It also had a lot of speech filters, such as "Pig Latin", "Stutter", "Elmer Fudd", etc. Fun times for a kid!