Discussion:
Help: FUNCTION -- return array howto ?
(too old to reply)
Alen Hopek
2006-05-04 16:52:57 UTC
Permalink
Hello,

sorry for such newbie question.

I need to return a array as return value out of a function in PowerBasic
v8.01

Something like this:

FUNCTION Test() AS LONG
DIM array(1 to 20)

array(0) = "Value1"
array(1) = "Value2"
array(2) = "Value3"

REM Some other Job

FUNCTION = array
END FUNCTION

This will not work.
Has anyone some help for me ?

Greetings
Alen Hopek
Jonathan Berry
2006-05-04 18:15:55 UTC
Permalink
ARRAY is a reserved word. Try MYarray or something.

The FUNCTION = array thingie also looks strange to my
naive eyes. I thought you could only assign scalar values.
But I don't have PBWIN 8.
Post by Alen Hopek
Hello,
sorry for such newbie question.
I need to return a array as return value out of a function in PowerBasic
v8.01
FUNCTION Test() AS LONG
DIM array(1 to 20)
array(0) = "Value1"
array(1) = "Value2"
array(2) = "Value3"
REM Some other Job
FUNCTION = array
END FUNCTION
This will not work.
Has anyone some help for me ?
Greetings
Alen Hopek
--
happy
Jonathan Berry and Erika http://members.shaw.ca/berry5868/fun.htm
Tom Lake
2006-05-04 17:21:22 UTC
Permalink
Post by Alen Hopek
Hello,
sorry for such newbie question.
I need to return a array as return value out of a function in PowerBasic
v8.01
If you use Dim Shared, you can get the values from the array after the
FUNCTION ends. You can return 0 if the function worked or an error
code if it didn't work.
Post by Alen Hopek
FUNCTION Test() AS LONG
DIM Shared array(1 to 20)
array(0) = "Value1"
array(1) = "Value2"
array(2) = "Value3"
REM Some other Job
FUNCTION = 0
END FUNCTION
This will not work.
Has anyone some help for me ?
Greetings
Alen Hopek
Michael Mattias
2006-05-04 18:15:45 UTC
Permalink
Post by Alen Hopek
Hello,
sorry for such newbie question.
I need to return a array as return value out of a function in PowerBasic
v8.01
You cannot return an array as the return value of a function using any
flavor of PowerBASIC (as clearly stated in all help files).

You can, however, pass an array as a parameter and operate on it, eg...

FUNCTION Foo ( Z() AS STRING) AS LONG

REDIM Z(new UBOUND)
FILL Z() with data
SORT Z() if desired
Whisper-sweet-nothings-into-z()'s-ear
whatever

FUNCTION = some return value, maybe Zero for success, one for error

END FUNCTION

USAGE:

REDIM Z(anynumber)
iRet = Foo (Z(0))
IF Ret = 0 THEN
' function foo succeeded
ELSE
it didn't
END IF

MCM

Loading...