problem with modules
eddymouse
Posts: 67
Hi!
I need your help.
I'm making a module:
MODULE_NAME='moduleName' (DEV TP, integer nMaxZone )
DEFINE_VARIABLES
integer zone[nMaxZone]
In the main Program I call the module by:
DEFINE_MODULE 'moduleName' moduleName(TP, NZone)
where NZone is defined :
DEFINE_VARIABLE
integer NZone=31
So:
- In the module, zone is defined as a integer variable, not array and the value is 1, but if I check the value of nMaxZone in DEFINE_START of the module, the value is 31 (correct)
Why?
Thanks a lot!!!
Alessandro
I need your help.
I'm making a module:
MODULE_NAME='moduleName' (DEV TP, integer nMaxZone )
DEFINE_VARIABLES
integer zone[nMaxZone]
In the main Program I call the module by:
DEFINE_MODULE 'moduleName' moduleName(TP, NZone)
where NZone is defined :
DEFINE_VARIABLE
integer NZone=31
So:
- In the module, zone is defined as a integer variable, not array and the value is 1, but if I check the value of nMaxZone in DEFINE_START of the module, the value is 31 (correct)
Why?
Thanks a lot!!!
Alessandro
0
Comments
In Module:
MODULE_NAME='moduleName' (DEV TP, integer zone[] )
In Main Program:
DEFINE_VARIABLES
integer NZone[nMaxZone]
DEFINE_MODULE 'moduleName' moduleName(TP, NZone)
Jeff
As Dave mentioned there are no dynamically allocated arrays in Netlinx, all array sizes must be determined at compile time. You might want to rethink your design of your module. Why pass it an integer when you can pass it an array that you have already defined in client code? Do what Jeff mentioned and that will work fine. I doubt your module knows better than the calling code about the number of zones, unless you are doing something unusual.
I will mention though, that the styIe police will not like your use of the identifier nMaxZone. I think of Max as a maximum, like the most you can have and not to exceed, not just the count of the number of things you have.
ie:
iMaxTPChannels = 4000
iMaxChars = 256
If your variable really is a true maximum, then you can write the module like this:
MODULE_NAME='moduleName' (dev TP, integer nNumZones[256] )
Then in the module you can check to see if the length of the array passed is the same as the array in the above parameter and send a warning to the console on a timeline every 30 seconds if it isn't.
I have written code where I have both a iNumSomething and a iMaxSomething variable and they mean very different things. Fortunately the style police are lenient and don't usually press charges for first offense
Paul