473,432 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,432 software developers and data experts.

Parsing

Could someone please point me to a function/module for Access 2000 that will
enable me to parse a string field. So if a field consists of "word_1
word_2 ...... word_n", I would like to be able to select either the first
or the last or any number of consecutive words from the middle (similar to
the 'mid' function for characters).

Many thanks

Dec 18 '05 #1
14 2206
Split

Dec 18 '05 #2
Use the Split() function to break the words into an array.

Then LBound() gives you the first word, UBound() the last, or you can get
the nth element of the array for anything in between.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Peter" <ke******@peterbhurst.f2s.com> wrote in message
news:do**********@news.freedom2surf.net...
Could someone please point me to a function/module for Access 2000 that
will enable me to parse a string field. So if a field consists of
"word_1 word_2 ...... word_n", I would like to be able to select either
the first or the last or any number of consecutive words from the middle
(similar to the 'mid' function for characters).

Dec 18 '05 #3
Thanks, but I do not seem to have Split in Access 2000. Is there another
way or can I import it form somewhere?

Peter

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:43***********************@per-qv1-newsreader-01.iinet.net.au...
Use the Split() function to break the words into an array.

Then LBound() gives you the first word, UBound() the last, or you can get
the nth element of the array for anything in between.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Peter" <ke******@peterbhurst.f2s.com> wrote in message
news:do**********@news.freedom2surf.net...
Could someone please point me to a function/module for Access 2000 that
will enable me to parse a string field. So if a field consists of
"word_1 word_2 ...... word_n", I would like to be able to select either
the first or the last or any number of consecutive words from the middle
(similar to the 'mid' function for characters).


Dec 18 '05 #4
I don't seem to have the "split" function either...
Darn!!
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:43***********************@per-qv1-newsreader-01.iinet.net.au...
Use the Split() function to break the words into an array.

Dec 18 '05 #5
Peter wrote:
Thanks, but I do not seem to have Split in Access 2000. Is there
another way or can I import it form somewhere?


Split() was added in Access 2000. Are you trying to use it or trying to find it
in A2K's terrible help system?
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


Dec 18 '05 #6
Thanks for responding. I have been recommended to use split and L/UBound to
parse a string field in response to my request at the start of this thread.
No - I cannot find 'split' in this context in the on line help.
"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:%k*******************@newssvr29.news.prodigy. net...
Peter wrote:
Thanks, but I do not seem to have Split in Access 2000. Is there
another way or can I import it form somewhere?


Split() was added in Access 2000. Are you trying to use it or trying to
find it in A2K's terrible help system?
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Dec 18 '05 #7
Peter wrote in message <do**********@news.freedom2surf.net> :
Thanks for responding. I have been recommended to use split and L/UBound to
parse a string field in response to my request at the start of this thread.
No - I cannot find 'split' in this context in the on line help.

In VBE (hit Ctrl + g) type Split, then hit F1.

Then, if you also give use some bits and pieces about the purpose
of what you're doing, we might event help;-)

--
Roy-Vidar

Dec 18 '05 #8
Is there a great roll-your-own split function out there. I cobbled one
together yesterday because an e-mail I got asking about same was so
"quaint"!

But it's a few minutes work. Do we have a tested quick one?

Someone in e-mail wrote:
Hello, very much pleasure of greeting yourself!

I have a problem with the code in the module sendmailwithOE.
It is the function "split"
I cannot find her.
Can you send her me?

Thank you very much


Reply:

Hello

Split is a function introduced in Access 2000.

I am guessing that you are using Access 97.

I have taken a few minutes to write a similar function:

Public Function SplitB(ByVal SplitString As String, ByVal Delimiter As
String) As Variant
Dim Position As Long
Dim aSplit() As Variant
Dim Dimension As Long
Position = InStr(SplitString, Delimiter)
Do While Position <> 0
ReDim Preserve aSplit(Dimension)
aSplit(UBound(aSplit)) = Trim(Left(SplitString, Position - 1))
SplitString = Mid$(SplitString, Position + 1)
Dimension = Dimension + 1
Position = InStr(SplitString, Delimiter)
Loop
ReDim Preserve aSplit(Dimension)
aSplit(Dimension) = Trim(SplitString)
SplitB = aSplit
End Function

You could try this, but it is untested and I cannot say that it will
work.

You will, of course, have to replace the "Split" with "SplitB" in your
other code.

How much does a villa cost, anyway?

Lyle Fairfield

Dec 18 '05 #9
> In VBE (hit Ctrl + g) type Split, then hit F1.

Then, if you also give use some bits and pieces about the purpose
of what you're doing, we might event help;-)

--
Roy-Vidar

I have found split within VBA (I Was looking in the build facility for
Queries). This is a copy of my original question:
Could someone please point me to a function/module for Access 2000 that
will enable me to parse a string field. So if a field consists of
"word_1 word_2 ...... word_n", I would like to be able to select either
the first or the last or any number of consecutive words from the middle
(similar to the 'mid' function for characters).


I am no programing wiz, so I need all the help that I can get please!
Dec 18 '05 #10
Peter, here's another example I put together for someone else who was trying
to type a bunch of keywords in a text box, and then filter a form where the
Notes field contained any of them.

Hopefully you can adapt the approach.

Private Sub txtKeywords_AfterUpdate()
Dim strWhere As String
Dim strWord As String
Dim varKeywords As Variant 'Array of keywords.
Dim i As Integer
Dim lngLen As Long

If IsNull(Me.txtKeywords) Then 'Show all if blank.
If Me.FilterOn Then
Me.FilterOn = False
End If
Else
varKeywords = Split(Me.txtKeywords, " ")
If UBound(varKeywords) >= 99 Then '99 words max.
MsgBox "Too many words."
Else
'Build up the Where string from the array.
For i = LBound(varKeywords) To UBound(varKeywords)
strWord = Trim$(varKeywords(i))
If strWord <> vbNullString Then
strWhere = strWhere & "([Notes] Like ""*" & strWord &
"*"") OR "
End If
Next
lngLen = Len(strWhere) - 4 'Without trailing " OR ".
If lngLen > 0 Then
Me.Filter = Left(strWhere, lngLen)
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End If
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Peter" <ke******@peterbhurst.f2s.com> wrote in message
news:do**********@news.freedom2surf.net...
In VBE (hit Ctrl + g) type Split, then hit F1.

Then, if you also give use some bits and pieces about the purpose
of what you're doing, we might event help;-)

--
Roy-Vidar


I have found split within VBA (I Was looking in the build facility for
Queries). This is a copy of my original question:
Could someone please point me to a function/module for Access 2000 that
will enable me to parse a string field. So if a field consists of
"word_1 word_2 ...... word_n", I would like to be able to select either
the first or the last or any number of consecutive words from the middle
(similar to the 'mid' function for characters).


I am no programing wiz, so I need all the help that I can get please!

Dec 18 '05 #11
Peter wrote in message <do**********@news.freedom2surf.net> :
I have found split within VBA (I Was looking in the build facility for
Queries). This is a copy of my original question:
Could someone please point me to a function/module for Access 2000 that
will enable me to parse a string field. So if a field consists of "word_1
word_2 ...... word_n", I would like to be able to select either the first
or the last or any number of consecutive words from the middle (similar to
the 'mid' function for characters).


I am no programing wiz, so I need all the help that I can get please!


Well, here's an attempt, which I think you should be able to use for
instance in a query - note however, it's not tested in VBA.

Public Function mySplit(ByVal v_strInString As String, _
ByVal v_lngOrder As Long, _
Optional ByVal v_lngNumber As Long = 1, _
Optional ByVal v_strDel As String = ", ") _
As String

' v_strInString - the string to delimit
' v_lngOrder 0 = last word
' 1-N = index of word one wishes
' v_lngNumber 1-N = optional number of consecutive words
' wished, if not provided 1 is default
' v_strDelm = optional delimiter used for returned
' string, ", " is default

Dim myarr() As String
Dim lngCounter As Long
Dim lngMax As Long

myarr = Split(v_strInString, " ")
lngMax = Ubound(myarr) + 1
If v_lngOrder >= lngMax Then
v_lngOrder = lngMax
End If
Select Case v_lngOrder
Case 0
mySplit = myarr(lngMax - 1)
Case Else
If v_lngNumber > 1 Then
If v_lngOrder + v_lngNumber < lngMax Then
lngMax = v_lngOrder + v_lngNumber
End If
For lngCounter = v_lngOrder To lngMax - 1
mySplit = mySplit & myarr(lngCounter) & v_strDel
Next
mySplit = Mid$(mySplit, 1, Len(mySplit) - Len(v_strDel))
Else
mySplit = myarr(v_lngOrder - 1)
End If
End Select
End Function
But, allow one comment - if you're storing information in a field
such as you say, it does seem like a violation of first normal
form, and that it perhaps could be better solved with another
table?

--
Roy-Vidar

Dec 18 '05 #12

From Joe "/We Are Borg/" Foster, several years ago. I use this quite
a bit, even in A2K and above. (I seems to work quite well....)

Public Function JoeSplit(ByVal Expression As String, _
Optional ByVal Delimiter As String = " ", _
Optional ByVal Start As Long = 1, _
Optional ByVal Limit As Long = -1, _
Optional ByVal SkipEmptyFields As Boolean = False, _
Optional ByVal vCompare = vbBinaryCompare) _
As Variant

Dim LE As Long: LE = Len(Expression)
Dim LD As Long: LD = Len(Delimiter)

Dim Result() As String
Dim RCount As Long, RMax As Long

' greasy VB6 compatibility stuff
If Limit < -1 Or Start < 1 Then
Err.Raise 5
ElseIf LD > 0 And (LE = 0 Or Limit = 0) Then
JoeSplit = Array()
Exit Function
ElseIf LD = 0 Or Limit = 1 Then
ReDim Result(0 To 0) As String
If Start <> 1 Then Result(0) = Mid$(Expression, Start) _
Else Result(0) = Expression 'StrSwap Result(0), Expression
JoeSplit = Result
Exit Function
End If

If SkipEmptyFields Then RMax = (LE - Start + 1) \ (LD + 1) _
Else RMax = (LE - Start + 1) \ LD
If Limit < 1 Or Limit > 1000 Then _
ReDim Result(0 To RMax) As String _
Else ReDim Result(0 To Limit - 1) As String

Dim Pos1 As Long, Pos2 As Long
Pos1 = Start
Do
If Limit = 1 Then
Pos2 = LE + 1
ElseIf vCompare = vbBinaryCompare Then
Pos2 = InStr(Pos1, Expression, Delimiter, vbBinaryCompare)
Limit = Limit - 1
If Pos2 = 0 Then Pos2 = LE + 1
Else ' slimy performance hack, probably could be improved
' Microsoft has absolutely no excuse whatsoever for making
' this sort of shite necessary or even at all beneficial!
Dim C As Long, p As Long
C = LD * 4
Pos2 = Pos1
Do
p = InStr(1, Mid$(Expression, Pos2, C), Delimiter, vCompare)
If p > 0 Then Pos2 = Pos2 + p - 1: Exit Do
Pos2 = Pos2 + C - 2 * LD ' beware of chr(230) and others!
If C < 600 Then C = C + C \ 2
If Pos2 > LE Then Pos2 = LE + 1: Exit Do
Loop
Limit = Limit - 1
End If

If Pos1 < Pos2 Then
Result(RCount) = Mid$(Expression, Pos1, Pos2 - Pos1)
RCount = RCount + 1
ElseIf SkipEmptyFields = False Then
RCount = RCount + 1
End If

Pos1 = Pos2 + LD
Loop While Pos2 <= LE

If RCount = 0 Then
JoeSplit = Array(): Exit Function
ElseIf RCount <= UBound(Result) Then
ReDim Preserve Result(0 To RCount - 1) As String
End If

JoeSplit = Result
End Function

On 18 Dec 2005 06:47:21 -0800, "Lyle Fairfield"
<ly***********@aim.com> wrote:
Is there a great roll-your-own split function out there. I cobbled one
together yesterday because an e-mail I got asking about same was so
"quaint"!

But it's a few minutes work. Do we have a tested quick one?

--
Drive C: Error. (A)bort (R)etry (S)mack The Darned Thing

Dec 19 '05 #13
But, allow one comment - if you're storing information in a field
such as you say, it does seem like a violation of first normal
form, and that it perhaps could be better solved with another
table?

--
Roy-Vidar

Just to respond to this point, you are probably right. My databases are
strictly for my use and I do not have the time or skill for elegance. The
field in question is 'Place', which can contain any number of words for
which the list is virtually inexhaustible! I have a 'Country' field which
is referenced from a table. The 'Place' field is structured to show
County/State/Region/, City/Area etc up to some 5 to 10 words. The
combinations are too numerous and complex to put into a referenced table.
So if I wish to filter on 'County'. I need to isolate first word, or if on
city, on mid word etc. There is probably a better, more elegant way of
doing this. There is the difficulty over entities with double barrelled
names (e.g. North Yorkshire), which I enter with an underscore
(North_Yorkshire), but possibly some function which selects word between
standard delimiters might work better.

Peter
Dec 19 '05 #14

Thanks ever one for being so helpful. I will try out the various
suggestions.

Peter
Dec 19 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
0
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
5
by: randy | last post by:
Can some point me to a good example of parsing XML using C# 2.0? Thanks
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
7
by: Daniel Fetchinson | last post by:
Many times a more user friendly date format is convenient than the pure date and time. For example for a date that is yesterday I would like to see "yesterday" instead of the date itself. And for...
1
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.