Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check if variable exist in an ASP page?

Status
Not open for further replies.

Rachel80

Programmer
May 25, 2000
63
GB
Hi, I've used Coldfusion before and it has an in-built function to check for the existence of a variable.. As I need this function as well, I wonder if I could do similar checking in ASP?? Is to check if the variable is defined, then display something on the page.. THanx!
 
Returns a value indicating the subtype of a variable.

VarType(varname)
The varname argument can be any variable.

Return Values
The VarType function returns the following values:

Constant Value Description
vbEmpty 0 Empty (uninitialized)
vbNull 1 Null (no valid data)
vbInteger 2 Integer
vbLong 3 Long integer
vbSingle 4 Single-precision floating-point number
vbDouble 5 Double-precision floating-point number
vbCurrency 6 Currency
vbDate 7 Date
vbString 8 String
vbObject 9 Automation object
vbError 10 Error
vbBoolean 11 Boolean
vbVariant 12 Variant (used only with arrays of Variants)
vbDataObject 13 A data-access object
vbByte 17 Byte
vbArray 8192 Array

Note These constants are specified by VBScript. As a result, the names can be used anywhere in your code in place of the actual values.
Remarks
The VarType function never returns the value for Array by itself. It is always added to some other value to indicate an array of a particular type. The value for Variant is only returned when it has been added to the value for Array to indicate that the argument to the VarType function is an array. For example, the value returned for an array of integers is calculated as 2 + 8192, or 8194. If an object has a default property, VarType (object) returns the type of its default property.

The following example uses the VarType function to determine the subtype of a variable.

Dim MyCheck
MyCheck = VarType(300) ' Returns 2.
MyCheck = VarType(#10/19/62#) ' Returns 7.
MyCheck = VarType("VBScript") ' Returns 8.
 
Actually, I want to check for the Session Timeout property for the user session.. I thought I could use "is defined" function to detect Session("userid")?? If not defined, then display a message such as "User session timed out, please re-login etc." By the way, how can we customize the session variation's duration (i know the default is 20min).

Thanx!
 
Actually, I want to check for the Session Timeout property for the user session.. I thought I could use "is defined" function to detect Session("userid")?? If not defined, then display a message such as "User session timed out, please re-login etc." By the way, how can we customize the session variable's duration (i know the default is 20min).

Thanx!
 
As long as you don't have a sessionless ASP page the value for session.timeout will always exist. It is created by default by the server.

To reset it just enter

session.timeout = 3600 Or whatever amount of time in seconds you want the session to last.

You may have to use

set session.timeout =3600

Not sure, so try both to see which works.

 
hm.. i mean to ask code the session.timeout at which page?? at declaring the session variable, also define the timeout property? or in another file or in the global file?? (i'm using PWS, have this global file in the folder). Because in ColdFusion, the session timeout property is declared in the Application file which is first executed before other cfm files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top