Monday, July 20, 2009

Read client side IP Address

-------server side code for ASP Classic--------

ip_address=Request.Servervariables("REMOTE_HOST")
Response.write(ip_address)

-------End server side code -----------------

Thursday, April 2, 2009

Type conversion in ASP

From string to Integer conversion
Dim finalvalue="10"
IntValue=CInt(finalvalue)


From integer to String conversion
Dim finalvalue=10
i=CStr(finalvalue)

Session Object properties in ASP

The Session Object in ASP is a great tool for the modern web site. It allows you to keep information specific to each of your site's visitors. Information like username,password, etc.

Create Session
Session("username") = "Amit"

Accessing SessionID
Dim mySessionID
mySessionID = Session.SessionID

Set Session Timeout time
Session.Timeout = 240

Session Abandon(Clear)
Session.Abandon

Array declaration in ASP

You can create an array of specific size or you can create a dynamic sized array. Below we have examples of both types of arrays.

Dim myFixedArray(3) 'Fixed size array
Dim myDynArray() 'Dynamic size array

Example for fixed size Array
Dim myFixedArray(3)
myFixedArray(0) = "Item number1"
myFixedArray(1) = "Item number2"
myFixedArray(2) = "Item number3"
myFixedArray(3) = "Item number4"

Example for Dyanamic size Array
Dim myDynArray()
myDynArray(0) = "Item number1"
myDynArray(1) = "Item number2"
myDynArray(2) = "Item number3"
myDynArray(3) = "Item number4"

Current date format in ASP

The Format Date Time function takes two arguments: a date and (optional) an integer from 0 through 4. The meanings of these numbers are as follows:

0 - This is the default setting. A short date DD/MM/YYYY will be used.
1 - A long date defined by the computer's regional settings.
2 - A short date defined by the regional settings.
3 - (time)A time using the time format defined by the regional settings.
4 - (time)A time using military time HH:MM (H = hour, M = Minute)

OUTPUT :
0 = 4/2/2009
1 = Friday, October 21, 2005
2 = 4/2/2009
3 = 12:00:00 AM
4 = 00:00

Type 1.
CurrentDate=FormatDateTime(Date, 0)
Response.Write(CurrentDate)

OutPut : 4/2/2009


Type 2.
CurrentDate=FormatDateTime(Date, 1)
Response.Write(CurrentDate)

OutPut : Thursday, April 02, 2009