Interviewer Insights  
About Us  
Comments, Suggestions  
  or General Feedback  
Interested in writing for  
Tech Talk Tips?  

 

 


Application Developer
User input validation in Visual Basic 6
by Mark Horninger


This question should be used to assess the skills of a junior level VB programmer. A candidate with 6 months to 1 year of experience should be able to answer the following question. This is a common problem in Visual Basic applications.

You have the following form that consists of a TextBox and a command button. The text entered into the TextBox must be upper case. The TextBox is named txtNarrative. What is the best way to accomplish this with minimal impact to the user?

1) in the txtNarrative_Change() event add the following line of code:
    KeyAscii = Ucase(KeyAscii)

2) in the txtNarrative_KeyPress event add the following:
    IF Keyascii <> ucase(keyascii) then msgbox("You need to enter upper
    case"):exit sub

3) in the txtNarrative_KeyPress event add the following:
    KeyAscii = Asc(UCase(Chr$(KeyAscii)))

4) in the txtNarrative_KeyPress event add the following:
    If Chr$(KeyAscii) <> UCase(Chr$(KeyAscii)) Then MsgBox
    ("You need to enter upper case"): KeyAscii = 0: Exit Sub

   

Answer

The correct answer is 3, KeyAscii = Asc(UCase(Chr$(KeyAscii))). This will automatically convert the character entered with no effect on any other characters, including numerics, punctuation and special characters like the ! and % character. This will have little impact on the user. The characters typed will automatically be converted to upper case as they are typed.

Number 1 is incorrect. This will not work because KeyAscii is not defined in the routine. And even if it was it does not refer to anything in this routine.

Number 2 is incorrect. This will not work because keyascii is a numeric value.

Number 4 is incorrect. While it will meet the technical requirement, this solution will cause undue pressure on the user to enter the correct character uppercase.


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.


REVIEWNET is a trademark and service mark of ReviewNet Corporation © 1997-2002,
Jenkintown, PA - All Rights Reserved. This information is confidential and proprietary
to ReviewNet Corporation. Use, duplication or misappropriation is strictly prohibited.