09-21-2025, 07:19 PM
And it's way out!
So here is a method to use type variables, and still work with arrays, even though for some ****ing reason we can't assign arrays to a TYPE.
So we don't have to declare our array in the main or pass it into the sub routine. Rather, the sub routine builds the arrays, and keeps them in memory. Now we just need to pass an index, as a type variable, so the sub routine knows which set of variables to pull from memory.
In this example, we have three words displayed on three text lines, and because of the sub routine memory, each can be moved independently. The conventional method would have required all of our variables built as arrays.
What do you guys think? And if you like it, please contribute to the "Buy Steve an aspirin" patreon account.
Pete
So here is a method to use type variables, and still work with arrays, even though for some ****ing reason we can't assign arrays to a TYPE.
Code: (Select All)
Randomize Timer
Type foo
x As Integer
y As Integer
one As Integer
two As Integer
three As Integer
ind As Integer
way As Integer
object As String
End Type
Dim hp As foo
hp.object = "12345"
For hp.ind = 1 To 3
Select Case hp.ind
Case 1: hp.y = 1: hp.x = 35: hp.one = 1: hp.two = 2: hp.three = 3: hp.object = "first"
Case 2: hp.y = 3: hp.x = 35: hp.one = 10: hp.two = 20: hp.three = 30: hp.object = "second"
Case 3: hp.y = 5: hp.x = 35: hp.one = 100: hp.two = 200: hp.three = 300: hp.object = "third"
End Select
pete hp
Next
_Delay 1.5: hp.way = 1
Do
hp.ind = Int(Rnd * 3) + 1
If Int(Rnd * 10) = 1 Then hp.way = -hp.way
pete hp
_Limit 30
Loop
Sub pete (hp As foo)
Static ArrayCounter$, oldind, i
Static way(), y(), x(), one(), two(), three(), object$()
i = hp.ind
If InStr(ArrayCounter$, LTrim$(Str$(i)) + ",") = 0 Then
ArrayCounter$ = ArrayCounter$ + LTrim$(Str$(i)) + ","
ReDim _Preserve way(i), y(i), x(i), one(i), two(i), three(i), object$(i)
hp.way = way(i): y(i) = hp.y: x(i) = hp.x: one(i) = hp.one: two(i) = hp.two: three(i) = hp.three: object$(i) = hp.object
End If
hp.y = y(i): hp.x = x(i): hp.one = one(i): hp.two = two(i): hp.three = three(i): hp.object$ = object$(i)
way(i) = hp.way
If way(i) < 0 Then
If hp.x + way(i) > 0 Then hp.x = hp.x + way(i)
Else
If way(i) > 0 Then If hp.x + way(i) + Len(hp.object) <= _Width Then hp.x = hp.x + way(i)
End If
Color 8 - hp.ind
Locate hp.y, 1: Print Space$(_Width);: Locate hp.y, hp.x: Print hp.object$;
oldind = hp.ind: x(i) = hp.x
End Sub
So we don't have to declare our array in the main or pass it into the sub routine. Rather, the sub routine builds the arrays, and keeps them in memory. Now we just need to pass an index, as a type variable, so the sub routine knows which set of variables to pull from memory.
In this example, we have three words displayed on three text lines, and because of the sub routine memory, each can be moved independently. The conventional method would have required all of our variables built as arrays.
What do you guys think? And if you like it, please contribute to the "Buy Steve an aspirin" patreon account.
Pete

