fileObjectName = new File("path")To use a File object:
fileObjectName.methodName
.web
file resides--or absolute.
If the physical file specified in the path already exists, LiveWire references it when you call methods for the object. If the physical file does not exist, you can create it by calling the open method.
You can display the name and path of a physical file by calling the write function and passing it the name of the related File object.
A pointer indicates the current position in a file. If you open a file in the a or a+ mode, the pointer is initially positioned at the end of the file; otherwise, it is initially positioned at the beginning of the file. In an empty file, the beginning and end of the file are the same. Use the eof, getPosition, and setPosition methods to specify and evaluate the position of the pointer. See the open method for a description of the modes in which you can open a file.
userInfo = new File("info.txt")Example 2. In the following example, the File object references a physical file with an absolute path:
userInfo = new File("c:/data/info.txt")Example 3. The following example displays the name of a File object onscreen.
userInfo = new File("c:/data/info.txt") write(userInfom)
stringName.fixed()
Description
Use the fixed method with the write or writeln methods to format and display a string in a document.
Examples
The following example uses the fixed method to change the formatting of a string:
var worldString="Hello, world"
document.write(worldString.fixed())
The previous example produces the same output as the following HTML:
<TT>Hello, world</TT>
floor
Method. Returns the greatest integer less than or equal to a number.
Syntax
Math.floor(number)
Parameters
number is any numeric expression or a property of an existing object.
Method of
Math
Examples
//Displays the value 45
document.write("<P>The floor of 45.95 is " + Math.floor(45.95))
//Displays the value -46
document.write("<P>The floor of -45.95 is " + Math.floor(-45.95))
See also
ceil method
flush function
Function. Sends data from previously issued write functions to the client.
Syntax
flush()
Description
The flush function is a top-level LiveWire function that is not associated with any object.
To improve performance, LiveWire buffers the output of the write function and sends it to the client in large blocks. The flush function sends data that is in the buffer as a result of previously issued write functions to the client.
Use the flush function to control when data is sent to the client. For example, call the flush function before an operation that creates a delay, such as a database query. If a database query retrieves a large number of rows, you can flush the buffer after retrieving a small number of rows to prevent large delays in displaying data.
Because the flush function updates the client's cookie file as part of the HTTP header, you should perform any changes to the client object before flushing the buffer.
Do not confuse the flush method of the File object with the top-level flush function. The flush function flushes a buffer of data and causes it to display in the client browser; the flush method flushes a buffer of data to a physical file.
Examples
The following example iterates through a text file and outputs each line in the file, preceded by a line number and five spaces. The flush function then causes the client to display the output.
while (!In.eof()) {
AscLine = In.readln();
if (!In.eof())
write(LPad(LineCount + ": ", 5), AscLine, "\n");
LineCount++;
flush();
}
See also
write function
flush method
Method. Writes the content of the internal buffer to a file.
Syntax
fileObjectName.flush()
fileObjectName is the name of a File object.
Method of
File
Description
When you write to a file with any of the File object methods (write, writeByte, or writeln), the data is buffered internally. The flush method writes the buffer to the physical file. The flush method returns true if it is successful; otherwise, it returns false.
Do not confuse the flush method of the File object with the top-level flush function. The flush function flushes a buffer of data and causes it to display in the client browser; the flush method flushes a buffer of data to a physical file.
Examples
See the write method for an example of the flush method.
See also
write, writeByte, and writeln methods
fontcolor
Method. Causes a string to be displayed in the specified color as if it were in a <FONT COLOR=color> tag.
Syntax
stringName.fontcolor(color)
Parameters
stringName is any string or a property of an existing object.
color is a string or a property of an existing object, expressing the color as a hexadecimal RGB triplet or as one of the string literals listed in "Color values" on page 275.
Description
Use the fontcolor method with the write or writeln methods to format and display a string in a document.
If you express color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072".
The fontcolor method overrides a value set in the fgColor property.
Examples
The following example uses the fontcolor method to change the color of a string
var worldString="Hello, world"
document.write(worldString.fontcolor("maroon") +
" is maroon in this line")
document.write("<P>" + worldString.fontcolor("salmon") +
" is salmon in this line")
document.write("<P>" + worldString.fontcolor("red") +
" is red in this line")
document.write("<P>" + worldString.fontcolor("8000") +
" is maroon in hexadecimal in this line")
document.write("<P>" + worldString.fontcolor("FA8072") +
" is salmon in hexadecimal in this line")
document.write("<P>" + worldString.fontcolor("FF00") +
" is red in hexadecimal in this line")
The previous example produces the same output as the following HTML:
<FONT COLOR="maroon">Hello, world</FONT> is maroon in this line
<P><FONT COLOR="salmon">Hello, world</FONT> is salmon in this line
<P><FONT COLOR="red">Hello, world</FONT> is red in this line
<FONT COLOR="8000">Hello, world</FONT> is maroon in hexadecimal in this line
<P><FONT COLOR="FA8072">Hello, world</FONT> is salmon in hexadecimal in this line
<P><FONT COLOR="FF00">Hello, world</FONT> is red in hexadecimal in this line
fontsize
Method. Causes a string to be displayed in the specified font size as if it were in a <FONTSIZE=size> tag.
Syntax
stringName.fontsize(size)
Parameters
stringName is any string or a property of an existing object.
size is an integer between one and seven, or a string representing a signed integer between 1 and 7, or a property of an existing object.
Method of
string
Description
Use the fontsize method with the write or writeln methods to format and display a string in a document. When you specify size as an integer, you set the size of stringName to one of the seven defined sizes. When you specify size as a string such as "-2", you adjust the font size of stringName relative to the size set in the <BASEFONT> tag.
Examples
The following example uses string methods to change the size of a string:
var worldString="Hello, world"
document.write(worldString.small())
document.write("<P>" + worldString.big())
document.write("<P>" + worldString.fontsize(7))
The previous example produces the same output as the following HTML:
<SMALL>Hello, world</SMALL>
<P><BIG>Hello, world</BIG>
<P><FONTSIZE=7>Hello, world</FONTSIZE>
See also
big, small methods
getDate
Method. Returns the day of the month for the specified date.
Syntax
dateObjectName.getDate()
Parameters
dateObjectName is either the name of a date object or a property of an existing object.
Method of
Date
Description
The value returned by getDate is an integer between 1 and 31.
Examples
The second statement below assigns the value 25 to the variable day, based on the value of the date object Xmas95.
Xmas95 = new Date("December 25, 1995 23:15:00")
day = Xmas95.getDate()
See also
setDate method
getDay
Method. Returns the day of the week for the specified date.
Syntax
dateObjectName.getDay()
Parameters
dateObjectName is either the name of a date object or a property of an existing object.
Method of
Date
Description
The value returned by getDay is an integer corresponding to the day of the week: zero for Sunday, one for Monday, two for Tuesday, and so on.
Examples
The second statement below assigns the value 1 to weekday, based on the value of the date object Xmas95. This is because December 25, 1995 is a Monday.
Xmas95 = new Date("December 25, 1995 23:15:00")
weekday = Xmas95.getDay()
getHours
Method. Returns the hour for the specified date.
Syntax
dateObjectName.getHours()
Parameters
dateObjectName is either the name of a date object or a property of an existing object.
Method of
Date
Description
The value returned by getHours is an integer between 0 and 23.
Examples
The second statement below assigns the value 23 to the variable hours, based on the value of the date object Xmas95.
Xmas95 = new Date("December 25, 1995 23:15:00")
hours = Xmas95.getHours()
See also
setHours method
getLength
Method. Returns the length of a file.
Syntax
fileObjectName.getLength()
Parameters
fileObjectName is the name of a File object.
Method of
File
Description
If this method is successful, it returns the number of bytes in a binary file or characters in a text file; otherwise, it returns -1.
Examples
The following example copies a file one character at a time. This example uses getLength as a counter in a for loop to iterate over every character in the file.
// Create the source file object
source = new File("c:/data/source.txt")
// If the source file opens successfully, create a target file
if (source.open("r")) {
target = new File("c:/data/target.txt")
target.open("a")
// Copy the source file to the target
for (var x = 0; x < source.getLength(); x++) {
source.setPosition(x)
data = source.read(1)
target.write(data)
}
source.close();
}
target.close()
getMinutes
Method. Returns the minutes in the specified date.
Syntax
dateObjectName.getMinutes()
Parameters
dateObjectName is either the name of a date object or a property of an existing object.
Method of
Date
Description
The value returned by getMinutes is an integer between 0 and 59.
Examples
The second statement below assigns the value 15 to the variable minutes, based on the value of the date object Xmas95.
Xmas95 = new Date("December 25, 1995 23:15:00")
minutes = Xmas95.getMinutes()
See also
setMinutes method
getMonth
Method. Returns the month in the specified date.
Syntax
dateObjectName.getMonth()
Parameters
dateObjectName is either the name of a date object or a property of an existing object.
Method of
Date
Description
The value returned by getMonth is an integer between zero and eleven. Zero corresponds to January, one to February, and so on.
Examples
The second statement below assigns the value 11 to the variable month, based on the value of the date object Xmas95.
Xmas95 = new Date("December 25, 1995 23:15:00")
month = Xmas95.getDate()
See also
setMonth method
getPosition
Method. Returns the current position of the pointer in an open file.
Syntax
fileObjectName.getPosition()
Parameters
fileObjectName is the name of a File object.
Method of
File
Description
Use the getPosition method to determine the position of the pointer in a file. See the File object for a description of the pointer.
The getPosition method returns the current pointer position; the first byte in a file is byte 0. This method returns -1 if there is an error.
Examples
The following examples reference the file info.txt which contains the string "Hello World". The length of info.txt is 11 bytes.
Example 1. In the following example, the first call to getPosition shows that the default pointer position is 0 in a file that is opened for reading. This example also shows that a call to the read method repositions the pointer.
dataFile = new File("c:/data/info.txt")
dataFile.open("r")
write("The position is " + dataFile.getPosition() + "<BR>")
write("The next character is " + dataFile.read(1) + "<BR>")
write("The new position is " + dataFile.getPosition() + "<BR>")
dataFile.close()
This example displays the following information:
The position is 0
The next character is H
The new position is 1
Example 2. This example uses setPosition to position the pointer one byte from the end of the 11 byte file, resulting in a pointer position of offset 10.
dataFile = new File("c:/data/info.txt")
dataFile.open("r")
dataFile.setPosition(-1,2)
write("The position is " + dataFile.getPosition() + "<BR>")
write("The next character is " + dataFile.read(1) + "<BR>")
dataFile.close()
This example displays the following information:
The position is 10
The next character is d
Example 3. You can position the pointer beyond the end of the file and still evaluate getPosition successfully. However, a call to eof indicates that the pointer is beyond the end of the file.
dataFile.setPosition(1,2)
write("The position is " + dataFile.getPosition() + "<BR>")
write("The value of eof is " + dataFile.eof() + "<P>")
This example displays the following information:
The position is 12
The value of eof is true
See also
eof, open, and setPosition methods
getSeconds
Method. Returns the seconds in the current time.
Syntax
dateObjectName.getSeconds()
Parameters
dateObjectName is either the name of a date object or a property of an existing object.
Method of
Date
Description
The value returned by getSeconds is an integer between 0 and 59.
Examples
The second statement below assigns the value 30 to the variable secs, based on the value of the date object Xmas95.
Xmas95 = new Date("December 25, 1995 23:15:30")
secs = Xmas95.getSeconds()
See also
setSeconds method
getTime
Method. Returns the numeric value corresponding to the time for the specified date.
Syntax
dateObjectName.getTime()
Parameters
dateObjectName is either the name of a date object or a property of an existing object.
Method of
Date
Description
The value returned by the getTime method is the number of milliseconds since 1 January 1970 00:00:00. You can use this method to help assign a date and time to another date object.
Examples
The following example assigns the date value of theBigDay to sameAsBigDay.
theBigDay = new Date("July 1, 1999")
sameAsBigDay = new Date()
sameAsBigDay.setTime(theBigDay.getTime())
See also
setTime method
getTimezoneOffset
Method. Returns the time zone offset in minutes for the current locale.
Syntax
dateObjectName.getTimezoneOffset()
Parameters
dateObjectName is either the name of a date object or a property of an existing object.
Method of
Date
Description
The time zone offset is the difference between local time and GMT. Daylight savings time prevents this value from being a constant.
Examples
x = new Date()
currentTimeZoneOffsetInHours = x.getTimezoneOffset()/60
getYear
Method. Returns the year in the specified date.
Syntax
dateObjectName.getYear()
Parameters
dateObjectName is either the name of a date object or a property of an existing object.
Method of
Date
Description
The value returned by getYear is the year less 1900. For example, if the year is 1976, the value returned is 76.
Examples
The second statement below assigns the value 95 to the variable year, based on the value of the date object Xmas95.
Xmas95 = new Date("December 25, 1995 23:15:00")
year = Xmas95.getYear()
See also
setYear method