Computer Science Canada

How do I find the first letter of the second word in string?

Author:  peterggmss [ Tue Dec 05, 2006 1:30 pm ]
Post subject:  How do I find the first letter of the second word in string?

Hello,
I would like some help with my programming. I can display the first letter of the first word, but with the second word it gets confusing, I know where the second word starts, but need to know how to use Left() to get the first letter of the second word. Here's my code:

code:
    Dim First, Second, Last, LastName As String
    Dim LastPos As Single
   
Private Sub cmdDisplay_Click()
   
    'Make Sure that the names are words
    If IsNumeric(txtName.Text) Then
        txtName.Text = ""
        MsgBox ("Please enter your NAME!")
        txtName.SetFocus
        End
    End If
   
    'Make sure that the first character is a letter
    If Left(txtName.Text, 1) = " " Then
        txtName.Text = ""
        MsgBox ("You cannot have a space as your first name!")
        txtName.SetFocus
        End
    End If
   
    First = Left(txtName.Text, 1)
   
    Last = InStr(2, txtName.Text, " ", vbTextCompare)
   
    LastPos = Len(txtName.Text) - Last
   
    Second = Left(txtName.Text, Last)
   
    lblInitials.Caption = UCase(First) + UCase(Second)

End Sub

Author:  cool dude [ Tue Dec 05, 2006 3:16 pm ]
Post subject: 

ever heard of the Mid function?

Author:  Silent Avenger [ Tue Dec 05, 2006 4:33 pm ]
Post subject: 

Check out cool dude's tutorial which is here: http://www.compsci.ca/v2/viewtopic.php?t=13107 I believe that the mid function is under day 4 of the tutorial and it will explain how to use the mid function.

Author:  peterggmss [ Wed Dec 06, 2006 1:34 pm ]
Post subject: 

Thanks, I tried using Mid, but it didn't work - turned out that I was using the wrong variable. Embarassed Laughing

Author:  cool dude [ Wed Dec 06, 2006 3:34 pm ]
Post subject: 

peterggmss wrote:
Thanks, I tried using Mid, but it didn't work - turned out that I was using the wrong variable. Embarassed Laughing


did you get it fixed? if not post your code on how your using the Mid function so that we can tell you where your mistake is. Smile

Author:  peterggmss [ Thu Dec 07, 2006 1:36 pm ]
Post subject: 

cool dude wrote:
peterggmss wrote:
Thanks, I tried using Mid, but it didn't work - turned out that I was using the wrong variable. Embarassed Laughing


did you get it fixed? if not post your code on how your using the Mid function so that we can tell you where your mistake is. Smile
Yea, i did. Thanks.


: