byref fails with fixed length string

Please report bugs

byref fails with fixed length string

Postby bobr » Wed Jun 22, 2011 8:03 pm

If you declare a string as:
Dim fred as string * 256
' Then call a function
sid(fred)

' where the function sid() is declared as:
function sid(byref data as string)
data = "a bit of text"
end function

the text string isn't passed back to the variable in the call. If, however, fred is declared as:
Dim fred as string

the text string is passed back correctly.
bobr
 
Posts: 31
Joined: Fri Mar 18, 2011 10:30 pm

Re: byref fails with fixed length string

Postby Slowdown » Thu Jun 23, 2011 6:06 pm

No need for Byref.
If you use a function do it like this,
Code: Select all
Dim fred as string * 256

Private Sub Form_OnOpen()
  fred = "this a bit of text"
  print sid(fred) 
End Sub

Function sid(data as String) As String
  Return data
End Function


This will be returned as expected.
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: byref fails with fixed length string

Postby bobr » Thu Jun 23, 2011 7:07 pm

Yes, I know that I can pass the value back by "return". My little example was just to show what goes wrong. If you are calling a function that returns more than one value, you need to use "byref". My point is that if you are passing a fixed length string, the "byref" value doesn't get passed back!
bobr
 
Posts: 31
Joined: Fri Mar 18, 2011 10:30 pm

Re: byref fails with fixed length string

Postby Henning » Thu Jun 23, 2011 9:29 pm

My guess is you have to live with one of two work-arounds.

1. Copy Fred to a temp string, and then back again.

2. Make Fred Public, and not pass it at all.

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden


Return to Bug-Reports

cron