Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Control array problems

Posted on 2002-06-10
7
Medium Priority
?
223 Views
Last Modified: 2010-05-02
Hi,

I'm using control array to create controls at runtime on a tabstrip. I have a command button on the form with index = 0 and I create more buttons using

    iNextBtn = btnClose.Count
    Load btnClose(iNextBtn)
    With btnClose(iNextBtn)
        .caption = "&Close"
        .Tag = sNamedCell
        Set .Container = Controls(sNamedFrame)
    End With

and when the tab has to be closed, I unload the button with
    Unload btnClose(iBtnIndex)

However, when I unload the button with index say 1 and then subsequently try to load the button with the same Index, I get a runtime error that the item is already locked.  I'd like to know why this happens.  I can find a way to work around this, but I'd like to understand why I get the runtime error.

TIA
-RK
0
Comment
Question by:rkrishc
7 Comments
 
LVL 5

Expert Comment

by:rpai
ID: 7067348
Could you please post your code where the error is raised?
0
 
LVL 3

Expert Comment

by:nichia
ID: 7067402
You might try this:

Unload btnClose(iBtnIndex)
Set btnClose(iBtnIndex) = Nothing

0
 
LVL 2

Expert Comment

by:Finnbin
ID: 7067688
I haven't seen all your code but are you declaring the array as myarray() AS control.
       I usually use collections there easy to program and have a much more sophisticated item handling abilities.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Expert Comment

by:TigerZhao
ID: 7069026
Check your tabstrip control, maybe it hold btnClose(1)
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 400 total points
ID: 7069353
rkrishc think of this:

Create Buttons as follows:

Index = 1
Index = 2
Index = 3
Index = 4

Then Remove button where index = 2

Your Button.Count returns 3 yet index = 3 already exists so you will certainly get an error generated.

If you always use Button.UBound + 1 you can be assured that you will always get a valid index created. Obviously this may cause some gaps in your control array but this can be dealt with if necessary.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7873537
Hi rkrishc,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept TimCottee's comment(s) as an answer.

rkrishc, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7924975
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

963 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