Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3426770
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:45:21+00:00 2026-05-18T06:45:21+00:00

Hey all, i am trying to split a users name but i am having

  • 0

Hey all, i am trying to split a users name but i am having problems with doing so. Below is my version if the user name has a “go by” name in brackets ():

theName = "Gates, Bill W. (Bill)"
hasBracket = False

If InStr(theName, "(") <> 0 Then
    hasBracket = True
End If

If hasBracket = True Then
    bracketPos = InStr(theName, ",")

    lName = StrConv(Trim(Left(theName, bracketPos - 1)), vbProperCase)

    theName = Trim(Mid(theName, bracketPos + 2))
    bracketPos = InStr(theName, " ")

    fName = StrConv(Trim(Left(theName, bracketPos - 1)), vbProperCase)

    theName = Trim(Mid(theName, bracketPos))

    If Trim(Left(theName, 1)) <> "(" Then
        mName = StrConv(Replace(Trim(Left(theName, 1)), ".", ""), vbProperCase)
    Else
        mName = ""
    End If

    bracketPos = InStr(theName, "(")

    bName = StrConv(Replace(Replace(Trim(Mid(theName, bracketPos)), "(", ""), ")", ""), vbProperCase)
Else
    ...
End If

That part works just fine as long as it has the “()” in the user name. Now going to the ELSE part where the “()” are not used is somewhat of a challenge for me it seems. Problem being is that the user name can be formatted as such:

Gates, Bill W.
Gates, Bill

Maybe i am just over thinking it but i can not seem to check if it has a middle name or not using the code from above for the ELSE section:

ELSE
    bracketPos = InStr(theName, ",")

    lName = StrConv(Trim(Left(theName, bracketPos - 1)), vbProperCase)

    theName = Trim(Mid(theName, bracketPos + 2))
    bracketPos = InStr(theName, " ")

    If bracketPos <> 0 Then
        fName = StrConv(Trim(Left(theName, bracketPos - 1)), vbProperCase)
    End If

    theName = Trim(Mid(theName, bracketPos))

    If Trim(Left(theName, 1)) <> "(" Then
        mName = StrConv(Replace(Trim(Left(theName, 1)), ".", ""), vbProperCase)
    Else
        mName = ""
    End If

    MsgBox lName & " " & fName & " " & mName
END IF

The code above works just fine if the user name is “Gates, Bill W.” but not if its “Gates, Bill”. What can i do in order to check to see if it has a middle name because currently, if it does not, then i get an error on line:

theName = Trim(Mid(theName, bracketPos))

Any help would be great, thanks! :o)

David

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:45:22+00:00Added an answer on May 18, 2026 at 6:45 am

    I dont know why i didnt think of this before! Solved! :o)

    Dim arryTmp() As String
    Dim theName As String
    Dim fName As String
    Dim lName As String
    Dim mName As String
    Dim bName As String
    
    theName = "Gates, Bill W."
    arryTmp = Split(theName, " ")
    
    If InStr(theName, "(") <> 0 Then
        If UBound(arryTmp) = 3 Then
            lName = Replace(StrConv(Trim(arryTmp(0)), vbProperCase), ",", "")
            fName = StrConv(Trim(arryTmp(1)), vbProperCase)
            mName = Replace(StrConv(Trim(arryTmp(2)), vbProperCase), ".", "")
            bName = Replace(Replace(StrConv(Trim(arryTmp(3)), vbProperCase), ")", ""), "(", "")
        ElseIf UBound(arryTmp) = 2 Then
            lName = Replace(StrConv(Trim(arryTmp(0)), vbProperCase), ",", "")
            fName = StrConv(Trim(arryTmp(1)), vbProperCase)
            mName = Replace(StrConv(Trim(arryTmp(2)), vbProperCase), ".", "")
        ElseIf UBound(arryTmp) = 1 Then
            lName = Replace(StrConv(Trim(arryTmp(0)), vbProperCase), ",", "")
            fName = StrConv(Trim(arryTmp(1)), vbProperCase)
        End If
    Else
        If UBound(arryTmp) = 3 Then
            lName = Replace(StrConv(Trim(arryTmp(0)), vbProperCase) & " " & StrConv(Trim(arryTmp(1)), vbProperCase), ",", "")
            fName = StrConv(Trim(arryTmp(2)), vbProperCase)
            mName = Replace(StrConv(Trim(arryTmp(3)), vbProperCase), ".", "")
        ElseIf UBound(arryTmp) = 2 Then
            lName = Replace(StrConv(Trim(arryTmp(0)), vbProperCase), ",", "")
            fName = StrConv(Trim(arryTmp(1)), vbProperCase)
            mName = Replace(StrConv(Trim(arryTmp(2)), vbProperCase), ".", "")
        ElseIf UBound(arryTmp) = 1 Then
            lName = Replace(StrConv(Trim(arryTmp(0)), vbProperCase), ",", "")
            fName = StrConv(Trim(arryTmp(1)), vbProperCase)
        End If
    End If
    
    MsgBox lName & " " & fName & " " & mName & " " & bName
    
    MsgBox lName & " " & fName & " " & mName & " " & bName
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my
Hey all - I have an app where I'm authenticating the user. They pass
Hey all, my Computational Science course this semester is entirely in Java. I was
Hey all, I have something of an interesting requirement for my project. I need
Hey all. We're sending quite a few emails (around 23k) using IIS6 SMTP service
Hey all, I'm pulling my hair out on this one. I've checked all my
Hey all. I have a server written in java using the ServerSocket and Socket
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey so what I want to do is snag the content for the first
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.