Avatar of bpfsr
bpfsrFlag for United States of America

asked on 

Underscore in Visual Basic

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?
VB ScriptVisual Basic ClassicVisual Basic.NET

Avatar of undefined
Last Comment
bpfsr
Avatar of John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou
Flag of Greece image

Avatar of Bill Prew
Bill Prew

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
Avatar of spinzr0
spinzr0
Flag of United States of America image

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
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 & "|"
Slow fingers :)
Avatar of bpfsr
bpfsr
Flag of United States of America image

ASKER

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.
Yes, and what was the value of the Body.innerText at the time?
Avatar of bpfsr
bpfsr
Flag of United States of America image

ASKER

When I hover over it it shows "Select a shipping address..." Is there a way to select the entire content?
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of bpfsr
bpfsr
Flag of United States of America image

ASKER

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?
Avatar of bpfsr
bpfsr
Flag of United States of America image

ASKER

got it - body.innerHTML
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo