10-18-2023, 04:43 PM
(10-18-2023, 03:58 PM)Kernelpanic Wrote:Quote:@bplus - 5) Arrays should be hard indexed. Don't DIM SHARED Array(10); instead DIM SHARED Array(0 To 10). This prevents incompatibility if the user has OPTION BASE 1 in effect.Wether that makes sense? If you declare an array with A( 0 To 10) you have eleven array elements, despite OptionBase 1.
To prevent this you have to fill the array with 1 to 10. With it a declaration with A(0 To 10) has no practical use.
Code: (Select All)
'18. Okt. 2023
Option _Explicit
Option Base 1
Dim As Integer feld(0 To 10)
Dim As Integer feld2(0 To 10)
Dim As Integer feld3(10)
Dim As Integer a, b, c, d
Locate 3, 3
For a = 0 To 10
feld(a) = a
Print Using "## "; feld(a),
Next
Locate 5, 3
For b = 1 To 10
feld2(b) = b
Print Using "## "; feld2(b),
Next
Locate 7, 3
For c = 1 To 10
feld3(c) = c
Print Using "## "; feld3(c),
Next
'Error - Out of range.
Locate 9, 3
For d = 0 To 10
feld3(d) = d
Print Using "## "; feld3(d),
Next
End
You must see it from the library implementors view:
If I need an array in one of my library functions which needs to have 5 elements and I do that by writing DIM a(4), hence index 0-4, but the user of my library is used to code with OPTION BASE 1 effective, then my DIM a(4) would only create a 4 elements array (1-4) and my function would error out when trying to access a(0).
The library does not know the preference of the one or other user, hence the library must make sure it works with both settings which can be achived with DIM a(0 TO 4).
GuiTools, Blankers & other Projects:
https://qb64phoenix.com/forum/forumdisplay.php?fid=32
Libraries & useful Functions:
https://qb64phoenix.com/forum/forumdisplay.php?fid=23
https://qb64phoenix.com/forum/forumdisplay.php?fid=32
Libraries & useful Functions:
https://qb64phoenix.com/forum/forumdisplay.php?fid=23