Solved

Array Issue for An AddIn

Posted on 2011-03-24
10
377 Views
Last Modified: 2012-05-11
I am in the process of writing an addin which needs to work with several workbooks open. Everything was OK until I came to the following issue...on wb1, user selects 2-3 items from a listbox (e.g., a,b,c); public array is successfuly built and info available for later processing...life is good. this works. HOWEVER, user opens wb2 (with wb1 still open), selects, e.g., a,d...array is built and for wb2 info retained and available. Well, user goes back to wb1 and a,b,c has been rteplaced by a,d. Unfortunately makes sense. Since I programmatically can identify each wb name, should I maybe write array values to wb specific TempFolder, then Read from folder when necessary...eventually Kill temp folders? It would be easier if I could create a wb specific name array but my initial attempt seems to indicate this can't be done. Thoughts please.
0
Comment
Question by:ronaldj
10 Comments
 
LVL 8

Expert Comment

by:ragnarok89
ID: 35208387
It may be clunky, but You could use a hidden worksheet to store all these temp values, one sheet per workbook.
0
 
LVL 20

Expert Comment

by:clarkscott
ID: 35208408
Perhaps you're losing the ubound array value?.
Your app may be 'starting over' when assigning new items to the array.  You should be 'adding' to the upperbound value.

(Pseudo-code)

Public ArrayCnt as long

Add to the array....
ArrayCnt = ArrayCnt + 1
YourArray(Arraycnt) = YourNewValue

To start over, you must erase the array AND reset the public variable, ArrayCnt =0 .

??

Scott C


0
 
LVL 41

Accepted Solution

by:
dlmille earned 250 total points
ID: 35209386
You can most definately create a defined name and store an array - in fact, until I got to that point in your comment, that's what I was going to suggest:

The below code stub is from another question I recently answered, and I was doing just that - storing an array into a defined name, for later retrieval.
Sub storeControlSettings(sControl As String)
Dim sBuildControlName As String
Dim sControlSettings(1 To 6) As Variant ' set to the number of control settings to be stored
       
    Set oControl = ActiveSheet.OLEObjects(sControl)
    
    'store the settings to retain, so they can be reset on demand, thus avoiding Excel's resizing "problem"
    'create array of settings to be stored, with order dictated by CONTROL_OPTIONS for consistency/documentation
    
    sControlSettings(1) = oControl.Height
    sControlSettings(2) = oControl.Left
    sControlSettings(3) = oControl.Locked
    sControlSettings(4) = oControl.Placement
    sControlSettings(5) = oControl.Top
    sControlSettings(6) = oControl.Width
    
    
    sBuildControlName = "_" & sControl & "_Range" 'builds a range name based on the control name
    
    Application.Names.Add Name:="'" & ActiveSheet.Name & "'!" & sBuildControlName, RefersTo:=sControlSettings, Visible:=False 'Adds the control's settings to the defined names area and hides the range name
    
End Sub

Open in new window

Enjoy,

Dave
0
 

Author Comment

by:ronaldj
ID: 35210039
Dave:

What if I am prohibited from wring to the wb(s) OR adding a hidden sheet as suggested by ragnarok89 earlier? Since I posted this AM I have successfully written code which WRITES the current elements from the open wb array into a wb specific temp folder / text file. When back from dentist will work on READ code. Thanks, will keep you posted if you wpould like.

Ron
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 41

Expert Comment

by:dlmille
ID: 35210073
Why would you be prohibted from writing to the workbooks?  

>>It would be easier if I could create a wb specific name array but my initial attempt seems to indicate this can't be done. Thoughts please.

Anyway, I was just addressing your perceived problem with writing arrays to defined names, which in your question said would be "ideal"  As a result, I have submitted a proposed solution which you stated would be "easier".

Cheers,

Dave
0
 
LVL 45

Expert Comment

by:aikimark
ID: 35211947
you might

* use a dictionary object to store the different arrays by the wb.name as the key.
* use a variant array, where one of the dimensions is a string = wb.name
* use either dictionary or collection object to store string values that include both the wb.name and the numeric value.  You would parse the string for eligible items to recover/use the numeric data.
0
 
LVL 41

Expert Comment

by:dlmille
ID: 35796930
>>It would be easier if I could create a wb specific name array but my initial attempt seems to indicate this can't be done. Thoughts please.
I thought we provided some good solutions, and mine was directly in response to the original question, above, correctly.  Other good alternatives were also provided.

Dave
0
 
LVL 24

Expert Comment

by:broomee9
ID: 35877394
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now