Having a custom name in Textboxes, Listbox, ComboBox in VBA or VB.Net is a good strategy. So, it will be easy to debug the code or analyze the data.
If just relying on the default names is also good but it will get messy and it will be hard to control when there’s quite a few of textboxes, and list boxes. And the next person who will maintain the code will find it easier to debug or check the program when proper custom name is assigned to the controls. And that next person might be yourself. So, be gentle and be explicit in giving comments and assigning names to controls.
It doesn’t hurt to put a clear comment or an overview of what the piece of code does or what’s the input that the control is accepting. Because greediness breeds greediness, and it will bite back.
Anyway, to loop to all the custom or default names is quite easy.
Example, if there are 30 or more textboxes in a form. It can be done by a simple for loop like:
For x = 1 to 30
GetTboxvalue = Me.Controls(“Textbox” & x).value
‘the GetTboxvalue will get the value of Textbox 1 to Textbox 30 and display it
‘instead of just displaying it, it can be processed further
Msgbox GetTboxvalue
Next x
For custom names will just follow same logic.
Example: SalesInput1_CashierRow1 to SalesInput1_CashierRow5
For x = 1 to 5
SalesRow_Value = Me.Controls(“SalesInput” & x & “_CashierRow” & x).value
‘just display the value
Msgbox SalesRow_Value
Next x
The custom name or the default name is just a string and must be enclosed in open and close parentheses and preceded with me.controls to get the custom control name.
Cheers..till next time…
================================
Free Android Apps:
Click on links below to find out more:
Excel Keyboard shortcuts guide
Linux Android App cheat sheet:
Multiplication Table for early learners
https://play.google.com/store/apps/details?id=com.TableMultiplication
Divine Mercy Chaplet Guide (A Powerful prayer):
Comments
Post a Comment