RAS Playground 日本語 GitHub

Type definitions (Excel, VBA)

Scripting, VBScript and ADODB

These are the type definitions for the Microsoft Scripting Runtime (FileSystemObject, Dictionary), VBScript regular expressions (RegExp) and ADO's Stream. None of them is in the VBA project's references, so the generated VBA uses late binding (variables are Object, they are created with CreateObject(…), and enum values are numbers). In RAS you create them with new Scripting.FileSystemObject() / new Scripting.Dictionary() / new VBScript.RegExp().

Reference

Enum Scripting.IOMode

What a file is opened for with openTextFile / openAsTextStream.

Microsoft reference

#
forReading = 1

Reading.

#
forWriting = 2

Writing (the content is overwritten).

#
forAppending = 8

Appending to the end.

scripting.d.ras

Enum Scripting.Tristate

The encoding of a text file. tristateFalse is ANSI (Shift_JIS on Japanese Windows), tristateTrue is Unicode (UTF-16).

Microsoft reference

#
tristateTrue = -1
#
tristateFalse = 0
#
tristateUseDefault = -2

The system default (ANSI).

scripting.d.ras

Enum Scripting.SpecialFolderConst

The folder to get with getSpecialFolder.

Microsoft reference

#
windowsFolder = 0
#
systemFolder = 1
#
temporaryFolder = 2

The folder for temporary files (TMP).

scripting.d.ras

Interface Scripting.FileSystemObject

Works with files and folders. Create one with new Scripting.FileSystemObject().

Microsoft reference

#
buildPath(path: string, name: string): string

Appends a name to the end of a path (a separator is inserted only when needed).

Microsoft reference

VBA: BuildPath

#
copyFile(source: string, destination: string, overWriteFiles?: boolean): void

Copies files. The last part of the source can contain wildcards (* ?).

Microsoft reference

VBA: CopyFile

#
copyFolder(source: string, destination: string, overWriteFiles?: boolean): void

Copies a folder with its contents.

Microsoft reference

VBA: CopyFolder

#
createFolder(path: string): Folder

Creates a folder. Error 58 if it already exists.

Microsoft reference

VBA: CreateFolder

#
createTextFile(fileName: string, overwrite?: boolean, unicode?: boolean): TextStream

Creates and opens a text file. UTF-16 when unicode is true; ANSI by default.

Microsoft reference

VBA: CreateTextFile

#
deleteFile(fileSpec: string, force?: boolean): void

Deletes files. The last part can contain wildcards. Error 53 if none exist.

Microsoft reference

VBA: DeleteFile

#
deleteFolder(folderSpec: string, force?: boolean): void

Deletes a folder with its contents.

Microsoft reference

VBA: DeleteFolder

#
driveExists(driveSpec: string): boolean

Whether the drive exists.

Microsoft reference

VBA: DriveExists

#
fileExists(fileSpec: string): boolean

Whether the file exists.

Microsoft reference

VBA: FileExists

#
folderExists(folderSpec: string): boolean

Whether the folder exists.

Microsoft reference

VBA: FolderExists

#
getAbsolutePathName(path: string): string

Converts to an absolute path.

Microsoft reference

VBA: GetAbsolutePathName

#
getBaseName(path: string): string

The last part of the path without its extension.

Microsoft reference

VBA: GetBaseName

#
getDriveName(path: string): string

The drive name of the path (C:).

Microsoft reference

VBA: GetDriveName

#
getExtensionName(path: string): string

The extension of the last part of the path (without the .).

Microsoft reference

VBA: GetExtensionName

#
getFile(filePath: string): File

Returns a File for the file. Error 53 if it does not exist.

Microsoft reference

VBA: GetFile

#
getFileName(path: string): string

The last part of the path (the file name).

Microsoft reference

VBA: GetFileName

#
getFolder(folderPath: string): Folder

Returns a Folder for the folder. Error 76 if it does not exist.

Microsoft reference

VBA: GetFolder

#
getParentFolderName(path: string): string

The path of the parent folder (the path without its last part).

Microsoft reference

VBA: GetParentFolderName

#
getSpecialFolder(specialFolder: SpecialFolderConst): Folder

Returns the Windows, system or temporary folder.

Microsoft reference

VBA: GetSpecialFolder

#
getTempName(): string

Makes a unique name for a temporary file (rad1A2B3.tmp). No file is created.

Microsoft reference

VBA: GetTempName

#
moveFile(source: string, destination: string): void

Moves files (also used to rename).

Microsoft reference

VBA: MoveFile

#
moveFolder(source: string, destination: string): void

Moves a folder (also used to rename).

Microsoft reference

VBA: MoveFolder

#
openTextFile(fileName: string, ioMode?: IOMode, create?: boolean, format?: Tristate): TextStream

Opens a text file. When create is true, it is created if it does not exist.

Microsoft reference

VBA: OpenTextFile

#
readonly drives: object

The list of drives.

Microsoft reference

VBA: Drives

#
getDrive(driveSpec: string): object

Returns an object for the drive.

Microsoft reference

VBA: GetDrive

scripting.d.ras

Interface Scripting.File

A file. Get one with FileSystemObject.getFile or a folder's files.

Microsoft reference

#
name: string

The file name. Assigning to it renames the file.

VBA: Name

#
readonly path: string

The full path.

VBA: Path

#
readonly shortName: string

The short (8.3) file name.

VBA: ShortName

#
readonly shortPath: string

The short (8.3) path.

VBA: ShortPath

#
readonly parentFolder: Folder

The parent folder.

VBA: ParentFolder

#
readonly drive: object

The drive.

VBA: Drive

#
readonly size: any

The size (bytes).

VBA: Size

#
readonly type: string

A description of the file type (Text Document and so on).

VBA: Type

#
attributes: int

The attributes (a combination of vbReadOnly, vbHidden and so on).

VBA: Attributes

#
readonly dateCreated: date

When it was created.

VBA: DateCreated

#
readonly dateLastAccessed: date

When it was last accessed.

VBA: DateLastAccessed

#
readonly dateLastModified: date

When it was last modified.

VBA: DateLastModified

#
copy(destination: string, overWriteFiles?: boolean): void

Copies it.

Microsoft reference

VBA: Copy

#
move(destination: string): void

Moves it.

Microsoft reference

VBA: Move

#
delete(force?: boolean): void

Deletes it.

Microsoft reference

VBA: Delete

#
openAsTextStream(ioMode?: IOMode, format?: Tristate): TextStream

Opens it as a text file.

Microsoft reference

VBA: OpenAsTextStream

scripting.d.ras

Interface Scripting.Files

The files in a folder. Can be enumerated with for...of and indexed by file name.

Microsoft reference

#
(key: any): File

Gets a file by name (default member).

#
item(key: any): File

Gets a file by name.

VBA: Item

#
readonly count: int

The number of files.

VBA: Count

scripting.d.ras

Interface Scripting.Folder

A folder. Get one with FileSystemObject.getFolder and so on.

Microsoft reference

#
name: string

The folder name. Assigning to it renames the folder.

VBA: Name

#
readonly path: string

The full path.

VBA: Path

#
readonly shortName: string

The short (8.3) folder name.

VBA: ShortName

#
readonly shortPath: string

The short (8.3) path.

VBA: ShortPath

#
readonly parentFolder: Folder

The parent folder. null for a root folder.

VBA: ParentFolder

#
readonly drive: object

The drive.

VBA: Drive

#
readonly isRootFolder: boolean

Whether it is a root folder.

VBA: IsRootFolder

#
readonly size: any

The total size of all the files and subfolders inside (bytes).

VBA: Size

#
readonly type: string

A description of the folder type.

VBA: Type

#
attributes: int

The attributes (a combination of vbDirectory and so on).

VBA: Attributes

#
readonly dateCreated: date

When it was created.

VBA: DateCreated

#
readonly dateLastAccessed: date

When it was last accessed.

VBA: DateLastAccessed

#
readonly dateLastModified: date

When it was last modified.

VBA: DateLastModified

#
readonly files: Files

The files inside.

VBA: Files

#
readonly subFolders: Folders

The subfolders.

VBA: SubFolders

#
copy(destination: string, overWriteFiles?: boolean): void

Copies it with its contents.

Microsoft reference

VBA: Copy

#
move(destination: string): void

Moves it.

Microsoft reference

VBA: Move

#
delete(force?: boolean): void

Deletes it with its contents.

Microsoft reference

VBA: Delete

#
createTextFile(fileName: string, overwrite?: boolean, unicode?: boolean): TextStream

Creates and opens a text file in this folder.

Microsoft reference

VBA: CreateTextFile

scripting.d.ras

Interface Scripting.Folders

The subfolders of a folder. Can be enumerated with for...of and indexed by folder name.

Microsoft reference

#
(key: any): Folder

Gets a folder by name (default member).

#
item(key: any): Folder

Gets a folder by name.

VBA: Item

#
readonly count: int

The number of subfolders.

VBA: Count

#
add(name: string): Folder

Creates a subfolder.

Microsoft reference

VBA: Add

scripting.d.ras

Interface Scripting.TextStream

An open text file, read or written sequentially.

Microsoft reference

#
readonly atEndOfLine: boolean

Whether the position is at the end of a line (just before a line break).

VBA: AtEndOfLine

#
readonly atEndOfStream: boolean

Whether the position is at the end of the file.

VBA: AtEndOfStream

#
readonly column: int

The current column (1-based).

VBA: Column

#
readonly line: int

The current line (1-based).

VBA: Line

#
close(): void

Closes it. What was written is committed to the file here.

Microsoft reference

VBA: Close

#
read(characters: int): string

Reads the given number of characters.

Microsoft reference

VBA: Read

#
readAll(): string

Reads all the rest.

Microsoft reference

VBA: ReadAll

#
readLine(): string

Reads one line (without the line break).

Microsoft reference

VBA: ReadLine

#
skip(characters: int): void

Skips the given number of characters.

Microsoft reference

VBA: Skip

#
skipLine(): void

Skips one line.

Microsoft reference

VBA: SkipLine

#
write(text: string): void

Writes a string (no line break is added).

Microsoft reference

VBA: Write

#
writeBlankLines(lines: int): void

Writes empty lines.

Microsoft reference

VBA: WriteBlankLines

#
writeLine(text?: string): void

Writes a string and a line break (CRLF).

Microsoft reference

VBA: WriteLine

scripting.d.ras

Interface Scripting.Dictionary

A dictionary holding key-value pairs. In RAS you normally use Map<K, V> (converted to the same Scripting.Dictionary). This type exists for existing code that uses CreateObject("Scripting.Dictionary") directly. for...of enumerates the keys.

Microsoft reference

#
(key: any): any

Returns the value for the key (default member). Reading a missing key adds it with an empty value. Set with d[key] = value.

A property with arguments (it can be assigned to: x(…) = value).

#
item(key: any): any

Returns the value for the key.

A property with arguments (it can be assigned to: x(…) = value).

VBA: Item

#
readonly count: int

The number of pairs.

VBA: Count

#
compareMode: VBA.VbCompareMethod

How keys are compared (vbBinaryCompare / vbTextCompare). Can only be changed while empty.

VBA: CompareMode

#
add(key: any, item: any): void

Adds a pair. Error 457 if the key already exists.

Microsoft reference

VBA: Add

#
exists(key: any): boolean

Whether the key exists.

Microsoft reference

VBA: Exists

#
items(): any[]

Returns an array of the values (0-based).

Microsoft reference

VBA: Items

#
keys(): any[]

Returns an array of the keys (0-based).

Microsoft reference

VBA: Keys

#
remove(key: any): void

Removes a pair. Error 32811 if the key does not exist.

Microsoft reference

VBA: Remove

#
removeAll(): void

Removes every pair.

Microsoft reference

VBA: RemoveAll

scripting.d.ras

Interface VBScript.RegExp

A regular expression. Create one with new VBScript.RegExp().

Microsoft reference

#
pattern: string

The pattern of the regular expression.

VBA: Pattern

#
global: boolean

Whether to find every match in the whole string (by default only the first).

VBA: Global

#
ignoreCase: boolean

Whether case is ignored.

VBA: IgnoreCase

#
multiline: boolean

Whether ^ and $ also match at the start and end of each line.

VBA: Multiline

#
test(sourceString: string): boolean

Whether some part matches the pattern.

VBA: Test

#
execute(sourceString: string): MatchCollection

Returns the matches.

VBA: Execute

#
replace(sourceString: string, replaceVar: any): string

Returns the string with the matches replaced. The replacement can use $1, $& and so on.

VBA: Replace

scripting.d.ras

Interface VBScript.MatchCollection

The matches returned by RegExp.execute (0-based). Can be enumerated with for...of.

#
(index: int): Match

Gets a match by number (0-based) (default member).

#
item(index: int): Match

Gets a match by number (0-based).

VBA: Item

#
readonly count: int

The number of matches.

VBA: Count

scripting.d.ras

Interface VBScript.Match

One part that matched the pattern.

#
readonly value: string

The matched string.

VBA: Value

#
readonly firstIndex: int

The position in the original string (0-based).

VBA: FirstIndex

#
readonly length: int

The length of the matched string.

VBA: Length

#
readonly subMatches: SubMatches

The parts that matched the ( ) of the pattern.

VBA: SubMatches

scripting.d.ras

Interface VBScript.SubMatches

The strings that matched the ( ) of the pattern (0-based). A ( ) that did not match is empty (Empty).

#
(index: int): any

Gets one by number (0-based) (default member).

#
item(index: int): any

Gets one by number (0-based).

VBA: Item

#
readonly count: int

The number of ( ).

VBA: Count

scripting.d.ras

Enum ADODB.StreamTypeEnum

The kind of content of a Stream (type).

Microsoft reference

#
adTypeBinary = 1

Bytes.

#
adTypeText = 2

Text (in the encoding of charset).

scripting.d.ras

Enum ADODB.SaveOptionsEnum

What saveToFile does when the file exists.

Microsoft reference

#
adSaveCreateNotExist = 1

Creates the file if it does not exist (an error if it does).

#
adSaveCreateOverWrite = 2

Overwrites it.

scripting.d.ras

Enum ADODB.StreamReadEnum

How much readText reads.

Microsoft reference

#
adReadAll = -1

All the rest.

#
adReadLine = -2

One line (up to lineSeparator).

scripting.d.ras

Enum ADODB.StreamWriteEnum

Whether writeText adds a line break.

Microsoft reference

#
adWriteChar = 0

The string only.

#
adWriteLine = 1

The string and a line break (lineSeparator).

scripting.d.ras

Enum ADODB.LineSeparatorEnum

The line separator (lineSeparator).

Microsoft reference

#
adCRLF = -1

CR LF (default).

#
adLF = 10

LF。

#
adCR = 13

CR。

scripting.d.ras

Interface ADODB.Stream

An in-memory stream for reading and writing bytes and text. Create one with new ADODB.Stream() and open() it before use. The encoding of text is charset ("utf-8", "shift_jis", "unicode" (UTF-16 LE), "unicodeFFFE" (UTF-16 BE), "euc-jp", "iso-2022-jp" and so on). Writing with "utf-8" and "unicode" puts a BOM at the start.

Microsoft reference

#
type: StreamTypeEnum

The kind of content (adTypeBinary / adTypeText). Can only be changed when position is 0.

VBA: Type

#
charset: string

The encoding of text (default "unicode"). Can only be changed when position is 0.

VBA: Charset

#
position: int

The current position (bytes, 0-based).

VBA: Position

#
readonly size: int

The size (bytes).

VBA: Size

#
readonly eos: boolean

Whether the position is at the end.

VBA: EOS

#
lineSeparator: LineSeparatorEnum

The line separator of readText(adReadLine) / writeText(…, adWriteLine).

VBA: LineSeparator

#
readonly state: int

Whether it is open (1) or closed (0).

VBA: State

#
open(): void

Opens it (as an empty stream).

Microsoft reference

VBA: Open

#
close(): void

Closes it.

Microsoft reference

VBA: Close

#
loadFromFile(fileName: string): void

Loads the contents of a file (replacing the content; position becomes 0).

Microsoft reference

VBA: LoadFromFile

#
saveToFile(fileName: string, options?: SaveOptionsEnum): void

Writes all the content to a file.

Microsoft reference

VBA: SaveToFile

#
readText(numChars?: int): string

Reads text (with adTypeText). All the rest by default.

Microsoft reference

VBA: ReadText

#
writeText(data: string, options?: StreamWriteEnum): void

Writes text (with adTypeText).

Microsoft reference

VBA: WriteText

#
read(numBytes?: int): any

Reads bytes (with adTypeBinary; an array of Byte). All the rest by default.

Microsoft reference

VBA: Read

#
write(buffer: any): void

Writes bytes (an array of Byte) (with adTypeBinary).

Microsoft reference

VBA: Write

#
copyTo(destStream: Stream, numChars?: int): void

Copies from the current position (only numChars characters or bytes; all the rest by default) to the current position of another stream.

Microsoft reference

VBA: CopyTo

#
setEOS(): void

Makes the current position the end (truncating what follows).

Microsoft reference

VBA: SetEOS

#
skipLine(): void

Skips one line.

Microsoft reference

VBA: SkipLine

#
flush(): void

Commits the content of the buffer.

Microsoft reference

VBA: Flush

scripting.d.ras