Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please Help Me to PHM 1

Status
Not open for further replies.

IknowMe

Programmer
Aug 6, 2004
1,214
US
For x = 1 To CountFields("Mary Had A Little Lamb", " ")
sAbreviation = sAbreviation & Left(nthField(Mary Had A Little Lamb",x), 1)
Next

sAbreviation = "MHALL" after the loop above (In REAL BASIC) is there something similar in VBA?

I have a workaround but it sure feels clunky

Code:
Sub main()
sOriginalString = "Mary Had A Little Lamb"
sStringSplit = Split(sOriginalString, " ")

For x = LBound(sStringSplit) To UBound(sStringSplit)
   sAbbreviation = sAbbreviation & Left(sStringSplit(x), 1)
Next

MsgBox "final = " & sAbbreviation
End Sub



[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
For Each f In Split("Mary Had A Little Lamb")
sAbbreviation = sAbbreviation & Left(f, 1)
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
It's not too clunky actually. You could step through it, but I think you'll like yours better (as do I) when you look at them side by side...

Code:
Sub main()
    Dim sOriginalString As String, sStringSplit() As String
    Dim sAbbreviation As String, x As Long
    sOriginalString = "Mary Had A Little Lamb"
    sStringSplit = Split(sOriginalString, " ")
    For x = LBound(sStringSplit) To UBound(sStringSplit)
        sAbbreviation = sAbbreviation & Left(sStringSplit(x), 1)
    Next
    MsgBox "final = " & sAbbreviation
End Sub

Sub main2()
    Dim sAbbreviation As String, sOriginalString As String, x As Long
    sOriginalString = "Mary Had A Little Lamb"
    sAbbreviation = Left(sOriginalString, 1)
    For x = 1 To Len(sOriginalString) - Len(Replace(sOriginalString, " ", ""))
        sAbbreviation = sAbbreviation & Mid(sOriginalString, InStr(1, sOriginalString, " ") + 1, 1)
        sOriginalString = Right(sOriginalString, Len(sOriginalString) - InStr(1, Replace(sOriginalString, " ", "~", 1, 1), "~"))
    Next x
    MsgBox "final = " & sAbbreviation
End Sub

HTH

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
@Firefytr I definately like it better than your example in Sub Main2. But PHV's was exactly what I was looking for.

Thanks to both for your informative and prompt responses and helping to expidite my learning curve of VBA.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
I also found this useful.

For x = 2 To 3
MsgBox left(Split("Mary Had A Little Lamb")(x),2)
Next

I'm writing a proximal match function for commonly abbreviated names

"Fraternal Order of Monkeys" "FOM" ect. ect.

Again thanks for all your help

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top