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
Introduction to ASP Ebook Download this ebook to get everything you need to know about learning ASP - from a step by step tutorial to function lists, sample code, common errors and solutions, and much more! 101 pages. |