Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Execute ???
#6
"Array1(1 to 25), Array2(1 to 85), Array3(1 to 15) etc. I have tried this before and there is no way QB64PE can create array names on the fly using concatenation."

You can do this without special array names or even multiple arrays.

I have lectured on this many times here that variable length strings can be made to function like arrays AND that to have sequence of variables ie var1, var2, var3, ...
Just use an array of variable length strings so

array$(1) = "1, 2, 3, 4, 5"
array$(2) = "1, 4, 9, 16, 25, 36"
array$(3) = "2, 4, 6"
array$(4) = "1, 1, 2, 4, 3, 9, 4, 16, 5, 25, 6, 36"
array$(5) = "a, b, c"
array$(6) = "dim, ster"
array$(7) = "b, p, l, us"

This extracts the item number from such a string:
Code: (Select All)
Function Item$ (s$, nItem As Long, delimiter$)
    Dim c As Long, d As Long, lastd As Long
    If Len(s$) = 0 Then Item$ = "": Exit Function
    lastd = 1: d = InStr(lastd, s$, delimiter$)
    While d > 0
        c = c + 1
        If c = nItem Then
            Item$ = Mid$(s$, lastd, d - lastd): Exit Function
        Else
            lastd = d + 1: d = InStr(lastd, s$, delimiter$)
        End If
    Wend
    c = c + 1
    If c <> nItem Then Item$ = "" Else Item$ = Mid$(s$, lastd, Len(s$))
End Function

The delimiter$ of the sample strings I gave is ", "

So all the 2nd items in all those strings that function like arrays are:
Code: (Select All)
array$(1) = "1, 2, 3, 4, 5"
array$(2) = "1, 4, 9, 16, 25, 36"
array$(3) = "2, 4, 6"
array$(4) = "1, 1, 2, 4, 3, 9, 4, 16, 5, 25, 6, 36"
array$(5) = "a, b, c"
array$(6) = "dim, ster"
array$(7) = "b, p, l, us"

For i = 1 To 7
    Print Item$(array$(i), 2, ", ")
Next

Function Item$ (s$, nItem As Long, delimiter$)
    Dim c As Long, d As Long, lastd As Long
    If Len(s$) = 0 Then Item$ = "": Exit Function
    lastd = 1: d = InStr(lastd, s$, delimiter$)
    While d > 0
        c = c + 1
        If c = nItem Then
            Item$ = Mid$(s$, lastd, d - lastd): Exit Function
        Else
            lastd = d + 1: d = InStr(lastd, s$, delimiter$)
        End If
    Wend
    c = c + 1
    If c <> nItem Then Item$ = "" Else Item$ = Mid$(s$, lastd, Len(s$))
End Function

   
b = b + ...
Reply


Messages In This Thread
Execute ??? - by Dimster - 01-02-2024, 09:21 PM
RE: Execute ??? - by bplus - 01-02-2024, 10:04 PM
RE: Execute ??? - by TerryRitchie - 01-02-2024, 10:38 PM
RE: Execute ??? - by SMcNeill - 01-02-2024, 10:46 PM
RE: Execute ??? - by SMcNeill - 01-02-2024, 10:53 PM
RE: Execute ??? - by bplus - 01-03-2024, 03:31 AM
RE: Execute ??? - by Dimster - 01-03-2024, 01:05 PM
RE: Execute ??? - by bplus - 01-03-2024, 04:59 PM
RE: Execute ??? - by aurel - 01-03-2024, 06:39 PM
RE: Execute ??? - by aurel - 01-03-2024, 06:46 PM
RE: Execute ??? - by Unatic - 01-03-2024, 06:57 PM
RE: Execute ??? - by Dimster - 01-03-2024, 09:52 PM
RE: Execute ??? - by aurel - 01-04-2024, 07:36 AM



Users browsing this thread: 1 Guest(s)