Trimming a dynamically changing string

E

Eli

Hello Experts,

I'm using MS Access 2003 and I have a text box on a form that retrieves the
html of a dynamically changing web-page as a string.

I need to extract a number from that string


The number always (!) is a 5 digit number, 1 digit before a decimal point
and 4 digits after it.
The number has a changing # of characters before and after it, but 36
characters before it there (always!) is a unique word (no second recurrences
in the string): style="width:108px;"


Will this work:

Function getNumber(value As String) As String
Dim pos As Long
Const search = "style=""width:108px;"""
If Len(value) > 0 Then
pos = InStr(1, value, search, vbTextCompare)
If pos > -1 Then
'found
getNumber = Mid(value, pos + 36 + Len(search), 6) ' 1+point+4 =6
End If
End If
End Function

if it will, can you give me detailed instructions as of how to use it?

Thanks in advance
 
C

Clif McIrvin

Eli said:
Hello Experts,

I'm using MS Access 2003 and I have a text box on a form that
retrieves the
html of a dynamically changing web-page as a string.

I need to extract a number from that string


The number always (!) is a 5 digit number, 1 digit before a decimal
point
and 4 digits after it.
The number has a changing # of characters before and after it, but 36
characters before it there (always!) is a unique word (no second
recurrences
in the string): style="width:108px;"


Will this work:

Function getNumber(value As String) As String
Dim pos As Long
Const search = "style=""width:108px;"""
If Len(value) > 0 Then
pos = InStr(1, value, search, vbTextCompare)
If pos > -1 Then
'found
getNumber = Mid(value, pos + 36 + Len(search), 6) ' 1+point+4
=6
End If
End If
End Function

if it will, can you give me detailed instructions as of how to use it?

Thanks in advance


I'm not quite sure what you're asking for. Your function looks sound
(I'm unclear on a couple points, I'll get back to those.)

You say you have a form that is retreiving the string. Add a standard
code module to that form, and place your function there. Inside the
procedure that is retreiving the string add something like this:

NumberOfInterest = getNumber(me.txtWebString.value)

with appropriate validity checking, etc.

I'm not certain about > Const search = "style=""width:108px;"""
.... some quick testing in the immediate window should clear that up.

What precisely do you mean by "36 characters before the number"? Your
code indicates that there are 36 characters *between* the final double
quote of ...px;" and the first digit of your number. Again, you can
verify that by setting a breakpoint and using the immediate window.
 
E

Eli

The web-page is dynamically changing, so its html is never the same which
means that the number of characters before and after the "number of intrest"
is constantly changing, to cope with that issue I use [Const search =
"style=""width:108px;"""] to find those unique words that always are located
36 characters before the "number of intrest", and getNumber = Mid(value, pos
+ 36 + Len(search), 6) to extract that number.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top