|
This question should be used to assess the skills of a junior
level Visual Basic programmer. A candidate with one year of
experience should be able to answer the following question
correctly. This is a common problem in visual basic applications.
You support an application developed by another programmer
for an aircraft parts company. When the form is displayed
the cursor is on the text2 field (see the following graphic).
The client would like the cursor to be on the text1 TextBox.
What is the easiest way to accomplish this?
Answer: The simplest way is to set the TabIndex property
of text1 to 0. This will force the cursor to the text1 TextBox
when the form is opened. This is the preferred acceptable
method for accomplishing this task.
Another method
that is technically correct but not as simple is to include
the line: txtText1.SetFocus in the form_load event
of the form. Although not preferred, this is also an acceptable
answer.
A candidate may
suggest to put the txtText1.SetFocus in the form_activate
event. This will cause the cursor to jump to the txtText1
TextBox whenever the forms get focused.
Other answers,
like adding a txtText1.SetFocus to other events, like
the text2_gotfocus event are wrong and show a lack of understanding
of Visual Basic's intrinsic events.
Additionally, the
candidate should mention that the TabOrder should be set for
all the "tabbable" controls or the user will go the wrong
place after leaving the first text box.
About
the author
Mark Horninger, A+, MCSE+I, MCSE, MCSD, MCDBA, MCSA is President
and founder of Haverford Consultants Inc. (http://www.haverford-consultants.com),
located in the suburbs of Philadelphia, PA. He develops custom
applications and system engineering solutions, specializing
primarily in Microsoft operating systems and Microsoft BackOffice
products. He has over 15 years of computer consulting experience
and has passed 31 Microsoft Certification Exams. During his
career Mark has worked on many extensive and diverse projects
including database development, client server and web-based
application development, training, embedded systems development
and Windows NT and 2000 project rollout planning and implementations.
Mark is a contributing author to the books: MCSE Windows
2000 Professional Study Guide, Designing SQL Server 2000 Databases
for .NET Enterprise Servers, VB .NET Developers Guide and
Configuring and Troubleshooting Windows XP Professional.
Mark lives with
his wife Debbie and three children in Havertown, Pa. and can
be reached at mark@haverford-consultants.com
or markh@op.net.
|