Skip to main content

Loop thru custom Textboxes name in VBA or VB.Net


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:


Linux Android App cheat sheet:

Divine Mercy Chaplet Guide (A Powerful prayer):

Comments

Popular posts from this blog

Copy a single file using robocopy

Copy a single file using robocopy from a local folder to a shared folder on the network.
A simple rule of thumb before any disaster strike, don't interchange the source and the destination.

If source and destination is mistakenly reverse, files might get overwritten. To avoid any loss of data do a test with a dummy file to ensure things work perfectly.
Robocopy [source][destination]   [file to be copied]
robocopy c:\local_c_folder  \\PC_network\shared_folder   file_to_be_copied_xx.txt
The command will be completed successfully provided the network access right has no issues.

Robocopy works quite good on large files. A simple copy or xcopy command will also work but the speed might vary.

Robocopy is free it can be accessed from command line. No need to install the resource kit tool if the operating system is Windows 7 or newer version.

Copy files with selected file extension using PowerShell and Robocopy:

$extension = ('.pdf', '.jpg', '.txt')
gci d:\WorkFolde…

WMIC List printers

WMIC comes handy if you are a command line junkie.

To list printers via command line type:

wmic printer get name  = = = this will list all the printers installed on a workstation

To list the printer name and the port name of the printers, type this command:

wmic printer get name, portname

Type this command below to list the printer drivers:

wmic printer get name, drivername

To get the device id:

wmic printer get name, deviceid

You can deploy a batch file startup script to check which printer is installed on the computers and redirect the output to a shared folder.

PowerShell can also be used in conjunction with WMIC command:
http://quickbytesstuff.blogspot.sg/2015/11/powershell-list-printers-of-remote.html


To see more WMIC tips, click on WMIC label below.

Cheers!!!

Linux Android App cheat sheet:
https://play.google.com/store/apps/details?id=com.LinuxMobileKit