Good evening, Mr Excel!
I'm in the process of writing a dynamic programming piece of code as part of a university case study. The assignment itself is very open-ended and doesn't mention VBA so there's no need to worry that I'm simply scounting for answers.
This would be the largest piece of VBA I've written and involves the need to write functions or procedures in a separate module in order to keep the code itself clear and repeatable. However, these functions involve altering the contents of arrays and I cannot for the life of me find a way to stop the arrays from going out of scope once the function/procedures have completed. Attempts to search for solutions involving ByRef with arrays on the Internet are met with frustrating errors.
Here is a snippet of the code; feel free to pm if I intrigue you enough to want to look at the whole thing. I'm willing to write comments in the code highlighting whereabouts the issue arises if that's the case.
-----------------------------------------
Module "Main"
Public alngHeadsAv(1 to 10) As Long
[...]
Public Sub Main()
[...]
headsAvEntry 'Function
End Sub
Module "Functions"
Public Function headsAvEntry()
alngHeadsAv(1) = 1
alngHeadsAv(2) = 3
[...]
alngHeadsAv(10)=12
End Function 'data goes out of scope here.
----------------------------------------------
I'm quite sure I need to use ByRef somehow, but every variation of its use on the Internet is met with errors. I'm using Excel 2010 and am on Windows 7 at a University computer. Any help at all would be appreciated; even an abstract example of ByRef for arrays that would WORK would make me very appreciative indeed.
Thank you~!
I'm in the process of writing a dynamic programming piece of code as part of a university case study. The assignment itself is very open-ended and doesn't mention VBA so there's no need to worry that I'm simply scounting for answers.
This would be the largest piece of VBA I've written and involves the need to write functions or procedures in a separate module in order to keep the code itself clear and repeatable. However, these functions involve altering the contents of arrays and I cannot for the life of me find a way to stop the arrays from going out of scope once the function/procedures have completed. Attempts to search for solutions involving ByRef with arrays on the Internet are met with frustrating errors.
Here is a snippet of the code; feel free to pm if I intrigue you enough to want to look at the whole thing. I'm willing to write comments in the code highlighting whereabouts the issue arises if that's the case.
-----------------------------------------
Module "Main"
Public alngHeadsAv(1 to 10) As Long
[...]
Public Sub Main()
[...]
headsAvEntry 'Function
End Sub
Module "Functions"
Public Function headsAvEntry()
alngHeadsAv(1) = 1
alngHeadsAv(2) = 3
[...]
alngHeadsAv(10)=12
End Function 'data goes out of scope here.
----------------------------------------------
I'm quite sure I need to use ByRef somehow, but every variation of its use on the Internet is met with errors. I'm using Excel 2010 and am on Windows 7 at a University computer. Any help at all would be appreciated; even an abstract example of ByRef for arrays that would WORK would make me very appreciative indeed.
Thank you~!