Code Examples
  Home arrow Code Examples arrow Page 4 - Searching Body Text with textRange: Buildi...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Searching Body Text with textRange: Building on the Script and the VBScript Alternative
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 16
    2005-06-30

    Table of Contents:
  • Searching Body Text with textRange: Building on the Script and the VBScript Alternative
  • Add a Flag
  • The VBScript
  • VBScript Continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Searching Body Text with textRange: Building on the Script and the VBScript Alternative - VBScript Continued


    (Page 4 of 4 )

    The main difference between subs and functions is that functions return values whereas subs do not.  The set keyword is used to set the value of the range variable equal to the textRange we have defined.

    Another difference is the way in which alerts are defined.  The MsgBox function is used in place of the alert method and you’ll see that this gives you greater control over the general working of the alert.  Several of the MsgBox elements have been set as vbExclamation and several as vbCritical.  Not only does this change the icon that appears on the alert, it also changes the sound that is associated with it (provided the users’ sound settings cater for this.)  Also, instead of specifying a return of false following a search term not being entered, you can simply exit the subroutine.  Syntactically, these are the main differences between the two scripts.  The search window does not need to be changed in anyway; the JavaScript ModalDialog window will happily pass the required value back to the VBScript file without causing any problems.  You may also have noticed that some of the additional error handling if statements have been left out as the some of the user actions do not cause errors with the VBScript in the same way as they do with JavaScript.

    Before this will work properly, you need to adjust the main HTML page that calls the script.  Firstly, the file referenced in the script src attribute needs to be changed to behaviour.vbs or the JavaScript file will still be called, secondly, you need to remove the onclick event handlers from the button code.  The subs in the VBScript file have the onclick events tacked on to the end of the button names in the first line of the sub.

    As a point of interest; once a word has been found and highlighted, it is easy to use the range to replace the word searched for as well.  Theoretically, another button could be added to the example web page that called a textReplace() function.  The code this contained could produce a second dialog window which asked for a word to replace the highlighted word with.

    It is then simply a case of setting range.text equal to the new word variable.  While it is difficult to think of the point in using the replace method in this example, I’m sure there are cases when it would be useful, a simple script-based spell checking function added to form text area’s is one possibility. 

    As I mentioned in the first article, both of these scripts will work only on IE browsers.  The JavaScript version may work on IE on other platforms such as the MAC (I don’t know as I haven’t tested it), but the VBScript will only work on MS platforms.  The most popular alternative browser to IE at the moment is FireFox, a browser that uses the Gecko rendering engine to draw the various elements that make up web pages in the browser.  This is also used by Netscape and Mozilla browsers so having a script that will be compatible with Gecko will clear up any compatibility issues between all major browsers.  Provided you have some kind of detection model in place that can refer different browsers to different areas of your site, you can have the IE only script of choice running on one section, and the Gecko based script residing on another section.  A gecko compatible script is the subject of discussion in article three.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    CODE EXAMPLES ARTICLES

    - Handling Animations and Bitmaps Using GDI+ f...
    - Download a Web Page using the WebClient
    - Creating a Chart using Data from a Database ...
    - The Basics of Charting with the MS Chart Con...
    - Searching Body Text with textRange: Enter th...
    - Searching Body Text with textRange: Building...
    - Searching Body Text with textRange, part 1: ...
    - First Steps in Programming
    - Programming in C
    - Quick Introduction to ASF,ASX, and Networkin...
    - SatView: Pointer Perfect, Part 2: Constructi...
    - SatView: Pointer Perfect, Part 1
    - Style Case Studies: Construction Unions
    - Creating an Engine for Games for Windows
    - Style Case Studies: Generic Callbacks





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway