Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA store arrays in public function and use it repeatedly?

Status
Not open for further replies.

dynatang

Petroleum
Jan 28, 2005
5
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.
 
Replies continue below

Recommended for you

Public variable?

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

UK steam enthusiasts:
 
Thanks. But even static variable does not work.
 
If you declare a Public variable in a module then its value remains while the workbook is open.

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:
 
I will try and let you know the result. thanks anyway.
 
johnwm,
It's really working. You are right. The variables I declared work till I close the workbbok. Thanks A million.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor