Results 1 to 4 of 4

Thread: Monogram

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Posts
    49

    Monogram

    I have a program that when i enter a first middle and last name like "John Doe Smith" into a text box named txt1 it will print the initals like this "jDs" to a label named lbl1.

    This is a code that I used and it only gives what I put in like if I put in "John Doe Smith" into a text box the label displays "JDS" and if i put in "john doe smith" the label prints out "jds" and you get the idea.

    So here is the code, Can someone fix it up a bit so i get what I need?

    Dim strArr() As String, intIdx As Integer
    strArr() = Split(txt1.text,"")
    For intIdx = 0 To Ubound(strArr)
    lbl1.caption = lbl1.caption & Left$(strArr(intIdx), 1)
    Jak

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strArr() As String, intIdx As Integer
    3. lbl1.Caption = ""
    4. strArr() = Split(txt1.Text, " ") ' You left out a space between the quotes
    5. For intIdx = 0 To UBound(strArr)
    6.     lbl1.Caption = lbl1.Caption & Left$(strArr(intIdx), 1)
    7. Next
    8.  
    9. If Len(lbl1.Caption) = 3 Then
    10.     lbl1.Caption = UCase(Left(strArr(0), 1)) & LCase(Left(strArr(1), 1)) & UCase(Left(strArr(2), 1))
    11. End If
    12.  
    13. End Sub

  3. #3
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    From what I can understand I think this might be the alteration you're after.

    VB Code:
    1. Dim strArr() As String, intIdx As Integer, sChr As String
    2.   strArr() = Split(txt1.Text, " ")
    3.  
    4.   For intIdx = 0 To UBound(strArr)
    5.     sChr = Left$(strArr(intIdx), 1)
    6.    
    7.     If (intIdx <> 0) And (intIdx <> UBound(strArr)) Then sChr = UCase(sChr)
    8.    
    9.     lbl1.Caption = lbl1.Caption & sChr
    10.   Next intIdx
    -adehh

  4. #4
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    This is the function I use:

    VB Code:
    1. Function Initials(iString As String, iDelim As String) As String
    2. Dim tmpCount As Integer
    3. Dim tmpString As String
    4. tmpString = iString
    5.  
    6. Initials = ""
    7. tmpString = Trim(tmpString)
    8. If tmpString = "" Then Exit Function
    9.  
    10. Initials = Left(tmpString, 1)
    11.  
    12. 'scan string to find start of each word
    13. For tmpCount = 2 To Len(tmpString)
    14.     If InStr(" !.,:/-\?;" + Chr(34), Mid(tmpString, tmpCount - 1, 1)) > 0 Then
    15.         Initials = Initials + iDelim + Mid(tmpString, tmpCount, 1)
    16.     End If
    17. Next
    18.  
    19. End Function

    Usage:

    Result = Initials("John Doe Smith","")
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width