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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How many controls can you add to a form? 2

Status
Not open for further replies.

Agent009

Programmer
Apr 4, 2003
96
IE
I'v created a
very large, complex form with a huge amount of
controls i.e. textboxes etc. I cannot add any more as
vb gives me an error that i have reached the limit to
what i can add. How can i sort this out cause i need
to add alot more??

Thanks in advance!

Agent009
 
While I've never run into a limit of controls on a form, I would imagine that if you've run into this limitation, you must have thousands of such controls. You may want to try changing your tactics to creating just one control of the type you need, and changing the properties during runtime, or creating copies of the control dynamically in your programming. Here, I'm assuming you must have created at least a few hundred controls on a single form, because I've seen fairly complex applications without any hint of this limitation.
 
From VB Docs

Total Number of Controls
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.



Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
To be honest I'm with rgautier here; if you are hitting the control name limit, then you may want to rethink your interface design.
 
My limit has to be one less than max because I use the Form_KeyPress (etc) functions and in order get (say) arrow keys working in the form I have to have a NOT visible control and contrive to Set Focus to that just before End Sub on all controls. The ghost button then has it's own Sub controlname_KeyUp as if it was the form (which cannot receive focus if it has controls). This makes the text in a control (if tight to sides) more predictable by guarranteeing where focus is.
I doubt I am near max but I have a lot of controls that are only visible on demand and are mutually exclusive. It is the only way to avoid confusing the user. Naming them uniquely rather than having them arrayed makes them mnemonic - a big plus in the face of my memory.
 

>Naming them uniquely rather than having them arrayed makes them mnemonic - a big plus in the face of my memory

Ever consider using constants as the INDEX?

Private Const TXTBX_DATE_1% = 10

Private Form_Load()
TxtBx(TXTBX_DATE_1).Text = Date
End Sub

Private Sub TxtBx(Index As Integer)

Select Case Index
Case TXTBX_DATE_1
'Do something
End Select
End Sub
 
You know, that's one of those neat tricks that - once you've seen it - you slap your forehead and go "Of course, how obvious". Here, have a star CCLINT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top