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!

First-letter of word/acronym creator

Status
Not open for further replies.

rookievb6

MIS
Nov 27, 2002
1
ES
I am setting up a login system for our new computers. I want the login names to be automatically made through a computer program that takes the first letter of the first, middle and last names as well as the first letter of their title, department, and department number from an entered string. For example,
John Frederick Doe, Customer Service Representative, Human Resources, 23HR
would be JFDCSRHR2 for identification purposes. I am trying to use the INstr function to locate the spaces, but I cannot get it to all work out for me. Any suggestions would be helpful. Thanks.
 
Dim StartArray() As String
Dim RetStr As String
Dim ProcStr As Variant

RetArray = Split(YourStr, " ")

For Each ProcStr In RetArray
RetStr = RetStr + Left(ProcStr, 1)
Next
 
Option Explicit

Private Sub Form_Load()
Dim sTargetString As String
Dim sParsedArrayAllRecords() As String
Dim sParsedArraySingleRecords() As String
Dim sID As String
Dim iCountAllRecords As Integer
Dim iCountSingleRecord As Integer


sTargetString = "John Frederick Doe, Customer Service Representative, Human Resources, 23HR"
sParsedArrayAllRecords = Split(sTargetString, ",")

For iCountAllRecords = LBound(sParsedArrayAllRecords) To UBound(sParsedArrayAllRecords)
If iCountAllRecords = 0 Then
sParsedArraySingleRecords = Split(sParsedArrayAllRecords(iCountAllRecords), " ")
For iCountSingleRecord = LBound(sParsedArraySingleRecords) To UBound(sParsedArraySingleRecords)
sID = sID & Left$(sParsedArraySingleRecords(iCountSingleRecord), 1)
Next
End If

If iCountAllRecords = 1 Then
sParsedArraySingleRecords = Split(sParsedArrayAllRecords(iCountAllRecords), " ")
For iCountSingleRecord = LBound(sParsedArraySingleRecords) To UBound(sParsedArraySingleRecords)
sID = sID & Left$(sParsedArraySingleRecords(iCountSingleRecord), 1)
Next
End If

If iCountAllRecords = 2 Then
sParsedArraySingleRecords = Split(sParsedArrayAllRecords(iCountAllRecords), " ")
For iCountSingleRecord = LBound(sParsedArraySingleRecords) To UBound(sParsedArraySingleRecords)
sID = sID & Left$(sParsedArraySingleRecords(iCountSingleRecord), 1)
Next
End If

If iCountAllRecords = 3 Then
sParsedArraySingleRecords = Split(sParsedArrayAllRecords(iCountAllRecords), " ")
For iCountSingleRecord = LBound(sParsedArraySingleRecords) To UBound(sParsedArraySingleRecords)
sID = sID & Left$(sParsedArraySingleRecords(iCountSingleRecord), 1)
Next
End If
Next
MsgBox sID

End Sub
 
After thought:
Is it possible that one or more of your elements might be empty? Like NAME,,,,,
You might consider changing your string to uppercase and the replace all commas with lowercase letters, like :
NAME,,,,, to NAME n n n n n, would then return Nnnnnn, Instead of N,,,,, or Nabcde.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top