Solved

Seperate Strings into words

Posted on 2000-05-14
6
182 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

759 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