×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBA store arrays in public function and use it repeatedly?

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.

RE: VBA store arrays in public function and use it repeatedly?

Public variable?

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?

(OP)
Thanks. But even static variable does not work.

RE: VBA store arrays in public function and use it repeatedly?

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: www.essexsteam.co.uk

RE: VBA store arrays in public function and use it repeatedly?

(OP)
I will try and let you know the result. thanks anyway.

RE: VBA store arrays in public function and use it repeatedly?

(OP)
johnwm,
It's really working. You are right. The variables I declared work till I close the workbbok. Thanks A million.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources