ahuimanu

Chapter 7, Ex. 15

Jun 18th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     'first we declare our variables
  2.    Dim firstName As String     'using this to hold first name
  3.    Dim length As Integer       'using this to store the length of the name
  4.    Dim val As Integer          'using this to hold the ascii numeric value of a character in the string
  5.    Dim counter As Integer      'using this to control the do/while loop
  6.    Dim flag As Boolean         'raise this when a invalid character is encountered
  7.    
  8.     counter = 1
  9.    
  10.     firstName = InputBox("Give me your first name please", "Prompt")
  11.    
  12.     length = Len(firstName)
  13.    
  14.     Do While counter <= length
  15.    
  16.         val = Asc(Left(firstName, counter))
  17.        
  18.         'check for ascii, see http://www.techonthenet.com/ascii/chart.php
  19.        If (val >= 65 And val <= 90) Or (val >= 97 And val <= 122) Then
  20.             'all is well, keep going
  21.        Else
  22.             flag = True
  23.             Exit Do
  24.         End If
  25.        
  26.         counter = counter + 1
  27.    
  28.     Loop
  29.    
  30.     If flag Then
  31.         MsgBox "An invalid character was found", vbCritical, "Result"
  32.     Else
  33.         MsgBox "All is well", vbInformation, "Result"
  34.     End If
  35.  
  36. End Sub
Advertisement
Add Comment
Please, Sign In to add comment