Solved

Control array problems

Posted on 2002-06-10
7
200 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Notepad++ how to remove delimiter : from beggning of the line? 3 111
Visual Studio search word table and return Cell index 8 68
VB6 - Convert HH:MM into Decimal 8 62
MsgBox 4 68
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

790 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