Re: How to return a sting of numbers from a longer string

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance





First, I didn't tell you that this is a script being run in an htm file, so
I needed to change the msgbox into Alert.

Second, the code seems to require that I already know what whatimlookingfor
(EntryNum) is. But I don't. I'm trying to return this number. So the
question is, how can I look for a string (whatimlookingfor) within a string
(string) via the Instr statement, if I don't know what the smaller string
actually is, other than that it's a six digit number (which I think in all
cases will start with two zeros)?

Thanks,





"Franz aRTiglio" <franzgol@xxxxxxxxxxxx> wrote in message
news:454fcedc$0$13759$4fafbaef@xxxxxxxxxxxxxxxxxxxxxx
Larry wrote:
Let's say I have a string like this, which I'll call docAddress.


http://www.website.com/cgi-bin/mt/mt.cgi?__mode=view&_type=entry&id=003322&blog_id=1

I want to return the six digit string inside it, which in this case is
003322, but it could be any six digit number, and I'll call it
EntryNum.

Dim string
Dim whatimlookingfor
Dim pointer
Dim x
string =
"http://www.website.com/cgi-bin/mt/mt.cgi?__mode=view&_type=entry&id=003322&;
blog_id=1"
whatimlookingfor="id="
pointer = instr(string,whatimlookingfor)
If pointer= 0 then
msgbox (whatimlookingfor & " not found")
wscript.quit
End If
pointer = pointer + len(whatimlookingfor)
For x = pointer + 1 to len(string)
If isnumeric(mid(string,pointer,x-pointer))=false then exit for
next
If len(mid(string,pointer,x-pointer-1)) = 0 then
msgbox "numeric value not found"
Else
msgbox "Found !" & vbcrlf & mid(string,pointer,x-pointer-1)
End If




.



Relevant Pages

  • Re: Modify a .doc document with a macro without Word ?
    ... Const LL_ITEMPTR = 4 ' Pointer to the item ... Public Sub Add(Item As Variant, Optional Key As String, Optional Before As Variant, Optional After As Variant) ... Dim lpArray As Long ' Pointer to the first element of the array ... Dim lpItem As Long ' Pointer to the item ...
    (microsoft.public.scripting.vbscript)
  • Re: Sub reagiert trotz Exit Sub
    ... Dim EVMsg As String ... MsgBox gsMessages ... Ereignisse eintreffen und nachdem die MsgBox vom Benutzer ...
    (microsoft.public.de.vb)
  • Re: Sub reagiert trotz Exit Sub
    ... On Error Resume Next ... Dim EVMsg As String ... MsgBox gsMessages ...
    (microsoft.public.de.vb)
  • RE: Jump ahead one month
    ... assigning a string to it, it can all be done in one line. ... Dim strSQL As String, strMessage As String ... Dim rst As Object ... MsgBox Err.Description, vbExclamation, "Error" ...
    (microsoft.public.access.gettingstarted)
  • Re: ADP bound form - force record save, recordsetclone not populating after requery
    ... Function RefreshForm(myForm As Form, myField As String) ... Dim rs As ADODB.Recordset ... MsgBox "YOU HAVE NOT MADE A SELECTION" ... recordsetclone on ADO form recordsets in the 2000 version - could you try just using the ..clone method of the form recordset in stead, and see if that changes anything? ...
    (comp.databases.ms-access)