Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - VBScript: Converting and Formatting with F...
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

VBScript: Converting and Formatting with Functions
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-05-27

    Table of Contents:
  • VBScript: Converting and Formatting with Functions
  • The Function with Character
  • Express Your In(teger) Self
  • CSng, the Loneliest Function of them All!
  • Witchy Woman Put a Hex On You

  • 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


    VBScript: Converting and Formatting with Functions - Express Your In(teger) Self


    (Page 3 of 5 )

    Got an expression you want converted into an Integer? Well, CInt() is for you! And you can own it for the low, low price of $19.95. All checks payable to James Payne...


    <html>

    <head>

    <script type="text/vbscript">

    dim this, that, theOther

    this=32766.9892939

    that=-32767.99999999999

    document.write(CInt(this)) & "<br />"

    document.write(CInt(that))

    </script>

    </head>

    <body>

    </body>

    </html>

    This converts our values to integers and prints out:

      32767
      -32768

    Note that the value must be a number and the minimum and maximum amount is between -32,768 and 32,767.

    CLng, Nice Knowing You

    If you need to convert an expression to a larger number, you can use the CLng function, which looks suspiciously like a Klingon. Not the Original Trek Klingon...the Deep Space Nine one, which is somehow less scary:


    <html>

    <head>

    <script type="text/vbscript">

    dim this, that, theOther

    this=2147483646.9999999999

    that=-2147483647.999999999

    document.write(CLng(this)) & "<br />"

    document.write(CLng(that))

    </script>

    </head>

    <body>

    </body>

    </html>

    Again, there is a min and max of -2147483648 and 2147483647, respectively. Note that when I say expression, I really mean expression. In all of these samples I have assigned a value to the variable. But nothing is to stop you from doing this as well:


    <html>

    <head>

    <script type="text/vbscript">

    dim this, that, theOther

    this=900.23

    that=800.63

    theOther=this*that+(this+that)

    document.write(CLng(theOther))

    </script>

    </head>

    <body>

    </body>

    </html>

    Here we performed some equations, adding them to that lonely variable I inserted into the other examples but never used, giving us this result:

      722452

    More Windows Scripting Articles
    More By James Payne


       · In our last tutorial, I tried to cover as many of the Conversion and Formatting...
     

    WINDOWS SCRIPTING ARTICLES

    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...
    - Modifying XML Files in WSH
    - Reading XML Files in WSH
    - Visual Basic 2005 XML Programming Using XML ...
    - Creating an XML Document in WSH
    - 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

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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