Solved

Array Issue for An AddIn

Posted on 2011-03-24
10
376 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 41

Expert Comment

by:dlmille
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

762 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

10 Experts available now in Live!

Get 1:1 Help Now