Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass Multi Dimensional Array to function

Status
Not open for further replies.

PANTLORD

Programmer
Aug 28, 2001
49
EU
Hi there,

Have a defined multidimensional String array which I wish to pass by reference to a function within a window object. How do I need to define the function parameter ? currently I have it as
Pass By: Reference
Argument Type: String
Argument Name: lsa_my_array[2,3]

If I don't include the [2,3] then the function doesn't seem to see it as a multidimensional array and thus won't let me create assignments to it, but I'm worried that I'm only passing as reference the location [2,3] and not the whole array, any ideas ?

Many thanks,
Mully
 
You could declare the array as an instance variable on an nvo and then pass the nvo to the function.
 
Thanks for the reply sorry bit green here your onna hav eto help me out, but what is an nvo ? and does this mean that you can't pass a multidimensional array as I wished to do to a function ?

Thanks again,
Mully
 
Nvo is a non-visual object.

This is from the Powerbuilder books online:

"Passing arrays
When an argument is an array, you specify brackets as part of the argument name in the declaration for the function or event.
Variable-size array as an argument For example, suppose a function named uf_convertarray accepts a variable-size array of integers. If the argument's name is intarray, then for Name enter intarray[ ] and for Type enter integer.
In the script that calls the function, you will either declare an array variable or use an instance variable or value that has been passed to you. The declaration of that variable, wherever it is, looks like this:
integer a[]
When you call the function, omit the brackets (because you are passing the whole array). If you specified brackets, you would be passing one value from the array:
uf_convertarray(a)"

Looks like you have your declaration reversed.
 
Thanks for that.

I ended up declaring the array as an Instance variable so I can call it from my main object functions.
W.r.t the formatting I have passed other arrays and omitted the brackets and this seemed to work fine but its not the case for a multidimensional one. As soon as you try to make assignments if you omit the brackets in the parameter it just assumes it is a single dimension array and you start to get errors.

Its fun if you pass an argument name as something like Argument Name: lsa_my_array[0,0], watch PB7 self destruct!!

All the best,
Mully

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top