05-28-2025, 09:11 AM
(05-28-2025, 06:17 AM)bplus Wrote: @PhilOfPerth the way you are using Subs in place of functions makes clear how functions are so much easier to use and understand. First of all you don't have to rely on special shared variables
Replace Sub One, Two and Three in your example with 2 Functions Twice&(Number&) and StrAdd$(s1$, s2$)
and do it for allot more variables without Shared variables!
For example do this with Subs:
Code: (Select All)Print "For numbers 1 to 10, show number and Twice it:"
For i = 1 To 10
Print i; "-"; Twice&(i); " ";
Next
Print: Print
Print "For letters a - z show the letter and 2 random letters with it"
For i = 1 To 26
Print Chr$(i + 96); "-"; StrAdd$(Chr$(i + 96), StrAdd$(RndLetter$, RndLetter$)); " ";
Next
Function Twice& (Number&)
Twice& = Number& * 2
End Function
Function StrAdd$ (s1$, s2$)
StrAdd$ = s1$ + s2$
End Function
Function RndLetter$ ()
RndLetter$ = Chr$(Int(Rnd * 26) + 97)
End Function
@bplus
Thank you, but I remain unconvinced, sorry.
Do you mean something like this?
Code: (Select All)
Common Shared a
Print "For numbers 1 to 10, show number and Twice it:"
For a = 1 To 10
DublIt (a)
Next
Print "For letters a - z show the letter and 2 random letters with it"
For a = 1 To 26
AddRandom (a)
Next
Sub DublIt (a)
Print a; "-"; a * 2
End Sub
Sub AddRandom (a)
Print Chr$(a + 64);
For a = 1 To 2
Print Chr$(Rnd * 26 + 64);
Next
Print " ";
End Sub
Yes, it uses a shared variable (and probably more on larger progs), but I find these easier to manage.

Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) 
Please visit my Website at: http://oldendayskids.blogspot.com/

Please visit my Website at: http://oldendayskids.blogspot.com/