Get the name of a control at runtime

By | 2002-06-01

I’ve recently taken over a project from someone else, and I’ve been left with code that has few naming conventions and a lot of bugs. I often find myself stepping through code wanting to check the value of a field. Unfortunately, I don’t know the field’s name-it could be Name, UserName, NameUser, txtName, and so on. It’s a real pain to stop the program, click on the control in question, press [F4], get the control name, start the program again, and return to the point in the code where I was before. Here’s a handy trick to get the control name right away.
by Jeff Brown; Jeff.Brown@piog.com; Pioneering Management Corporation

Original Author: Found on the World Wide Web

Code

At runtime, set the focus to the control in question. Then, click the Break button on the VB toolbar, type
?á?á?á?Screen.ActiveControl.Name
in the debug window, and press [Enter]. Voila! VB displays the control name in the debug window-and you didn't have to stop the program.

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.