Try this..
CODE
Private Sub cmdGroup_Click()
Dim strName As String
Dim intFirstLetterPos As Integer
Dim strFirstLetter As String
strName = txtName.Text
intFirstLetterPos = InStr(strName, " ") + 1
strFirstLetter = UCase(Mid(strName, intFirstLetterPos, 1))
If Asc(strFirstLetter) >= 65 And Asc(strFirstLetter) <= 73 Then
lblGroup.Caption = "Group 1"
ElseIf Asc(strFirstLetter) >= 74 And Asc(strFirstLetter) <= 83 Then
lblGroup.Caption = "Group 2"
ElseIf Asc(strFirstLetter) >= 84 And Asc(strFirstLetter) <= 90 Then
lblGroup.Caption = "Group 3"
End If
End Sub
This code is assuming that whoever has typed their name in has separated their first name and last name by a space. It first finds the location of the space, and then adds one to that, which will be the location of the first letter of the last name.
It then uses the mid function combined with the UCase function to extract that first letter into the string "strFirstLetter" as well as ensure that it is in capital form (because capitals and lowercase have different number equivalents).
It then uses the Asc function to convert that single letter into its number equivalent and checks to see which range it's in. 65 is "A", 73 is "I", and all the numbers in between have letter equivalents that would be between "A" and "I" in the alphabet.
This post has been edited by Zhalix: 15 May, 2008 - 06:26 PM