QB64 Phoenix Edition
SHARED Array values with SUBs and FUNCTIONs - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11)
+--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2)
+--- Thread: SHARED Array values with SUBs and FUNCTIONs (/showthread.php?tid=1770)

Pages: 1 2


RE: SHARED Array values with SUBs and FUNCTIONs - bplus - 06-22-2023

KP "No!"  no my code runs fine!

Why are you changing the ReDim's to 2 for lower bound?
   

My code ran fine here is indy test of it to show the final values as correct:
Code: (Select All)
Dim Shared mySharedArray(1 To 20) As Long

For i = 1 To 20
    mySharedArray(i) = i * i
Next

ReDim out10(1 To 10) As Integer
first10Plus5 = first10squaresPlus&(5, out10())
For i = 1 To 10
    Print i ^ 2 + 5, out10(i)
    tot2 = tot2 + i ^ 2 + 5
Next
Print "Total was: "; first10Plus5
Print "Tot2 check my sub total"; tot2

Function first10squaresPlus& (X, outputFirst10() As Integer)
    For i = 1 To 10
        outputFirst10(i) = mySharedArray(i) + X
        tot& = tot& + outputFirst10(i)
    Next
    first10squaresPlus& = tot&
End Function
   


RE: SHARED Array values with SUBs and FUNCTIONs - mnrvovrfc - 06-22-2023

Things should be done like Jack's example if the subprogram has to handle arrays like that. Cannot assume 0 or 1 or any other value as the lowest subscript, just like trying to decide the upper subscript for a given program using the same subprogram.

There are too many programs I've seen that assume only zeroth subscript, to then use REDIM _PRESERVE on it, but even so, a subprogram should always consult with LBOUND() and UBOUND() for the limits.