
-----------------------------------
peterggmss
Tue Dec 05, 2006 1:30 pm

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:

    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

-----------------------------------
cool dude
Tue Dec 05, 2006 3:16 pm


-----------------------------------
ever heard of the Mid function?

-----------------------------------
Silent Avenger
Tue Dec 05, 2006 4:33 pm


-----------------------------------
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.

-----------------------------------
peterggmss
Wed Dec 06, 2006 1:34 pm


-----------------------------------
Thanks, I tried using Mid, but it didn't work - turned out that I was using the wrong variable. :oops:  :lol:

-----------------------------------
cool dude
Wed Dec 06, 2006 3:34 pm


-----------------------------------
Thanks, I tried using Mid, but it didn't work - turned out that I was using the wrong variable. :oops:  :lol:

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. :)

-----------------------------------
peterggmss
Thu Dec 07, 2006 1:36 pm


-----------------------------------
Thanks, I tried using Mid, but it didn't work - turned out that I was using the wrong variable. :oops:  :lol:

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. :)Yea, i did.  Thanks.
