Confusion over passing by reference vs passing by value
#11
As far as I know, BASIC doesn't allow one to set a whole array to some value all at once, which is what you're trying to do here:

satz3() = "SagNiemalsNie!"

You need an index of some sort to assign the value to, such as the below here:

Code: (Select All)
Dim satz3(10) As String


Print
satz3(0) = "SagNiemalsNie!"
Satztest3 satz3() '!! Damit hat der Compiler Probleme
Print "Wert des Feldes von satz3 nach der Subroutine: ", satz3(0)

End



Sub Satztest3 (feld() As String)
    feld(0) = feld(0) + "DonaldDuck"
End Sub

Note also that you can not pass arrays via parenthesis.

Satztest3 (satz3()) -- this is bugged and produces a c++ compile failure.

Satztest3 satz3() -- change it to this and it works perfectly fine.
Reply
#12
Thumbs Up 
Thanks SMcneill! It works now.

I constructed this "Satztest3 (satz3())" according to the manual for QBasic, but I misunderstood something.
Reply
#13
I'm pretty sure this syntax is actually also a bug, identified in the previous QB64Team repository:

Code: (Select All)
feld() = feld() + "DonaldDuck"

What they said was that
feld()
was getting treated as
feld(0)
by mistake, which compiles but is obviously not what you wanted. Really this syntax should just produce a compiler error, it has no meaning.

This is the issue I was remembering, it should probably be added to the Phoenix Edition repo since it's still a bug: https://github.com/QB64Team/qb64/issues/216
Reply




Users browsing this thread: 4 Guest(s)