Solved

Control array problems

Posted on 2002-06-10
7
174 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 100 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

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

18 Experts available now in Live!

Get 1:1 Help Now