Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'first we declare our variables
- Dim firstName As String 'using this to hold first name
- Dim length As Integer 'using this to store the length of the name
- Dim val As Integer 'using this to hold the ascii numeric value of a character in the string
- Dim counter As Integer 'using this to control the do/while loop
- Dim flag As Boolean 'raise this when a invalid character is encountered
- counter = 1
- firstName = InputBox("Give me your first name please", "Prompt")
- length = Len(firstName)
- Do While counter <= length
- val = Asc(Left(firstName, counter))
- 'check for ascii, see http://www.techonthenet.com/ascii/chart.php
- If (val >= 65 And val <= 90) Or (val >= 97 And val <= 122) Then
- 'all is well, keep going
- Else
- flag = True
- Exit Do
- End If
- counter = counter + 1
- Loop
- If flag Then
- MsgBox "An invalid character was found", vbCritical, "Result"
- Else
- MsgBox "All is well", vbInformation, "Result"
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment