|
-
Mar 11th, 2004, 05:46 PM
#1
Thread Starter
Member
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)
-
Mar 11th, 2004, 05:59 PM
#2
VB Code:
Private Sub Command1_Click()
Dim strArr() As String, intIdx As Integer
lbl1.Caption = ""
strArr() = Split(txt1.Text, " ") ' You left out a space between the quotes
For intIdx = 0 To UBound(strArr)
lbl1.Caption = lbl1.Caption & Left$(strArr(intIdx), 1)
Next
If Len(lbl1.Caption) = 3 Then
lbl1.Caption = UCase(Left(strArr(0), 1)) & LCase(Left(strArr(1), 1)) & UCase(Left(strArr(2), 1))
End If
End Sub
-
Mar 11th, 2004, 05:59 PM
#3
Hyperactive Member
From what I can understand I think this might be the alteration you're after.
VB Code:
Dim strArr() As String, intIdx As Integer, sChr As String
strArr() = Split(txt1.Text, " ")
For intIdx = 0 To UBound(strArr)
sChr = Left$(strArr(intIdx), 1)
If (intIdx <> 0) And (intIdx <> UBound(strArr)) Then sChr = UCase(sChr)
lbl1.Caption = lbl1.Caption & sChr
Next intIdx
-adehh
-
Mar 12th, 2004, 04:34 AM
#4
Frenzied Member
This is the function I use:
VB Code:
Function Initials(iString As String, iDelim As String) As String
Dim tmpCount As Integer
Dim tmpString As String
tmpString = iString
Initials = ""
tmpString = Trim(tmpString)
If tmpString = "" Then Exit Function
Initials = Left(tmpString, 1)
'scan string to find start of each word
For tmpCount = 2 To Len(tmpString)
If InStr(" !.,:/-\?;" + Chr(34), Mid(tmpString, tmpCount - 1, 1)) > 0 Then
Initials = Initials + iDelim + Mid(tmpString, tmpCount, 1)
End If
Next
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|