[Gambas-user] Need to pass a string by ref

Oliver Stieber oliver_stieber at ...370...
Sun Jan 9 01:01:55 CET 2005


 --- Eric Damron <edamron at ...776...> wrote: 
> I'm finding not being able to pass simple datatypes
> by reference really 
> annoying.  I need to create a function that returns
> a boolean but also 
> returns a string.  In VB I would pass in a string by
> reference.  I've 
> tryed to pass in a string array but I can't seem to
> get the syntax 
> correct.  Can someone help me out.
> 
> Private Sub foo()
> 
>     Dim strS[2] as String
> 
>     strS[0] = "Some String"
>     strS[1] = ""
> 
>      if foo2(strS[]) THEN
>        ' do some stuff
>     End If
> End
> 
> private FUNCTION foo2(strString[] as string) AS
> Boolean
> 
>     strS[1] = "Some other string"
> 
>     Return TRUE
> End
> 
> 
>
I'm putting some examples of things like this together
at the moment.

You can do...
(comments are VB syntax)

'private sub vbByref()
 PUBLIC SUB vbByref()
 'dim strS as string
     DIM strS AS  String[]
     strS = NEW String[](1)
 'strS = "Some String"
     strS[0] = "Some String"

 'if byFunc(strS) then
      IF byFunc(strS) THEN
'print strS
        PRINT strS[0]
 'end if
     END IF
'end sub
 END

' private function byfunc (byref aString as string) as
boolean
 PRIVATE FUNCTION byFunc(aString AS String[]) AS 
Boolean
'aString =  "Some other string"
     aString[0] = "Some other string"
'byfunc = true
     RETURN TRUE
'end function
END

Look at "Java-like" arrays in help for more
information on the systax of arrays.
I found the mixed approach to arrays a little
confusing at first.



	
	
		
___________________________________________________________ 
ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com




More information about the User mailing list