Solved

Underscore in Visual Basic

Posted on 2010-09-04
11
1,013 Views
Last Modified: 2012-05-10
I am writing a script that needs to find the string "ox_shipaddress" within text. I can see the string in the text but the script does not find the string. So when I use:

if instr (body.innertext, "ox_shipaddress") then ...

it skips the if statement because it is not locating  "ox_shipaddress" . I am sure this is because of the underscore in  "ox_shipaddress" . Can somebody please tell me how to rewrite the script to locate the string?
0
Comment
Question by:bpfsr
11 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33603406
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 33603409
The underscore itself should not pose a problem as you have used it.  It is treated like a normal character in a string, so if "ox_shipaddress" is in body.innertext it will locate it.

I suspect the problem is that the string in body.innertext isn't what you think it is.  Perhaps the underscore is a different character?  Or there is a space around it?  

Can you paste up what is in body.innertext when the test fails?

~bp
0
 
LVL 8

Expert Comment

by:spinzr0
ID: 33603420
You can also just loop through body.innertext to see what character the _ is by using this:

For i=1 To Len(body.innertext)
    Msgbox Asc(Mid(body.innertext, i, 1)
Next

Additionally, just to make sure its not case sensativity you should use this:
If InStr (1, body.innertext, "ox_shipaddress", vbTextCompare) Then
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33603422
If this is VB6 or VBA, then the underscore is NOT your problem.  For example:MsgBox instr(1,"blah_blah_hee blah blah", "blah_hee")will return 6, as expected.More likely, either the string being sought is not truly there, or you are using a case-sensitive search (by default, InStr is case sensitive, unless you use vbTextCompare in an optional argument, or have a module declaration of Option Compare Text.Perhaps you should insert this line before the one above, and see what is written to the Immediate window:Debug.Print "|" & body.innertext & "|"
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33603433
Slow fingers :)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:bpfsr
ID: 33604163
Thanks for the help; here is the paragraph from the source document:

      </div>
    </form>
   <table>
    <tr>
     <td valign="top">
      <form  method="post" action="/gp/checkout/address/edit.html/ref=ox_shipaddress_edit_addr_1" id="edit-joqkltnomp">
        <input type="hidden" name="addressID" value="joqkltnomp" />
        <input type="hidden" name="changeAddressOrderID" value="" />
        <input type="hidden" name="useAddressWidget" value="1" />

and here is the snippet from the script:

If InStr(Body.innerText, "ox_shipaddress_edit_addr_1") Then

I actually copied and pasted the phrase.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33604264
Yes, and what was the value of the Body.innerText at the time?
0
 

Author Comment

by:bpfsr
ID: 33604504
When I hover over it it shows "Select a shipping address..." Is there a way to select the entire content?
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 33605005
See above, with Debug.Print
0
 

Author Comment

by:bpfsr
ID: 33605125
right, sorry. Okay, that seems to be it. The phrase I am looking for is part of the html source code for an Internet Explorer page, while whats being outputted in the Immediate Screen is the output of the html, i.e. the IE page itself, sans the source code. I'm guess then that is the function of body.innertext. Is there then a function that would search the source code?
0
 

Author Comment

by:bpfsr
ID: 33605220
got it - body.innerHTML
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now