|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
In High Density Mode - Looking for previous control counting postSorry, my brain is like glue today.
I was scanning posts a while back and saw a very helpful snippet to count the number of unique controls on a form to see if the count was near the form limit. Let's play find the post? I tried all the keywords I could think of but ... Thanks and sorry, I usually clip the great snippets, but for some reason I forgot to. P.S.
I just found out the hard way that each menu entry counts as one control. I banged up against the end (control count wise) and got a nasty message. Turned out to be punitive. I closed the menu editor and found that when I tried to reopen it, there, zero, nada, no menu items to be found. I closed the project and reopened it and all was well. Whew! Now I am revamping the menus and using Index all over the place. More lessons learned the hard way. It always brings to mind my VB instructor who used to stand in the front of the classroom with his laptop and laptop projecter and demonstrate how quickly he could move his mouse around the screen while talking at 120 mph. I took all my VB classes from him but found out as we all usually do, that the classes simply teach us how to place a control on a form not what do do when you run out of "room" for contols on the form. Show quoteHide quote "Bee" wrote: > Sorry, my brain is like glue today. > I was scanning posts a while back and saw a very helpful snippet to count > the number of unique controls on a form to see if the count was near the form > limit. > Let's play find the post? I tried all the keywords I could think of but ... > Thanks and sorry, I usually clip the great snippets, but for some reason I > forgot to. > > "Bee" <B**@discussions.microsoft.com> wrote in message After making the menus into control arrays, add this to make reading your news:343B9F2F-D2BA-40BF-A4B6-2EE52B8E5AD1@microsoft.com... > P.S. > I just found out the hard way that each menu entry counts as one control. code easier: Private Enum enmFile enmOpen enmSave enmExit End Enum Private Enum enmTools enmRun enmOptions End Enum When you type "enmFile", followed by dot, intellisense would show the list of constants. Example: mnuFile(enmFile.enmOpen) This is more readable than just typing numbers. Keep in mind that Enums are visible outside the Enum, so you can't have two "enmOpen", nor any variable or function with the same name. VB does not hide the enum constants inside the Enum, it is as if you used Const to declare them, but there is no intellisense when you use Const. "Bee" <B**@discussions.microsoft.com> wrote You could put something like this as the first line of Form_Load:> Sorry, my brain is like glue today. > I was scanning posts a while back and saw a very helpful snippet to count > the number of unique controls on a form to see if the count was near the form > limit. > Let's play find the post? I tried all the keywords I could think of but ... > Thanks and sorry, I usually clip the great snippets, but for some reason I > forgot to. MsgBox Controls.Count But it isn't the number of controls you need to worry about. Its the number of control names that is limited. See: http://msdn.microsoft.com/en-us/library/aa240865(VS.60).aspx "The maximum number of controls allowed on a single form depends on the type of controls used and available system resources. However, there is a fixed limit of 254 control names per form. A control array counts only once toward this limit because all the controls in the array share a single control name." Of course if you're hitting the upper end of system resources, your form might be a bit too busy.... Is that the case here? LFS Depends on what one calls busy.
To me, having a bunch of windows open or just poping open and closed all over the place is too busy. So, even though my app has multiple forms, I minimuize the number of windows being open or poping open all the time. I put a tab on the main form and each tab has tabs. I try to keep the visual business down so the user sees only a few controls on each tab. I do not know any other way to do it. Suggestions please. Also, see my other post in this thread for my solution to counting controls. Thanks as always. Show quoteHide quote "Larry Serflaten" wrote: > > "Bee" <B**@discussions.microsoft.com> wrote > > Sorry, my brain is like glue today. > > I was scanning posts a while back and saw a very helpful snippet to count > > the number of unique controls on a form to see if the count was near the form > > limit. > > Let's play find the post? I tried all the keywords I could think of but ... > > Thanks and sorry, I usually clip the great snippets, but for some reason I > > forgot to. > > You could put something like this as the first line of Form_Load: > > MsgBox Controls.Count > > But it isn't the number of controls you need to worry about. Its the > number of control names that is limited. See: > > http://msdn.microsoft.com/en-us/library/aa240865(VS.60).aspx > > "The maximum number of controls allowed on a single form depends > on the type of controls used and available system resources. However, > there is a fixed limit of 254 control names per form. A control array > counts only once toward this limit because all the controls in the array > share a single control name." > > Of course if you're hitting the upper end of system resources, your > form might be a bit too busy.... Is that the case here? > > LFS > > > "Bee" <B**@discussions.microsoft.com> wrote in message It's this post:news:CDFCFD42-F870-4C39-9AB0-E3395961DC58@microsoft.com... > Sorry, my brain is like glue today. > I was scanning posts a while back and saw a very helpful snippet to count > the number of unique controls on a form to see if the count was near the > form > limit. > Let's play find the post? I tried all the keywords I could think of but > ... > Thanks and sorry, I usually clip the great snippets, but for some reason I > forgot to. http://groups.google.com/group/microsoft.public.vb.general.discussion/msg/fa1a0ca24f5d3cb9 Thanks. Both of you must get up very early in MY moring to have responded as
you did. Based in England or eastward? Anyway, after much gnashing of teeth I came up with the following code. In my case I use a dictionary class that I wrote so I do not have to use FSO. I think this works OK. What do you think? Private Sub ControlCount() Dim i As Integer Dim iNd As Integer Dim sKey As String Dim sValue As String Dim lCountNonIndex As Long Dim lCountIndex As Long Dim dicIndexed As Dictionary Set dicIndexed = New Dictionary For i = 0 To Me.Controls.Count - 1 sKey = "Control" & i Err.Clear On Error Resume Next iNd = Me.Controls(i).Index If (Err.Number = 0) Then sValue = Me.Controls(i).Name & "," & CStr(iNd) lCountIndex = lCountIndex + 1 If Not dicIndexed.Exists(Me.Controls(i).Name) Then dicIndexed.Add Me.Controls(i).Name, i End If Else sValue = Me.Controls(i).Name lCountNonIndex = lCountNonIndex + 1 End If Debug.Print sValue Next i Debug.Print "Total Count =" & FormatNumber(Me.Controls.Count, , , , True) Debug.Print "Non-Indexed Count =" & FormatNumber(lCountNonIndex, , , , True) Debug.Print "Indexed Count =" & FormatNumber(lCountIndex, , , , True) Debug.Print "Unique Indexed =" & FormatNumber(dicIndexed.Count, , , , True) Debug.Print "Total Unique Controls =" & FormatNumber(lCountNonIndex + dicIndexed.Count, , , , True) End Sub 'ControlCount Show quoteHide quote "Nobody" wrote: > "Bee" <B**@discussions.microsoft.com> wrote in message > news:CDFCFD42-F870-4C39-9AB0-E3395961DC58@microsoft.com... > > Sorry, my brain is like glue today. > > I was scanning posts a while back and saw a very helpful snippet to count > > the number of unique controls on a form to see if the count was near the > > form > > limit. > > Let's play find the post? I tried all the keywords I could think of but > > ... > > Thanks and sorry, I usually clip the great snippets, but for some reason I > > forgot to. > > It's this post: > > http://groups.google.com/group/microsoft.public.vb.general.discussion/msg/fa1a0ca24f5d3cb9 > > > > "Bee" <B**@discussions.microsoft.com> wrote I'd suggest if you have to worry about having too much stuff on a form,> Anyway, after much gnashing of teeth I came up with the following code. .... > What do you think? you probably already have too much stuff on a form! <g> Not that I'd suggest a redesign now, but what if your form supplied control arrays for the common controls and you simply loaded and unloaded controls as needed for the different tabs? You already indicated that each tab in itself was kept minimal, that would help to make load times that much quicker.... Just a thought! LFS
VB6 on Vista Home Premium problem
Excel Execution from VB Fails on 2nd Attempt Use an Addin to automatically add date/time stamp to each edited line of VB6 code? Sub .... or Private Sub.... When and where do I do Set m_FormVar = Nothing? VB6 - Just In Time Error Message Help Moving .exe somtimes works How to create the project referencing library, which user may not have on his computer? MS Access Query in VB6 fso.Drives replacement |
|||||||||||||||||||||||