VBA store arrays in public function and use it repeatedly?
VBA store arrays in public function and use it repeatedly?
(OP)
I coded the clustering algorithem into a excel public function.
Then VBA solver is used to adjust two parameters to reach the target.
Because most time is used in inputing a same large data file, I am wondering is there any way in VBA to read in data once into memory and use by rest of the program, like key word "common" in Fortran?
The reason is each iteration of solver need the clustering for all nodes. And end of each sub or function. VB will unlaod all arrays and memory. And my data is stored in data file. So I need to read in data every time.
Then VBA solver is used to adjust two parameters to reach the target.
Because most time is used in inputing a same large data file, I am wondering is there any way in VBA to read in data once into memory and use by rest of the program, like key word "common" in Fortran?
The reason is each iteration of solver need the clustering for all nodes. And end of each sub or function. VB will unlaod all arrays and memory. And my data is stored in data file. So I need to read in data every time.





RE: VBA store arrays in public function and use it repeatedly?
Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting
UK steam enthusiasts: www.essexsteam.co.uk
RE: VBA store arrays in public function and use it repeatedly?
RE: VBA store arrays in public function and use it repeatedly?
In the VB editor do Insert|Module and declare a public variable in the Declarations section of the module:
Public intA As Integer
In your Workbook code page set the values for that Public variable:
Private Sub Workbook_Open()
intA = 5
End Sub
You can then use intA from any worksheet and it will retain it's value (unless changed by your code of course)
Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting
UK steam enthusiasts: www.essexsteam.co.uk
RE: VBA store arrays in public function and use it repeatedly?
RE: VBA store arrays in public function and use it repeatedly?
It's really working. You are right. The variables I declared work till I close the workbbok. Thanks A million.