SHARED statement
#2
I did not think Shared could be used in Subroutines but it appears so...

Anyway the 4th method makes sense to me because a, b are default single as "Shared" in the 4th Method of Sub
Quote:SHARED a, b, c AS INTEGER ' only the value of 'c' is passed, 'a' and 'b' are zero.

Here is a further mod to show what I see:
Code: (Select All)
Dim As Integer a, b, c

a = 10
b = 20
c = 30

Mysub
Print a, b, c

Sub Mysub ()

    '---------------
    ' ** Method 1 ** ------------> ** THIS WORKS **
    '---------------

    'SHARED AS INTEGER a, b, c ' all SHARED on a single line

    '---------------
    ' ** Method 2 ** ------------> ** THIS WORKS **
    '---------------

    'SHARED a AS INTEGER ' all SHARED on a separate line
    'SHARED b AS INTEGER
    'SHARED c AS INTEGER

    '---------------
    ' ** Method 3 ** ------------> ** THIS WORKS **
    '---------------
    'SHARED AS INTEGER a, b ' two different SHARED alternatives
    'SHARED c AS INTEGER

    '---------------
    ' ** Method 4 ** ------------> ** THIS DOES -NOT- WORK **
    '---------------

    Shared a, b, c As Integer ' only the value of 'c' is passed, 'a' and 'b' are zero.

    '-----------------------------------------------------------------------------------
    ' Method 4 is not a valid alternative to SHARED listed in the Wiki and should
    ' therefore not work. However, I would think an error would be generated in the IDE
    ' or at least at run-time when SHARED is attempted to be used in this manner?
    '-----------------------------------------------------------------------------------
    a = 1.111: b = 2.222
    Print a, b, c

End Sub
b = b + ...
Reply


Messages In This Thread
SHARED statement - by TerryRitchie - 03-14-2023, 07:16 PM
RE: SHARED statement - by bplus - 03-14-2023, 08:01 PM
RE: SHARED statement - by RhoSigma - 03-14-2023, 10:38 PM
RE: SHARED statement - by Kernelpanic - 03-14-2023, 11:33 PM
RE: SHARED statement - by SMcNeill - 03-15-2023, 01:43 AM
RE: SHARED statement - by TerryRitchie - 03-15-2023, 03:18 AM
RE: SHARED statement - by mnrvovrfc - 03-15-2023, 12:23 PM
RE: SHARED statement - by SMcNeill - 03-15-2023, 02:07 PM
RE: SHARED statement - by TempodiBasic - 03-19-2023, 11:51 PM



Users browsing this thread: 2 Guest(s)