How to generate a key and add it to status bar panel?

I have a status bar with 8 panels.
Because a user can change profile this is loaded several times.

Now wherever it loads it finds an error.
Key not unique in collection.

Now since at the stage that this happen I cannot add a key
that is something I can retrieve from the database like a primary key.

I thought of adding a count to it but doesnt work

my idea
dim count as integer
count =0

dim panel as panel

set panel=stbmdipanels.panels.add(,"Bookings" & Count,"Bookings)
count=count + 1

but this doesnt work because whenever it loads again it fails.
any suggestions?


Who is Participating?
MonchangerConnect With a Mentor Commented:
> Because a user can change profile this is loaded several times.

I'm not sure understood this correctly, but are you adding panels to the *same instance* of the statusbar whenever a new user logs in? If so, they would indeed hold the same key and give you a runtime error. (If your application is small, I believe this would be the cause)

Instead, you could rebuild the statusbar when a user logs in - first remove all existing panels, and then creating new panels (it would be more efficient to fix the old panels, but that depends on your needs)

Something like:

Private Sub RebuildStatusBar()
    StatusBar1.Panels.Add , "Panel1", "First Panel"
    StatusBar1.Panels.Add , "Panel2", "Second Panel"
End Sub

if I understand U need Static Var in a procedure

Static Conut        ' instead of Dim Count

'     Basic Initialize it  to 0 automatically
Gabriel_BrienzaAuthor Commented:
Thanks guys for your replys

I have tried to add a static count and didnt work

I did

static AddKey as integer

Dim Panel As Panel
 addKey=addkey + addkey              

set Panel = stbMDI.Panels.Add, "Bookings" + addkey, "Bookings")
but this didnt work and I cannot understand why

also i tried to remove it and the add it but it keeps saying element not found which means.

I need to find a way first if it exist and if does remove and add it.

Any suggestions how to do it?


Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

The Panels.Clear should remove all of the panels.

Maybe if you posted your code we'd understand why it doesn't work for you.
Gabriel_BrienzaAuthor Commented:
Thanks for your help
I have solved the problem.

the panel's KEY MUST not be a number.  it HAS to start with a text character.  i know this question is answered, but i found this very useful to know.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.