Solved

Underscore in Visual Basic

Posted on 2010-09-04
11
1,005 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 51

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

747 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

11 Experts available now in Live!

Get 1:1 Help Now