Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - VBScript: Conversion and Format Functions
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: Conversion and Format Functions
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2008-05-19

    Table of Contents:
  • VBScript: Conversion and Format Functions
  • The Asc() Function
  • CBool...CBool Run
  • CCur...Did I Stutter? Oh Yeah, I Guess I Did
  • This Next Part Will Make You CDbl()

  • 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: Conversion and Format Functions - CCur...Did I Stutter? Oh Yeah, I Guess I Did


    (Page 4 of 5 )

    This bad boy takes an expression and converts it to a currency. If it has more than four places after the decimal point...well, maybe I'd better just let you see for yourself. Behold the code and the wondrous result!


    <html>

    <body>

    <script type="text/vbscript">

    dim num, num2, num3

    num=.03356

    num2=12.59633256

    num3=0.995

    num4= 9/2

    document.write(CCur(num) & "<br />")

    document.write(CCur(num2) & "<br />")

    document.write(CCur(num3)& "<br />")

    document.write(CCur(num4))

    </script>

    </body>

    </html>

    You will note that while these values are now currency, they don't have a dollar symbol. That's because the computer doesn't need that symbol to tell it the value is a dollar. Only you do. Here is the result:

      0.0336
      12.5963
      0.995
      4.5

    I Want to CDate() Angeline Jolie

    Okay, so I lied. I don't want to date her. I mean, I would have to donate my meager earnings to charitable causes and adopt a bunch of children who would think I was an enormous cheeseburger anyway.

    CDate does what all of these other functions do, except it changes the expression (if applicable at any rate) to a date or time format. Here it is in code people:


    <html>

    <body>

    <script type="text/vbscript">

    a="April 22, 1977"

    document.write(CDate(a))

    </script>

    </body>

    </html>

    This results in my birth date:

      4/22/1977


    Here is another example:

    <html>

    <body>

    <script type="text/vbscript">

    a="April 22, 1977"

    b=#4/22/77#

    c="10:19:50 PM"

    d=#12:00:00#

    document.write(CDate(a)) & "<br />"

    document.write(CDate(b))& "<br />"

    document.write(CDate(c))& "<br />"

    document.write(CDate(d))

    </script>

    </body>

    </html>

    This gives us the results:

      4/22/1977
      4/22/1977
      10:19:50 PM
      12:00:00 PM

    And lastly, we can use if statements to ensure that the value is, in fact, a date:


    <html>

    <body>

    <script type="text/vbscript">

    a="April 22, 1977"

    b="Higgeldy Piggeldy"

    if IsDate(a) then

    document.write(CDate(a)) & "<br />"

    end if

    if IsDate(b) then

    document.write(CDate(b))& "<br />"

    else

    document.write("That ain't no date sucka!")

    end if

    </script>

    </body>

    </html>

    This program tests the value in the variable "a" and prints it out if it is a date. It then checks the value in the variable "b" and prints it out if it is a date. If it isn't, then it prints out some text, giving us this result:

      4/22/1977
      That ain't no date sucka!

    One final pun...

    More Windows Scripting Articles
    More By James Payne


       · Welcome back. In this article we will cover Conversion and Formatting functions. If...
     

    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 4 hosted by Hostway
    Stay green...Green IT