ASP Is Fun

Learning ASP
Free Course
Basics
Functions
SQL Commands
Sample Code


Servers / Setup
Host Reviews
Server Setup
Error Tips


Contract ASP
Development

Search For:


Intro to ASP


 
ASP Intro Ebook


Cast - Reassigning Variable Type



In ASP you might occasionally see error messages about casting a variable or object. To cast a variable is to reassign its type.

In other languages, like C or C++, there are very specific commands used in order to change a variable. If you had PiValue = 3.141519, and you just wanted the integer (3) part of that number, you would recast PiValue as an integer.

ASP is far less picky about its variables. You really don't even have to define your variable types before you use them. If you have

PiValue = 3.141519

and you wanted to have a variable called PiShort with just the integer part, then you just say

PiShort = cInt(PiValue)

That's it, it takes the integer of PiValue and puts it into PiShort.

If you end up with casting errors, do a bunch of response.writes to see EXACTLY what every variable is set to along the way.

For example, if you start setting up a mail object -

Set objMail = Server.CreateObject("CDO.Message")

and then you try to turn objMail into an integer, that won't work :) So make sure that the variable you are starting with can actually be cast into the destination type variable.

ASP Variable Basics



Bookmark this site so you can reference it any time you have ASP questions in the future!




ASP Main Page | ASP Ebooks | Free ASP Course | Contact Lisa
All content copyright © 2012 Minerva WebWorks LLC. All rights reserved.

French Wedding


Free Newsletter!

Ebooks
Intro to ASP
ASP SQL DB
Members
Shopping


Introduction to ASP

Romance Tips
Irish Romance
Italian Romance
French Romance

ASP Poll
How do you handle 500 errors?
I don't
Page does nothing
Displays error
Emails error