Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Panels in StatusBar? 1

Status
Not open for further replies.

meinhunna

Programmer
Jul 31, 2004
118
0
0
AU
How can I count number of panels in a StatusBar control?
 
Ther's probrably a better way to do this, but you could stick this in a function:

Code:
Dim x As Integer
Dim temp As String
Try
  For x = 0 To 99999999
    temp = Me.StatusBar1.Panels(x).Text
  Next
Catch
  x -= 1
End Try
Debug.WriteLine(x)

-Rick

----------------------
 
You can find it out by
Code:
StatusBar1.Panels.Count
I know you didn't see it in the intellisnce list, but it exists. You can find it in the help. This is not the first time I see such a problem.
All this problems are in VB, not in C#.

ThatRickGuy, what you suggested is not a good idea. There are a lot of articles saying you should use try catch only for bad cases, because the performance of try and catch is very poor.
Look in:
 
Korach, any idea why .Count is not in the intellisence? It is definately a better option in this situation.

I agree with the blog poster about not using try/catches when they are not necesary, but, take that with a grain of salt. It does not mean that you should always use code to prevent an situation instead of catch's to deal with a situation.

In his example he shows the speed advantage of using a non-catch based formula, 30,000 times. If on the other hand, you are looking for a 1 time event (IE: Is the app going to need to check how many panels there are 30,000 time?) the performance hit decreases significantly.

There are some situations also where a simple try/catch block can take significantly less code and be easier to read. Leading to easier maintenance.

There are even some situations where exception handling/throwing will give improved performance. I can pull up some multithreading code that will show a huge advantage in performance for using exceptions to exit threads as opposed to code to exit threads.

In short, don't rule out the use of exceptions because in one situation they are not a wise choice. And thanks for the .Count reference!

-Rick

----------------------
 
StatusBar1.Panels.Count did work. Could not find anything in IntelliSense though.

 
Try to find Button.IsDisposed in VB.NET (in C# you can see it).

Try to write:
Code:
        Dim o As Object
        o.ToString()
When you press the "." you get only the "GetType" method in the intellisense list, but write "ToSt" after the period and press on ctrl+space and you'll see that visual studio completed the word ToString for you! You can even see the tool tip for this method. In C# it is ok.

The Count problem for the panels collection is in C# too.
 
Any idea why? I've seen this before with shadows methods, but Panels.Count is a public overridable overloads readonly property. same with .ToString

Odd.

-Rick

----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top