Solved

Control array problems

Posted on 2002-06-10
7
202 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
Technology Partners: 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!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Updates not working for MS Windows 7 12 192
VB6 Compile Compatibility Issue 4 121
Assign a value in Excel V-Basic 3 28
Help with Classic ASP - Parameterizing Query 16 16
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

763 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