Functions and Statements in Visual Basic 6.0 (S-Z)

SavePicture Statement

SavePicture picture, stringexpression

Saves an graphic image from an object's Picture or Image property to a file. The picture argument specifies the control from which the graphics file is to be created (Picture or Image), and stringexpression specifies the path and filename to which the image is saved.

SaveSetting Statement

SaveSetting appname, section, key, setting

Saves or creates an application (appname) entry, section (section), key setting (key), and value (setting) in the System Registry.

Second Function

Second(time)

Returns a Variant of subtype Integer that represents the second (0[nd]59) of the time value specified by the time argument.

Seek Function

Seek(filenumber)

Returns a Long value that specifies the current record or byte position for the open file associated with filenumber. When dealing with Random files, Seek returns the number of the next record to be read or written. For all other file types, Seek returns a byte position.

Seek Statement

Seek [#]filenumber, position

Sets the record or byte position of the open file associated with filenumber.

Select Case Statement

Select Case testexpression
    [Case expressionlist-n
        [statements-n]] ...
    [Case Else
        [elsestatements]]
End Select

Evaluates an expression (testexpression) and, depending on the result, executes one or more statements (statements-n) that correspond to the expression's value (expressionlist-n). In other words, the value of testexpression is compared with one or more other values (expressionlist-n), and whichever matches gets its statements (statements-n) executed. If there are no matches, an optional Case Else set of statements (elsestatements) is executed.

SendKeys Statement

Generates one or more keystrokes as if they came from the keyboard. The string argument determines which keystrokes to send, and the optional Wait argument (Boolean) specifies whether keystrokes must be processed before control is returned to the procedure. False, the default value, means that control is returned to the procedure immediately after the keystrokes are sent.

Set Statement

Set objectvar = {[New] objectexpression | Nothing}

Assigns an object reference (objectexpression) to a variable or property (objectvar). The optional New keyword can be used to indicate that the object should be created implicitly. To disassociate objectvar with a specific object and free up the resources it is using, assign it the Nothing keyword.

SetAttr Statement

SetAttr pathname, attributes

Sets attributes for the file or directory specified by the pathname argument. The attributes argument can use several VB constants (vbNormal, vbReadOnly, vbHidden, vbSystem, vbDirectory, and vbArchive) that can be combined bitwise to determine which attributes are set.

Sgn Function

Sgn(number)

Returns a Variant of subtype Integer that represents the sign of a given number.

Shell Function

Shell(pathname[, windowstyle])

Runs the executable program specified by the pathname argument and returns a Variant of subtype Double that represents the program's task ID. If Shell is unsuccessful, it returns zero. The optional windowstyle argument determines the style of the window in which the shelled program runs.

Sin Function

Sin(number)

Returns a Double value that represents the sine of a given angle (as specified by the number argument).

SLN Function

SLN(cost, salvage, life)

Returns a Double value that represents the straight-line depreciation of an asset when given its initial cost, salvage value at the end of its useful life, and life span.

Space Function

Space(number)

Returns a Variant of subtype String that contains a number of spaces.

Spc Function

Spc(n)

Inserts a specified number of spaces (n) when writing or displaying text using the Print # statement or the Print method.

Sqr Function

Sqr(number)

Returns a Double value that represents the square root of a given number.

Static Statement

Static varname[([subscripts])] [As [New] type] [, varname[([subscripts])] 
[As [New] type] ...

Declares one or more static variables, which retain their values as long as the program is running. The varname argument is the name of the variable, and the optional As [New] type indicates its data type. If the New keyword is used, then an implicit creation of the object is made. The optional subscripts are the dimensions of an array variable.

Stop Statement

Stop

Suspends program execution.

Str Function

Str(number)

Returns a Variant of subtype String that is a representation of a given number.

StrComp Function

StrComp(string1, string2[, compare])

Returns a Variant of subtype Integer that indicates the result of a comparison between two strings (string1 and string2). The optional compare argument specifies how strings are to be compared, with 0 for a binary comparison and 1 for a noncase- sensitive textual comparison.

StrConv Function

StrConv(string, conversion)

Returns a Variant of subtype String that has been converted from an original string as specified by the conversion argument. The conversion argument can use several VB constants to specify the type of conversion, such as vbUpperCase, vbLowerCase, and vbProperCase.

String Function

String(number, character)

Returns a Variant of subtype String that is of the length specified by number and is filled with a given character.

Sub Statement

[Public | Private | Friend] [Static] Sub name [(arglist)]
    [statements]
    [Exit Sub]
    [statements]
End Sub

Declares the various parts of a Sub procedure. The optional Public, Private, and Friend keywords can be used to define the Sub's scope, and the optional Static keyword indicates that the procedure's local variables are preserved between calls to the Sub. The name argument specifies the name of the Sub procedure. The optional Exit Sub can be used to exit the Sub procedure immediately.

The optional list of arguments (arglist) defines the arguments that will be passed to the procedure. The arguments should use the following syntax:

[Optional] [ByVal | ByRef] [ParamArray] varname[()] [As _ type] [= default value]

where the Optional keyword can be used to specify that the argument is not required (default value assigns the argument's default value), ByVal and ByRef determine whether the argument should be passed by value or by reference (the default), and the ParamArray keyword specifies that the argument is an Optional array of Variant elements. ParamArray can only be used with the last argument in the argument list.

Switch Function

Switch(expr-1, value-1[, expr-2, value-2 ... [, expr-n, _ value-n]])

Evaluates a list of expressions (expr-1, expr-2...expr-n) and returns a Variant value that corresponds to the first expression that evaluates as True. If expr-1 is True, then Switch returns the value indicated by value-1; if expr-2 is True, then Switch returns the value indicated by value-2; and so on.

SYD Function

SYD(cost, salvage, life, period)

Returns a Double value that represents the sum-of-years' digits depreciation of an asset when given its initial cost, salvage value at the end of its useful life, life span, and period for which depreciation is calculated.

Tab Function

Tab(n)

Positions output to a given column (n) when writing or displaying text using the Print # statement or the Print method.

Tan Function

Tan(number)

Returns a Double value that represents the tangent of a given angle (specified by the number argument).

Time Function

Time

Returns a Variant of subtype Date that contains the current system time.

Time Statement

Time = time

Sets the system time to the time specified by the time argument.

Timer Function

Timer

Returns a Single value that represents the number of seconds that have elapsed since midnight.

TimeSerial Function

TimeSerial(hour, minute, second)

Returns a Variant of subtype Date that represents a time as specified by the hour, minute, and second arguments.

TimeValue Function

TimeValue(time)

Returns a Variant of subtype Date that is derived from the time value specified by the time argument.

Trim Function

Trim(string)

Returns a Variant of subtype String that contains a copy of a given string with any leading and trailing spaces removed.

Type Statement

[Private | Public] Type varname
    elementname [([subscripts])] As type
    [elementname [([subscripts])] As type]
    ...
End Type

Defines a user-defined type (UDT) structure that contains one or more elements (elementname). The optional Public and Private keywords specify the UDT's scope, and varname specifies the UDT's name. Elements can be arrays (by specifying subscripts), and their data type must be defined using the As type clause. The Type statement can only be used at module level.

TypeName Function

TypeName(varname)

Returns a String value that indicates the data type of a given variable (varname). Possible return values are: Byte, Integer, Long, Single, Double, Currency, Decimal, Date, String, Boolean, Error, Empty, Null, Object, Unknown, Nothing, or an object type.

UBound Function

UBound(arrayname[, dimension])

Returns a Long value that represents the largest subscript for a dimensioned array (arrayname). For multidimensional arrays, the dimension argument can be included to specify which dimension should be used.

UCase Function

UCase(string)

Converts a string to all uppercase characters and returns a new String value.

Unload Statement

Unload object

Unloads an object (such as a form or control) from memory and frees up any resources being used by the object.

Unlock Statement

Unlock [#]filenumber[, recordrange]

Removes locking that prevents another process from accessing all or part of the open file that corresponds to the filenumber argument. The recordrange argument refers to a range of records (or bytes) that are to be unlocked and should use the syntax:

recnumber | [start] To end

where recnumber is the record number (for Random files) or byte position (for Binary files) where unlocking should begin. Alternatively, the starting and ending record numbers or bytes to be unlocked can be specified using the start and end arguments.

Val Function

Val(string)

Returns the numeric value of a string. The data type that is returned by Val depends on the kind of numeric value the string contains. If the string does not contain a numeric value, then Val returns zero.

VarType Function

VarType(varname)

Returns an Integer value that represents the subtype of the variable specified by varname. Several VB constants are used to define the data type values returned by the VarType function, including: vbEmpty, vbNull, vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbDate, vbString, vbObject, vbError, vbBoolean, vbVariant, vbDataObject, vbDecimal, vbByte, and vbArray.

Weekday Function

Weekday(date, [firstdayofweek])

Returns a Variant of subtype Integer that represents the day of the week for a given date. Weekday returns a 1 for Sunday, 2 for Monday, and so on. The optional firstdayofweek argument can be used to specify the first day of the week. If firstdayofweek is not specified, then Sunday (1) is assumed.

While...Wend Statement

While condition
    [statements]
Wend

Repeats one or more statements while a condition remains True. When the condition becomes False, then control is passed to the line of code immediately following the While...Wend structure.

Width # Statement

Width #filenumber, width

Assigns an output line width (in characters) for the open file associated with filenumber.

With Statement

With object
    [statements]
End With

Executes one or more statements on a single object or user-defined type.

Write # Statement

Write #filenumber, [outputlist]

Writes data to the open sequential file associated with the filenumber argument. The varlist argument should contain one or more comma-delimited variables that contain the data to be written to the file.

Year Function

Year(date)

Returns a Variant that represents the year for the date value specified by the date argument.

No comments: