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
Solved

Underscore in Visual Basic

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

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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

860 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