Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / User Made Function : Passing an Array

Author
Message
Dejunai
19
Years of Service
User Offline
Joined: 19th Jul 2005
Location: Mentally: Manhattan; Physically: LA -doh
Posted: 27th Jul 2005 00:28 Edited at: 27th Jul 2005 00:49
( in DBP Trial )

True or False:
Can You pass an Array to a user function?

Cannot seem to locate a specific help file,
Detailing how ( if you can at all ).

If you can:
Could some please post a simple example...

I was trying this, I know it doesn't work...
It's just an simple example, of what I would like to expand on.



In other languages one might use a POINTER reference,
But the HELP documentation seems sketchy at best about
pointers.

As Always any help would be appreciated...


Edit :
As I just located a DLL at Matrix1 ( the ever generous IanM's page )
that addresses at least some of my issues,
I can assume that DBPro does not have the capability
to pass arrays to user functions...
Of course if this is incorrect,
I still look forward to any help.

================
-Dejunai
================
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 27th Jul 2005 01:23
Not supported.

Kevin Picone
[url]www.underwaredesign.com[/url]
Play Nice! Play Basic (Release V1.08 Out Now)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Jul 2005 19:08
Arrays are global, they can't be local. So although it's technically a limitation, you already have a workaround. You can access arrays anywhere.

BatVink
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 27th Jul 2005 23:20
No, arrays can be global and local. However, he wants to pass an array (by pointer) into anfunction and perform an operation upon it. Which is not natively supported in DB or DBpro.

For example, in PlayBasic you can do this.



Kevin Picone
[url]www.underwaredesign.com[/url]
Play Nice! Play Basic (Release V1.08 Out Now)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Jul 2005 00:42
You can create arrays anywhere, including in a function. But it's still global

I take advantage of this by making arrays in Init() routines, thus making my include files 100% portable.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Jul 2005 20:07
Arrays defined in functions can be local if you declare them as local:



If you remove the 'local' command, you'll see that things go back to being global, and the dim in the function becomes the standard 'resize array' type command.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Xolatron old
20
Years of Service
User Offline
Joined: 25th Jan 2004
Location: The Star Forge Language: DBpro
Posted: 30th Jul 2005 00:53
Note, however, that you cannot create a global array inside of a function, and you must use a subruotine.

-Xol

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 30th Jul 2005 01:34 Edited at: 30th Jul 2005 01:36
You can create a global array inside a function, that's the whole point. If you look at IanM's code, you have to force DB Pro to make the array local. If you don't, it automatically becomes global.

Try this:



I always wondered why local was provided. Now it makes sense. This seems to be the only reason it's there, all other variables work based on where they are decalred.

Xolatron old
20
Years of Service
User Offline
Joined: 25th Jan 2004
Location: The Star Forge Language: DBpro
Posted: 30th Jul 2005 21:36
BatVink,
Go look at the bug reports section - I have code that won't work declaring a global array in a function, but it was rejected because arrays aren't supposed to be able to be made global in a function.

-Xol

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Jul 2005 15:06
That's not what I said, or meant when I rejected your post. I said that the array name wasn't available outside the function.

An array can be declared as global within a function, and from that point will exist, but only within the function.

To make it plain:
WHERE the array is defined, determines the availability of the array name (or it's scope)
HOW the array is defined, determines where the array is stored (or it's lifetime)

So, an array declared outside of a function is available everywhere. An array declared within a function is available within the function.

An array declared as local will be created on the program stack. An array declared as global (as they are by default) will be stored in the 'static' variable area.

Once you get scope and lifetime straight, you'll understand how it works.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk

Login to post a reply

Server time is: 2024-11-27 20:38:27
Your offset time is: 2024-11-27 20:38:27