Solved

Seperate Strings into words

Posted on 2000-05-14
6
183 Views
Last Modified: 2010-05-02
Hi

How do you seperate a string, e.g. a Surname from a Christian Name with VBA.

Regards
admoller
0
Comment
Question by:admoller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:ofirg
ID: 2808079
It's hard for me to understand what is it you want to do, but the best way to seperate a string to word is by the "split" function

Joy and Happiness
0
 
LVL 44

Expert Comment

by:bruintje
ID: 2808166
that depends on how the string is formed

example

declare a few public variables in the module

Dim m_strSurName As String
Dim m_strCristianName As String

then take this function

function SplitNames(Byval Name As String) As Boolean

Dim strCompleteName As String
Dim lngSeper As Long

strName = "Hakkebar, Bertje"

'get the position of the seperator
lngSeper = InStr(1, ",", strName)

m_strSurName = Left(strName, Len(strName) - lngSeper + 1)

m_strChristianName = Right(strName, Len(strName) - lngSeper + 1)

end function


something like this, of course it still depends on the format of your names, but the idea is clear ....

can be errorprone, no testing done :O)

HTH:O)Bruintje
0
 
LVL 6

Accepted Solution

by:
Marine earned 50 total points
ID: 2808236
'Say this is input
'"Hakkebar, Bertje"
strName = "Hakkebar, Bertje"
sArray = Split(strName,",")

msgbox sArray(0) & "  " & sArray(1)

you can loop now ofcourse from lBound to Ubound of sArray since when you use Split Function it creates an array of values for you. In this example teh delimter that is used is a comma.
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 28

Expert Comment

by:AzraSound
ID: 2808615
let it be noted that the split function is only available in vb6 but the Instr function works just as well here as bruintje points out
0
 

Author Comment

by:admoller
ID: 2808760
Thanks Marine
I had noticed before the split function mentioned - but there was little help in the help on it. Your example is bang-on.
regards
admoller
0
 
LVL 6

Expert Comment

by:Marine
ID: 2808816
Your Welcome.
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month5 days, 15 hours left to enroll

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question