From jacobson@math-cs.cns.uni.edu Fri Sep 6 20:23:43 2002 Date: Fri, 06 Sep 2002 17:43:54 -0500 (CDT) From: Mark Jacobson To: 810-030-01@uni.edu Subject: Assignment #1 hints and VB code... Hi 030 VB students, The assignment due Monday can be turned in until 9 p.m. on Tuesday evening, by sliding it under my office door, if you do not get it done by Monday in time for class at 2 p.m. Here is some code you can adapt, if you want to handle the txtSSN issue mentioned at the bottom of the 2nd page of your handout. It keeps the spaces and slashes and hyphens and all non-digit characters out of the textbox for the Social Security Number. That textbox is aptly named, txtSSN, but could have easily been called txtSocialSecurityNumber as well. ' Examples of how to take care of the problem of only accepting digits, ' i.e. only allowing 0, 1, 2, 3, ... 8, 9 in the txtSSN textbox. ' Also illustrated what we did in lab today, how to keep the space out ' of two part last names like Van Lent, because we need it to be VanLent ' to make the COBRA or UNI ACAD ID. Private Sub txtLastName_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeySpace Then KeyAscii = 0 End If End Sub Private Sub txtSSN_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 57) Then ' NOT a digit since ASCII value ' of 0 is 48, ASCII of 9 is 57 If KeyAscii <> vbKeyBack And KeyAscii <> vbKeyReturn Then KeyAscii = 0 ElseIf KeyAscii = vbKeyReturn Then txtBirthday.SetFocus End If End If End Sub ' Note that the ASCII value of the null character is 0. ' Thus KeyAscii = 0 means whatever the user typed into the textbox ' got replaced by the null character, which is nothing. See you on Monday. Mark