Solved

Control array problems

Posted on 2002-06-10
7
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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 …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Suggested Courses
Course of the Month6 days, 9 hours left to enroll

634 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