counting_pine wrote:I can't reproduce this.
Code: Select all
Sub Alpha (Byref test As String)
test = "Hello"
Print test
End Sub
Sub Beta ()
Dim testing As String
testing="Tom"
alpha (testing)
Print testing
End Sub
Dim teststr As String
teststr = "erase"
alpha (teststr)
Print teststr
beta
I get all Hellos.
What version of FB are you using? Is that the entire code?
Hello, I'm using the lastest version on this site version 0.20. I don't have any patches.
All I can tell you is this sub ...
Code: Select all
Sub get_name ()
prt("Enter your player's name [press <RETURN> when finished]",22,3)
get_string(py.misc.name,3,11,24)
py.misc.name=temp_str1 ' patch to fix broken byRef string bug
clearscn(21,1)
End Sub
When it calls this function.... the byref does not work. But if I call this function from the main code it does work.
Code: Select all
function get_string (ByRef in_str As String,row As integer,column As integer,slen as integer ) As Byte ' ------- Patched for ByRef bug in FB
Dim start_col As Integer
Dim END_col As Integer
Dim i1 as Integer
Dim x As String
Dim tmp as vtype
Dim flag As Byte
Dim aborter As Byte
Dim VALUE As Byte
Dim Start_column As Integer
start_column = column
aborter = 0
flag = 0
in_str = ""
put_buffer(pad(in_str," ",slen),row,column)
put_buffer("",row,column)
start_col = column
END_col = column + slen - 1
put_buffer("_",row,column)
Do
Do
x=InKey
If x="" Then Sleep 10
Loop Until (x<>"")
If Asc(x)=3 Or Asc(x)=25 Or Asc(x)=26 Or Asc(x)=27 Then
put_buffer(" ",row,column)
aborter=1
Else
If Asc(x)=13 Then
put_buffer(" ",row,column)
flag=1
Else
If Asc(x)=8 Then
column=column-1
If column<start_column Then column=start_column
put_buffer("_ ",row,column)
in_str = Left(in_str,Len(in_str)-1)
Else
tmp = x
put_buffer(tmp+"_",row,column)
in_str = in_str + tmp
column = column + 1
if (column > END_col) Then
flag =1
put_buffer(" ",row,column)
End If
EndIf
EndIf
EndIf
Loop until (flag=1 or aborter=1)
If (aborter=1) Then
VALUE = 0
Else
i1 = Len(in_str)
If (i1 > 1) Then
Do while ((RIGHT(in_str,1) = " ") and (i1 > 1))
i1 = i1 - 1
in_str = Left(in_str,i1)
Loop
EndIf
VALUE = 1
EndIf
temp_Str1=in_str
Return VALUE
end Function
If I put a print in_str right before the return I see that it has the right value.
I call this function from main program, ie not another sub or function, it returns the value.
But when called from a sub as above. Nothing is returned.
Keep in mind this isn't my code. I just ported it as closely as I could from the Pascal code.
I literally just taking the original code, and making it work in Free Basic.
As I said it didn't see this behavor from all of my subs or functions. I'll release my converted code in a couple of weeks. You can study it all your want!!! However the above sub, when call this function, always failed to return a string value.