Vbscript in a Nutshell
Authors: Lomax P. Petrusha R. Childs M.
Published year: 2003
Pages: 151-152/335
Buy this book on amazon.com >>
Fix Function

Syntax

Fix(


number


)
number

Use: Required

Data Type: Numeric

Any valid numeric expression.

Return Value

The same data type as passed to the function containing only the integer portion of number .

Description

Removes the fractional part of a number. Operates in a similar way to the Int function.

Rules at a Glance

  • If number is Null , Fix returns Null .

  • The operations of Int and Fix are identical when dealing with positive numbers: numbers are rounded down to the next lowest whole number. For example, both Int(3.14) and Fix(3.14) return 3.

  • If number is negative, Fix removes its fractional part, thereby returning the next greater whole number. For example, Fix(-3.667) returns -3. This contrasts with Int , which returns the negative integer less than or equal to number (or -4, in the case of our example).

Example

Dim dblTest
   Dim varTest

   dblTest = -100.9353
   varTest = Fix(dblTest)
   ' returns -100
  Msgbox  varTest & " " & TypeName(varTest) 

   dblTest = 100.9353
   varTest = Fix(dblTest)
   'returns 100
   Msgbox.Print varTest & " " & TypeName(varTest)

Programming Tips and Gotchas

Fix doesn't round number to the nearest whole number; it simply removes the fractional part of number . Therefore, the integer returned by Fix is the nearest whole number less than (or greater than, if the number is negative) the number passed to the function.

See Also

Int Function, CInt Function, CLng Function, Round Function

Folder Object

Createable

No

Returned by

Drive.RootFolder property
FileSystemObject.CreateFolder method
FileSystemObject.GetFolder method
Folder. SubFolders .Item property
Folders.Add method

Library

Microsoft Scripting Runtime

Description

The Folder object allows you to interrogate the system properties of the folder and provides methods that allow you to copy, move, and delete the folder. You can also create a new text file within the folder.

The Folder object is unusual because with it, you can gain access to a Folders collection object. The more usual method is to extract a member of a collection to gain access to the individual object. However, because the Drive object exposes only a Folder object for the root folder, you have to extract a Folders collection object from a Folder object (the collection represents the subfolders of the root). From this collection, you can navigate downward through the filesystem to extract other Folder objects and other Folders collections. A Boolean property, IsRootFolder, informs you of whether the Folder object you are dealing with currently is the root of the drive.

The Folder object is one of the objects in the Filesystem object model; for an overview of the model, see the "File System Object Model" entry.

Properties

Attributes

Data Type: Long

A set of flags representing the folder's attributes. The flags that apply to folders are:

Constant

Value

Archive

32

Directory

16

Hidden

2

ReadOnly

1

System

4

As the table shows, the Scripting Runtime type library defines constants of the FileAttribute enumeration that can be used in place of their numeric equivalents. You can use them in your scripts in either of two ways. You can define the constants yourself by adding the following code to your script:

Const Normal = 0
Const ReadOnly = 1
Const Hidden = 2
Const System = 4
Const Directory = 16
Const Archive = 32

Or you can take advantage of the host's facilities to make the constants accessible. In Active Server Pages, you can include the METADATA tag in the global.asa file and provide the type library identifier for the Scripting Runtime as follows :

<!-- METADATA TYPE="TypeLib"
    UUID="420B2830-E718-11CF-893D-00A0C9054228"
-->

In Windows Script Host, you can include the following line in a .wsf file in order to access the constants defined in the Scripting Runtime:

<reference GUID="" />

You can determine which flag is set by using a logical AND along with the value returned by the property and the value of the flag you'd like to test. For example:

If oFolder.Attributes And ReadOnly Then
   ' Folder is read-only

To clear a flag, And the value of the Attributes property with a Long in which the flag you want to clear is turned off. For example, the following code clears a Folder object's read-only flag:

oFile.Attributes = oFile.Attributes And (Not
ReadOnly)
Date Created

Data Type: Date

The date and time the folder was created.

DateLastAccessed

Data Type: Date

The date and, if it's available from the operating system, the time that the folder was last accessed.

DateLastModified

Data Type: Date

The date and time the folder was last modified.

Drive

Data Type: Drive object

Returns a Drive object representing the drive on which this folder resides; the property is read-only.

Files

Data Type: Files collection object

Returns a read-only Files collection object representing all files in the current folder.

IsRootFolder

Data Type: Boolean

Returns True if the folder is the root folder of its drive.

Name

Data Type: String

Returns the name of the folder.

ParentFolder

Data Type: Folder object

Returns a folder object representing the folder that's the parent of the current folder. It returns Nothing if the current object is the root folder of its drive (i.e., if its IsRootFolder property is True ).

Path

Data Type: String

Returns the complete path of the current folder, including its drive. It is the default property of the Folder object.

ShortName

Data Type: String

Returns a DOS 8.3 folder name without the folder's path. The property is read-only.

ShortPath

Data Type: String

Returns the complete path to a folder in DOS 8.3 format. The property is read-only.

Size

Data Type: Long

Returns the total size of all files, subfolders, and their contents in the folder structure, starting with the current folder. The property is read-only.

In previous versions of the Scripting Runtime, this property failed to accurately report the size of a folder whose files and subfolders occupied more than 2 GB of disk space.

Attempting to retrieve the value of a Folder object's Size property when that folder is a drive's root folder (that is, its IsRootFolder property returns True) generates a runtime error.

SubFolders

Data Type: Folders collection object

Returns a Folders collection object representing all subfolders within the current folder.

Type

Data Type: String

Returns the description of a filesystem object, as recorded in the system registry. For Folder objects, the property always returns "File Folder."

Methods

Copy
Create TextFile
Delete
Move
Vbscript in a Nutshell
Authors: Lomax P. Petrusha R. Childs M.
Published year: 2003
Pages: 151-152/335
Buy this book on amazon.com >>

Similar books on Amazon