Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How do I find the first letter of the second word in string?
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
peterggmss




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Tue Dec 05, 2006 3:16 pm   Post subject: (No subject)

ever heard of the Mid function?
Silent Avenger




PostPosted: Tue Dec 05, 2006 4:33 pm   Post subject: (No 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.
peterggmss




PostPosted: Wed Dec 06, 2006 1:34 pm   Post subject: (No subject)

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




PostPosted: Wed Dec 06, 2006 3:34 pm   Post subject: (No 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
peterggmss




PostPosted: Thu Dec 07, 2006 1:36 pm   Post subject: (No 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.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: