| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Pass array name to function? https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=2967 |
Page 1 of 1 |
| Author: | Radar [ Sat Aug 10, 2013 10:37 am ] |
| Post subject: | Pass array name to function? |
Hey gang, I have 3 functions to backup, restore, and trim arrays, but at the moment, they all only work with a single array. Here's my TrimArray function... Code: Select all I've tried changing the function to accept the array name as a string, (void TrimArray(string ArrayToTrim)), but execution never gets past the for(int i=(ArrayRange(ArrayToTrim,0)-1); i>=0; i--) line of code So, as the title says, is there any way to pass the array name to the function, and replace the instances of MyTf with variable names so that one set of code suits all, or do I have to repeat the code for each array that I want to trim, (or backup/restore, as the case may be)? I'm most definitely at the limit of my knowledge with this, and really need an example of how to do it, if it's possible to do at all. Thanks in advance Have fun! Radar =8^) |
|
| Author: | dietcoke [ Sat Aug 10, 2013 11:48 am ] |
| Post subject: | Re: Pass array name to function? |
You cannot pass an array as a parameter to a function. What you have to do is pass a reference to the array instead. Decent explanation here: http://en.fortrader.ru/mql/nedokumentir ... -mql4.html Any way, the syntax is thus: Code: Select all TrimArray(MyArrayToTrim); where MyArrayToSort is the array you want to trim. |
|
| Author: | Radar [ Sat Aug 10, 2013 12:13 pm ] |
| Post subject: | Re: Pass array name to function? |
Hey Dietcoke, Thanks for that!! It took me 5 hours to just get the basics into my head, and another 12 hours to get from there to here. I'm off to put this into practise until it sticks Have fun! Radar =8^) |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|