473,397 Members | 1,969 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,397 software developers and data experts.

Extract Numbers from Memo field

Hope someone can help!
I have a memo fiels in which there are a few numbers including dates but
what I want to do is extract a number which is 6 figures long. Can anyone
help me?
Thanks Dave
Jul 16 '06 #1
6 5937
"Dave" wrote
I have a memo fiels in which there are
a few numbers including dates but
what I want to do is extract a number
which is 6 figures long. Can anyone
help me?
What indication do you have exactly where the text representing that number
_is_ in the Memo Field? The Left, Right, and Mid functions work nicely to
extract a text string from a larger text string, but you have to know the
character position where it begins (and where it ends, or how long it is).
If it is preceded by some title/label, it may be possible to use the InStr
function to locate the title/label's location, then add the necessary length
to determine the first character of the numeric string.

Larry Linson
Microsoft Access MVP
Jul 16 '06 #2
The only indication I have is that it is 6 figures long and looking at a
sample in the field it seems to be the only one that is this number of
figures. It is all I have to work with.

"Dave" <da*******@btinternet.comwrote in message
news:de********************@bt.com...
Hope someone can help!
I have a memo fiels in which there are a few numbers including dates
but what I want to do is extract a number which is 6 figures long. Can
anyone help me?
Thanks Dave

Jul 16 '06 #3
Dave wrote:
Hope someone can help!
I have a memo fiels in which there are a few numbers including dates but
what I want to do is extract a number which is 6 figures long. Can anyone
help me?
Thanks Dave
This requires that VB Script be installed. TTBOMK it is installed by
default with Windows >=2000.

Public Function SixDigitNumerals(ByVal vInput As String) As Variant
' assumes VBScript is installed
Dim RE As Object
Dim SDNMatches As Object
Dim SDN As Variant
Dim SDNS As String
Set RE = CreateObject("VBScript.RegExp")
With RE
.Global = True
.Pattern = "(\b|\D)\d{6}(\D|\b)"
End With
Set SDNMatches = RE.Execute(vInput)
For Each SDN In SDNMatches
SDNS = SDNS & "," & Mid$(SDN, 2, 6)
Next SDN
SDNS = Replace(SDNS, ",", "", , 1)
SixDigitNumerals = Split(SDNS, ",")

End Function

Sub test()
Dim s As Variant
Dim ss As Variant
s = SixDigitNumerals("a666666da55555a7777777g000000")
For Each ss In s
Debug.Print ss
Next ss
End Sub

It returns 666666 and 000000

It does not return the five digit 55555 nor the seven digit 7777777. It
could be adjusted according to your needs.

The function is not mature. I dashed it off while waiting for supper,
so it's only very slightly advanced beyond air code.

Maybe it needs the two objects to be released. I tend not to do this
unless VBA forces me to.

I wrote this in Google's TextBox ... at times it went nuts and showed
everything several times ... I hope it posts OK.

Jul 16 '06 #4
The function posted previously did not handle "666666abc..." correctly.
This is a revision with notes:

Public Function SixDigitNumerals(ByVal vInput As String) As Variant

' creates pointers to objects
Dim RE As Object
Dim RE2 As Object

' creates pointers to objects
Dim SDNMatches As Object
Dim SDNMatches2 As Object

' creates a pointer to a variant
Dim SDN As Variant

' creates a pointer to a string
Dim SDNS As String

' references the VBScript Library
' reserves space in memory
' for twp VBScript Regular Expression Objects
' adn their objects and properties
' and loads default values
Set RE = CreateObject("VBScript.RegExp")
Set RE2 = CreateObject("VBScript.RegExp")

' establishes the pattern
' which Regular Expression 2 will attempt to match
' this pattern is
' 6 digits
RE2.Pattern = "\d{6}"

With RE
' sets the Global Property
' of Regular Expression 1 to True
' thus directing that all searches and matches
' will find all matching patterns
' rather than just the first one
.Global = True

' establishes the pattern
' which the Regular Expression will attempt to match
' this pattern is

' (\^|\D) -begin at a input beginning
' or a non-digit character

' \d{6} -six digits

' (\D|\b) -end at a non-digit character
' or at input end
.Pattern = "(^|\D)\d{6}(\D|$)"
End With

' performs a search, matching
' in vInput for the pattern
' established above
' storing results in SDNMatches
' a collection like object
Set SDNMatches = RE.Execute(vInput)

For Each SDN In SDNMatches
' performs a search
' on each of the matches found
' matching just the 6 digits
Set SDNMatches2 = RE2.Execute(SDN)

' adds a comma
' and the 6 digit substring
' to our working string
SDNS = SDNS & "," & SDNMatches2(0)
Next SDN

' removes the first comma from the working string
SDNS = Replace(SDNS, ",", "", , 1)

' splits SDNS into a variant array
' of all 6 digit numerals in vInput
' and assigns the array to the function
' as its value
' (returns the array)
SixDigitNumerals = Split(SDNS, ",")
End Function

Jul 17 '06 #5
"Lyle Fairfield" <ly***********@aim.comwrote in message
<11**********************@m73g2000cwd.googlegroups .com>:
The function posted previously did not handle "666666abc..."
correctly. This is a revision with notes:

Public Function SixDigitNumerals(ByVal vInput As String) As Variant

' creates pointers to objects
Dim RE As Object
Dim RE2 As Object

' creates pointers to objects
Dim SDNMatches As Object
Dim SDNMatches2 As Object

' creates a pointer to a variant
Dim SDN As Variant

' creates a pointer to a string
Dim SDNS As String

' references the VBScript Library
' reserves space in memory
' for twp VBScript Regular Expression Objects
' adn their objects and properties
' and loads default values
Set RE = CreateObject("VBScript.RegExp")
Set RE2 = CreateObject("VBScript.RegExp")

' establishes the pattern
' which Regular Expression 2 will attempt to match
' this pattern is
' 6 digits
RE2.Pattern = "\d{6}"

With RE
' sets the Global Property
' of Regular Expression 1 to True
' thus directing that all searches and matches
' will find all matching patterns
' rather than just the first one
.Global = True

' establishes the pattern
' which the Regular Expression will attempt to match
' this pattern is

' (\^|\D) -begin at a input beginning
' or a non-digit character

' \d{6} -six digits

' (\D|\b) -end at a non-digit character
' or at input end
.Pattern = "(^|\D)\d{6}(\D|$)"
End With

' performs a search, matching
' in vInput for the pattern
' established above
' storing results in SDNMatches
' a collection like object
Set SDNMatches = RE.Execute(vInput)

For Each SDN In SDNMatches
' performs a search
' on each of the matches found
' matching just the 6 digits
Set SDNMatches2 = RE2.Execute(SDN)

' adds a comma
' and the 6 digit substring
' to our working string
SDNS = SDNS & "," & SDNMatches2(0)
Next SDN

' removes the first comma from the working string
SDNS = Replace(SDNS, ",", "", , 1)

' splits SDNS into a variant array
' of all 6 digit numerals in vInput
' and assigns the array to the function
' as its value
' (returns the array)
SixDigitNumerals = Split(SDNS, ",")
End Function
I've taken the liberty of doing a small alteration of the pattern -
grouping, then doing some alterations of the function, utilizing the
submatches collection of the match object (watch for linebreaks).
http://msdn.microsoft.com/library/de...0e7e82faa5.asp

Function rvsSixDigits(ByVal v_strIn As String) As Variant

Dim re As Object
Dim SDNMatches As Object
Dim SDN As Object
Dim SDNS As String

Set re = CreateObject("vbscript.regexp")

With re
.Global = True
.Pattern = "(^|\D)(\d{6})(\D|$)"
Set SDNMatches = .Execute(v_strIn)
For Each SDN In SDNMatches
SDNS = SDNS & "," & SDN.SubMatches(1)
Next SDN
SDNS = Replace(SDNS, ",", "", , 1)
End With

rvsSixDigits = Split(SDNS, ",")

End Function

--
Roy-Vidar
Jul 17 '06 #6
RoyVidar wrote:
Function rvsSixDigits(ByVal v_strIn As String) As Variant

Dim re As Object
Dim SDNMatches As Object
Dim SDN As Object
Dim SDNS As String

Set re = CreateObject("vbscript.regexp")

With re
.Global = True
.Pattern = "(^|\D)(\d{6})(\D|$)"
Set SDNMatches = .Execute(v_strIn)
For Each SDN In SDNMatches
SDNS = SDNS & "," & SDN.SubMatches(1)
Next SDN
SDNS = Replace(SDNS, ",", "", , 1)
End With

rvsSixDigits = Split(SDNS, ",")

End Function
Very nice; I didn't know VBScript's RegExp had submatches, and have
never been successful in VBS with using $n.
I think if one wanted an example of why we strive for elegant solutions
one might read this thread.

Jul 17 '06 #7

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

Similar topics

3
by: GorDon | last post by:
Hi, I have a report based on a query. The query grabs a memo field from my main table, yet when I display the memo field in the report it truncates the memo field (the field needs to hold more...
5
by: klall | last post by:
Hello. I need to extract date information from a memo field entered in the following way: 01/01/2005 - 31/12/2005 01/01/2004 - 31/12/2004 01/01/2003 - 31/12/2003 01/01/1996 - 31/12/1996. The...
8
by: Fabian Braennstroem | last post by:
Hi, I would like to remove certain lines from a log files. I had some sed/awk scripts for this, but now, I want to use python with its re module for this task. Actually, I have two different...
9
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo...
1
by: dangier | last post by:
I have an Access 2003 table with an XML field that is tagged as follows: <Calendar CompactMode="1"><CustomProperties><CustomProperty Name="startdate" Value="3/26/2007"...
2
by: Roger | last post by:
I've got two tables in sql2005 which have an 'ntext' field when I linked the first table in access97 last week using an odbc data source the access-field type was 'memo' when I link the 2nd...
1
by: Ibergarden | last post by:
Hello, I need to extract three text lines from a memo field (created by exporting messages from outlook) and separate them into individual fields. Does anybody can help me? Thank you
10
by: ARC | last post by:
This is mainly a speed question. In this example: I have a QuotesHdr table that has a few memo fields. If these memo fields are used extensively by some users, and if their are a large number of...
11
tdw
by: tdw | last post by:
Hi all, I have tried a few different methods to accomplish this, but with no luck. I will post the code for the latest attempt at the end of this post. I work at a land surveying company. This...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...

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.