The ASP On Line Course:
Naming and Defining Variables
One of the key features of using ASP is the ability to use and manipulate variables. How do you create a date-type variable? How about a numeric, or string variable? The answers are clearly laid out in this article.
How should you name variables? There are all sorts of conventions. Some people like a convention like sFirstName, meaning "string type variable, holding a first name". Others just like the content - BackColor for the value of the background color, for example. Whatever you do, be descriptive and reasonably lengthed. Don't go for variables like "i" and "j", those drive you crazy when you're trying to debug later. And don't go for variables like "lastnameofprimarycontact" - that makes it nearly impossible to read through the code.
So lets say you name your variables short but meaningful names - names like SiteName or UserName or SiteID. How do you use them?
For a regular variable, you simply assign a value to it. You don't have to predefine it - it knows by what type of variable you're assigning to it what sort of a variable it is. So if you say:
SiteName = "ASP"
it knows it's a text variable that you can do text operations on. If you say
BooksOrdered = 13
then it knows it's a numeric variable and that you can do addition and subtraction to it.
The date subtype needs a special format so that the system doesn't think it's just a string or a division problem :). You use # signs to indicate it's a date, as in:
DateStarted = #01/15/2001#
Also, if you want to use booleans (true/false), you simply use TRUE or FALSE as your values. So:
FinishedTask = TRUE
ASP Course and Code | HTML Tips, Code & Help | Java Code & Help | Gaming Walkthroughs