Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - Handling Live Web Content in WSH - Part 1
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 
Mobile Linux 
App Generation ROI 
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? 
WINDOWS SCRIPTING

Handling Live Web Content in WSH - Part 1
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 10
    2006-09-06

    Table of Contents:
  • Handling Live Web Content in WSH - Part 1
  • Processing the Response
  • A Little Error-Handling
  • The Final Code

  • 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


    Handling Live Web Content in WSH - Part 1 - A Little Error-Handling


    (Page 3 of 4 )

    So you’re probably asking what those extra If statements are for, right?  Those are just to make sure that the VB functions are actually returning usable values.  This prevents our script from crashing if an error occurs.  Ideally, we would add some error handling, but that’s beyond the scope of this tutorial.  More information about error-handling can be found in the Microsoft Windows 2000 Scripting Guide located on Microsoft’s TechNet website.

    http://www.microsoft.com/technet/scriptcenter/guide/

    Back to our script, we need to finish off our original If statement with the following code.

    Else

       strIP = "Unavailable"

    End If

    getIP = trim(strIP)

    This code only executes if strHTMLText is empty, meaning that we didn’t get a response from the website.  We could issue some kind of alert to the user to indicate there was a problem but we’re just going to assign “Unavailable” to strIP instead.  Remember, this is the variable that would hold our IP address had everything worked out correctly.

    You now have one of two things.  The variable strIP either contains your IP address or it contains the text “Unavailable”.  In line 4 we make use of VB’s trim() function to make sure that strIP doesn’t contain any leading or trailing spaces. You can do with this information whatever you like.  For our purposes here, we’re just going to end by echoing it back with WSH’s echo method.

    Wscript.Echo getIP

    Save your work as checkip.vbs and double-click it to see if it works.  If you followed along correctly, you should get an alert box that displays your external IP address.  If the script returns “Unavailable”, make sure you are connected to the internet and that the site isn’t down.

    Okay, let’s recap.  We used the XMLHttpRequest object to request a website.  That website was captured into a string variable.  We used VB's inStr() and mid() functions to cut away everything except the text that we wanted, and then we echoed that back to the user.

    Go ahead and congratulate yourself.  You’ve just learned how to capture live web content in WSH!

    More Windows Scripting Articles
    More By Nilpo


       · I wanted this article to demonstrate some alternative uses for WSH. A lot of people...
     

    WINDOWS SCRIPTING ARTICLES

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT