Solved

Seperate Strings into words

Posted on 2000-05-14
6
180 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
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

791 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