vbscript – CDate

FUNCTION:  CDate( )


Implemented in version 1.0

You can determine the expression subtype by using the function VarType( ).

CDate(Date)

The CDate function converts any valid date and time expression to the variant of subtype Date.

The default date output will be of the format:  **/**/** The default time output will be of the format:  **:**:** *M Converted date values can range from January 1, 100 to December 31, 9999

Code:
<% anydate = « June 26, 1943″ %>
<% =CDate(anydate) %>

Output:
6/26/43

Code:
<% anydate = #6/26/43# %>
<% =CDate(anydate) %>

Output:
6/26/43

Code:
<% anytime= »2:23:59 PM » %>
<% =CDate(anytime) %>

Output:
2:23:59 PM

vbscript – CCur

FUNCTION: CCur( )


Implemented in version 1.0

You can determine the expression subtype by using the function VarType( ).

CCur(Number)

The CCur function converts any number or numeric string to the variant of subtypeCurrency.

Converts to currency values ranging from
-922,337,203,685,477.5808 to 922,337,203,685,477.5807

Code:
<% anynumber=(12345) %>
<% =CCur(any_number) %>

Output:
12345

Code:
<% any_numeric_string=(« 98765″) %>
<% =CCur(any_numeric_string) %>

Output:
98765

This function rounds off to 4 decimal places.

Code:
<% anynumber=(55555.123456) %>
<% =CCur(anynumber) %>

Output:
55555.1235

vbscript – CByte

FUNCTION:  CByte( )


Implemented in version 1.0

You can determine the expression subtype by using the function VarType( ).

CByte(Number)

The CByte function converts any number between 0 and 255 to the variant of subtypeByte.

Code:
<% anynumber=(9.876) %>
<% =CByte(anynumber) %>

Output:
10

Code:
<% anynumber=(255) %>
<% =CByte(anynumber) %>

Output:
255

vbscript – CBool

FUNCTION:  CBool( )


Implemented in version 1.0

You can determine the expression subtype by using the function VarType( ).

CBool(Number)

The CBool function converts any number to the variant of subtype Boolean.

The output for Boolean is either true or false. If the conversion is successful, the output will be true. If the conversion fails, the output will be false or an error message.

Code:
<% anynumber=7.77 %>
<% =CBool(anynumber) %>

Output:
True

Code:
<% notnumber=abc %>
<% =CBool(notnumber) %>

Output:
False

vbscript – Call

STATEMENT:  Call


Implemented in version 1.0

Call

The Call statement can be used for calling a function or subroutine.

Note that the use of Call is optional. In other words, you can call a function or subroutine by simply stating the function’s or subroutine’s name. If you use Call and if there are one or more arguments to be passed you must enclose all of the arguments in parentheses. If you do not use Call, do not use the parentheses.

If you use Call to call a function, the return value of the function is discarded.

Code:
<% Call afunction %>

<% afunction %>

<% Call myfunction(myvar1, myvar2, mystring, myarray) %>

<% myfunction myvar1, myvar2, mystring, myarray %>

<% Call anysubroutine(anum, astring) %>

<% anothersubroutine %>

vbscript – BuildPath

METHOD:  FileSystemObject.BuildPath


Implemented in version 2.0

[newfullpath = ]object.BuildPath(path, name)

This method is used to append a name onto an existing path. The format of the new path is ‘existingpath\name’.

Code:
<%
dim filesys, newfullpath
set filesys=CreateObject(« Scripting.FileSystemObject »)
newfullpath = filesys.BuildPath(c:\inetpub\wwwroot, « images »)
%>

Output:
« c:\inetpub\wwwroot\images »

vbscript – AtEndOfStream

Property:  TextStream.AtEndOfStream


Implemented in version 2.0

object.AtEndOfStream

The AtEndOfStream property returns a Boolean value. If the file pointer is positioned at the end of the file, the value is True. Otherwise, the value is False. The TextStreamobject must be open for reading or an error will occur when using this method.

The following code uses the AtEndOfStream property to get the last character in text file.

Code:
<%
dim filesys, text, readfile, contents
set filesys = CreateObject(« Scripting.FileSystemObject »)
Set text = filesys.CreateTextFile(« c:\somefile2.txt »)
text.Write « Find the last character in the text file »
text.close
set readfile = filesys.OpenTextFile(« c:\somefile2.txt », 1, false)
do while readfile.AtEndOfStream <> true
contents = readfile.Read(1)
loop
readfile.close
Response.Write « The last character in the text file is ‘ » & contents & « ‘. »
%>

Output:
« The last character in the text file is ‘e’. »

vbscript – AtEndOfLine

Property:  TextStream.AtEndOfLine


Implemented in version 2.0

object.AtEndOfLine

The AtEndOfLine property returns a Boolean value. If the file pointer is positioned immediately before the file’s end-of-line marker, the value is True. Otherwise, the value is False. The TextStream object must be open for reading or an error will occur when retreiving this property this method.

The following code uses the AtEndOfLine property to get the last character in the first line of text in a file.

Code:
<%
dim filesys, text, readfile, contents
set filesys = CreateObject(« Scripting.FileSystemObject »)
Set text = filesys.CreateTextFile(« c:\somefile2.txt »)
text.Write « Find the last character in the text file »
text.close
set readfile = filesys.OpenTextFile(« c:\somefile2.txt », 1, false)
do while readfile.AtEndOfLine <> true
contents = readfile.Read(1)
loop
readfile.close
Response.Write « The last character in the text file is ‘ » & contents & « ‘. »
%>

Output:
« The last character in the text file is ‘e’. »

vbscript – Asc

FUNCTION:  Asc()


Implemented in version 1.0

Asc(String)

The Asc function returns the ANSI character code value for the first character in a string.

In these two examples, note that the ANSI value is returned only for the « a ».

Code:
<% =Asc(« abcde fghij klmno pqrst uvwxyz ») %>

Output:
97

Code:
<% =Asc(« a ») %>

Output:
97