PicoMite V6.00.02 release candidates - all versions


Author Message
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 601
Posted: 02:37am 07 Jun 2025      

  phil99 said  Having trouble with BYVAL in latest RC. According to the manual changing the value in this test Sub should leave the original value unchanged. Or have I got it wrong?
If that is the case an example in the manual would make it clearer.
> LIST
' Test prog 1
Dim integer a=5
 Print "a =";a
test

Sub test(BYVAL a As integer)
 If a = 5 Then
  a = 10
  Print "In Sub a =";a
 EndIf
End Sub

Print "After Sub a =";a
End
>
>
> RUN
a = 5
In Sub a = 10
After Sub a = 10
>


You're not using a as a parameter when you call test. Change test to test a.
If a isn't a parameter, it's global unless you define it as local in the sub.

> LIST
' Test prog 1
Dim integer a=5
 Print "a =";a
test a

Sub test(BYVAL a As integer)
 If a = 5 Then
  a = 10
  Print "In Sub a =";a
 EndIf
End Sub

Print "After Sub a =";a
End
>
>
> RUN
a = 5
In Sub a = 10
After Sub a = 5
>