Solved

Parse in Visual Basic

Posted on 2010-09-04
8
470 Views
Last Modified: 2012-08-14
I am trying to write a script which would parse the id from the following snippet:

<form  method="post" action="/gp/checkout/address/edit.html/ref=ox_shipaddress_edit_addr_1" id="edit-joqkltnomp">
     
and insert it where ID is in the following snippet:

        Set FormElement = GWFO(iedoc, "getElementByid", VbMethod, 30, ID)
       FormElement.submit
the id in the first snippet is always a variable so I searched for the part of the snippet immediately before it which is a constant as follows:

(Body.innerHTML, "ox_shipaddress_edit_addr_1")

I am thinking if i create a string called IDString, for example, I can run the latter snippet as

      Set FormElement = GWFO(iedoc, "getElementByid", VbMethod, 30, IDString)
       FormElement.submit

I am just having a hard time figuring out how to parse the id and creating the string. Help much appreciated.
0
Comment
Question by:bpfsr
[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
  • 5
  • 2
8 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33605565
Try something like this:
Dim IDString As String
Dim values As Variant
values = Split(Body.InnerHTML, "id=" & Chr(34))
If UBound(values) >= 1 Then
    values = Split(values(1), Chr(34))
    If UBound(values) >= 1 Then
        IDString = values(0)
        ' ...
        Set FormElement = GWFO(iedoc, "getElementByid", VbMethod, 30, IDString)
        FormElement.submit
    Else
        ' closing " was not found
    End If
Else
    ' id=" was not found
End If

Open in new window

0
 

Author Comment

by:bpfsr
ID: 33605615
I think you are close Idle but there is more than one "id=" in the HTML and it is picking up one of th eother ones. that is why I wanted to find the "ox_shipaddress_edit_addr_1" as that is unique. If I can find that first the "id=" after that will always be the id I am looking for.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 33605689
Ah...try this modification then:
Dim IDString As String
Dim values As Variant

values = Split(Body.InnerHTML, "ox_shipaddress_edit_addr_1")
If UBound(values) >=1 Then
    values = Split(values(1), "id=" & Chr(34))
    If UBound(values) >= 1 Then
        values = Split(values(1), Chr(34))
        If UBound(values) >= 1 Then
            IDString = values(0)
            ' ...
            Set FormElement = GWFO(iedoc, "getElementByid", VbMethod, 30, IDString)
            FormElement.submit
        Else
            ' closing " was not found
        End If
    Else
        ' id=" was not found
    End If
Else
    ' ox_shipaddress_edit_addr_1 was not found
End If

Open in new window

0
Independent Software Vendors: 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!

 

Author Comment

by:bpfsr
ID: 33606558
not working either. it looks likes its not finding "id=" as

values = Split(values(1), "id=" & Chr(34))
    If UBound(values) >= 1 Then
   
turns up ubound(values) = 0

0
 

Author Comment

by:bpfsr
ID: 33606658
From what I can tell you are trying to split the html from after the "ox_shipaddress_edit_addr_1"), then find the "id=" and parse the 34 characters after it; is that right? I did a

debug.print '|" & Body.innerHTML & '|"

and it looks like it is only splitting the last few paragraphs of the HTML (which is actually several pages long, with the "ox_shipaddress_edit_addr_1" we are looking for probably in the top quarter of the code)
there is an 'id=" in that last paragraph and it is pulling the script from after that, which in turn is not the right script. Is there a way to just parse the "id=" immediately after the "ox_shipaddress_edit_addr_1"  without doing the split as it seems the split is where the problem is...
0
 
LVL 45

Expert Comment

by:aikimark
ID: 33606839
why not use the XML DOM to get the data you want, rather than do string parsing?
0
 

Author Comment

by:bpfsr
ID: 33608011
???
0
 

Author Comment

by:bpfsr
ID: 33608381
Idle, it was very close but after playing with it this is what came to work:

      Set Body = GWFO(iedoc, "getElementsByTagName", VbMethod, 30, "BODY")(0)
            Debug.Print "|" & Body.innerHTML & "|"
            If InStr(Body.innerHTML, "ox_shipaddress_edit_addr_1") Then
            values = Split(Body.innerHTML, "ox_shipaddress_edit_addr_1")
                Debug.Print "|" & UBound(values) & "|"
                If UBound(values) >= 1 Then
                values = Split(values(1), "id=" & Chr(34))
                    If UBound(values) < 1 Then
                    values = Split(values(0), Chr(34))
                        If UBound(values) >= 1 Then
                        IDString = values(0)
                        IDString = Mid(IDString, 15, 10)
                        IDString = "edit-" & IDString
                        ' ...
                        Set FormElement = GWFO(iedoc, "getElementByid", VbMethod, 30, IDString)
                        FormElement.submit
                        Else
                        ' closing " was not found
                        End If
                    Else
                    ' id=" was not found
                    End If
                Else
                ' ox_shipaddress_edit_addr_1 was not found
                End If
            End If
 
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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