iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 11, 2008
Improving accessibility for motor impaired users
WebDevTips UK
 
May 11, 2008
10 ways to orientate users on your site
WebDevTips UK
 
May 11, 2008
Web Design Clinic - Rros restoration camp 2006
About
 
May 10, 2008
The Moods of Facebook
About
 
May 9, 2008
CSS 1 properties are a great start
About
 
May 9, 2008
Reader Question: How do you get fancy fonts?
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /ASP

Using built-in functions in ASP 

  Views:    19874
  Votes:    4
by Andrew Schools 4/06/04 Rating: 

Synopsis:

There are a lot of functions in ASP. Some are for type checking, typecasting, formatting, math, date and string manipulation. One of the greatest thing I love about vbscript, is they are easy to learn and use.
Pages: firstback2 forwardlast
The Article

Type Checking

These functions allow you to figure out data types.

TypeName() 
Returns the data type rather than the code.

IsNumeric() 
Returns a boolean value of true if the data type is that of a number and false if otherwise.

IsArray() 
Returns a boolean value of true if the data type is that of an array and false if otherwise.

IsDate() 
Returns a boolean value of true if the data type is that of a date and false if otherwise.

IsEmpty() 
Returns a boolean value of true if the data type is a empty value and false if otherwise.

IsNull() 
Returns a boolean value of true if the data type contains no valid data and false if otherwise.

IsObject() 
Returns a boolean value of true if the data type is that of an object and false if otherwise.

Typecasting

What's typecasting? Typecasting converts between data types. For instance, if you have data you obtained from a form, it's considered text. However, with typecasting, you can convert that variable into a date value.

Dim idate
'Get the DOB from the form
idate = Request.Form("DOB")
'Convert it to a date
idate = cdate(idate)

With the CBool() function, you can get a boolean value. If the number is 0, you get a boolean value of false, otherwise you get a boolean value of true. The following code will return true.

Dim inumber
inumber = 12
If CBool(inumber) = True Then
Response.Write "True"
Else
Response.Write "False"
End If

Formatting Functions

Formatting functions are useful when you need to display data the way you want it. For results, you will end up with a string. The code below will return 4/6/2004

Response.Write FormatDatetime(date, vbshortdate) 

You can also display the date like this: Tuesday, April 06, 2004, using the following code:

Response.Write FormatDatetime(date, vblongdate) 

The same applies to time:

Response.Write FormatDatetime(time, vblongtime) 

Math functions

Vbscript has lot's of math functions, however, you won't use them very often, so I will only list a couple.

Rnd(), when used with randomize, will generate an random number (random enough) less the one and greater than or equal to zero. Try out the following code:

randomize
Response.Write rnd
 

What does randomize do? Randomize uses the system timer to start the random number generator.

Another vbscript math function you might run into is the Round() function. And as you would guess, it rounds numbers.

Round(9.99) 

The code above returns 10.

Pages: firstback2 forwardlast

Similar/related articles:


 
  Sponsors