Functions and Statements in Visual Basic 6.0 (D-H)

Date Function

Date

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

Date Statement

Date = date

Sets the current system date as specified by the date argument. For Windows 95 systems, date must be a valid date between January 1, 1980 and December 31, 2099. For Windows NT systems, date must be a valid date between January 1, 1980 and December 31, 2079.

DateAdd Function

DateAdd(interval, number, date)

Returns a Variant of subtype Date calculated by taking the date specified by the date argument and adding or subtracting the amount of time specified by interval and time. The interval argument contains a code that represents a unit of time (for example, yyyy for years, m for months, d for days), and number is the number of units to be added to date.

DateDiff Function

DateDiff(interval, date1, date2[,firstdayofweek[, firstweekofyear]])

Returns a Variant of subtype Long that represents the number of time units between two dates (date1 and date2). The interval argument contains a code that represents the unit of time (for example, yyyy for years) that will be returned by the function. The optional firstdayofweek and firstweekofyear arguments are used to specify how the time difference should be calculated when certain codes are used for interval.

DatePart Function

DatePart(interval, date[,firstdayofweek[,firstweekofyear]])

Returns a Variant of subtype Integer that contains the part of date specified by interval. The interval argument contains a code that represents the unit of time (for example, ww for weeks) that will be returned by the function. The optional firstdayofweek and firstweekofyear arguments are used to specify how the date should be calculated when certain interval codes are used.

DateSerial Function

DateSerial(year, month, day)

Returns a Variant of subtype Date that represents a date as specified by the year, month, and day arguments.

DateValue Function

DateValue(date)

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

Day Function

Day(date)

Returns a Variant of subtype Integer that represents the day of the month (1[nd]31) for the date value specified by the date argument.

DDB Function

DDB(cost, salvage, life, period[, factor])

Returns a Double value that represents the depreciation of an asset for a specified amount of time using a given method of depreciation. The cost argument represents the initial cost of the asset, salvage represents the value of the asset at the end of its working lifetime, life represents the lifetime of the asset, and period represents the period (in months) for which the depreciation is calculated. The optional factor argument specifies the rate at which the balance declines. If it is omitted, then the double-declining depreciation method is used.

Declare Statement

[Public | Private] Declare Sub name Lib "libname" [Alias _ "aliasname"][([arglist])]

or

[Public | Private] Declare Function name Lib "libname" 
[Alias "aliasname"][([arglist])][As type]

Declares references to Sub or Function procedures in an external DLL (dynamic-link library). The optional Public and Private keywords define the procedure's scope. The name argument is the name of the procedure, and the libname argument specifies the DLL that contains the procedure. The optional aliasname argument specifies an alternate name for the procedure in the DLL. arglist is a list of arguments passed to the procedure. For Function procedures, the As type specifies the data type of the value returned by the Function. Declare statements can only be used at module level.

DefBool Statement

DefBool letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the Boolean data type. The letterrange arguments should be constructed as letter1[-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefBool can only be used at module level.

DefByte Statement

DefByte letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the Byte data type. The letterrange arguments should be constructed as letter1[-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefByte can only be used at module level.

DefCur Statement

DefCur letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the Currency data type. The letterrange arguments should be constructed as letter1 [-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefCur can only be used at module level.

DefDate Statement

DefDate letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the Date data type. The letterrange arguments should be constructed as letter1[-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefDate can only be used at module level.

DefDbl Statement

DefDbl letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the Double data type. The letterrange arguments should be constructed as letter1[-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefDbl can only be used at module level.

DefDec Statement

DefDec letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the Decimal data type. The letterrange arguments should be constructed as letter1[-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefDec can only be used at module level.

DefInt Statement

DefInt letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the Integer data type. The letterrange arguments should be constructed as letter1[-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefInt can only be used at module level.

DefLng Statement

DefLng letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the Long data type. The letterrange arguments should be constructed as letter1[-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefLng can only be used at module level.

DefObj Statement

DefObj letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the Object data type. The letterrange arguments should be constructed as letter1[-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefObj can only be used at module level.

DefSng Statement

DefSng letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the Single data type. The letterrange arguments should be constructed as letter1[-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefSng can only be used at module level.

DefStr Statement

DefStr letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the String data type. The letterrange arguments should be constructed as letter1[-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefStr can only be used at module level.

DefVar Statement

DefVar letterrange[, letterrange]...

Specifies that all variables and function return values that begin with the letters specified by the letterrange arguments are automatically defined to be of the Variant data type. The letterrange arguments should be constructed as letter1[-letter2], where letter1 is the first (or only) letter in the range, and letter2 is the last letter in the range. DefVar can only be used at module level.

DeleteSetting Statement

DeleteSetting appname, section[, key]

Deletes an application's section or key setting entries from the System Registry. The appname argument specifies the name of the application, and section is the name of the section to be deleted. If the optional key argument is used, then only that key (and not the whole section) will be deleted.

Dim Statement

Dim [WithEvents] varname[([subscripts])] [As [New] type] [,[WithEvents] 
varname[([subscripts])] [As [New] type]]...

Declares one or more variables or objects. 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 WithEvents keyword (valid only when the Dim statement is used in class modules) indicates that varname is an object variable as is used to respond to events triggered by an ActiveX object. The optional subscripts are the dimensions of an array variable.

Dir Function

Dir[(pathname[, attributes])]

Returns a String value containing the name of a file, directory, or folder that matches a pattern (specified in the pathname argument) and/or a file attribute (specified in attributes). The first time the Dir function is called, it returns the name of a file based on the pathname and attributes arguments. If the function is called again and no arguments are given, then it returns the second file name for the given pathname and attributes, and so on.

Do...Loop Statement

Do [{While | Until} condition]
   [statements]
   [Exit Do]
   [statements]
Loop

or

Do
   [statements]
   [Exit Do]
   [statements]
Loop [{While | Until} condition]

Repeats one or more statements while a condition is True or until a condition becomes True. The optional Exit Do keywords pass control to the line of code immediately following the Do...Loop structure.

DoEvents Function

DoEvents( )

Temporarily gives control to the operating system so that it can process other events. The DoEvents function is typically used inside loops so that a program does not tie up system resources for a long period of time.

End Statement

End
End Function
End If
End Property
End Select
End Sub
End Type
End With

Ends a program (End), procedure (End Function, End Property, or End Sub), type structure (End Type), or program block (End If, End Select, or End With).

Enum Statement

[Public | Private] Enum name
    membername [= constantexpression]
    membername [= constantexpression]
      ...
End Enum

Declares an enumeration type named name that is composed of one or more members specified by membername. Members can be assigned values using constantexpression. The optional Public and Private keywords define the enumeration's scope.

Environ Function

Environ({envstring | number})

Returns the String value of the operating system variable specified by envstring or, alternatively, the numeric order of the environment string in the environment-string table specified by number.

EOF Function

EOF(filenumber)

Returns a True or False value (Integer) that indicates whether the end of file marker has been reached for the Random or Input file associated with the filenumber argument.

Erase Statement

Erase arraylist

Reinitializes the elements in one or more fixed-size array and frees up the dynamic-array storage space that was taken up by the array(s). The arraylist argument is one or more comma-delimited array names.

Error Function

Error[(errornumber)]

Returns a String value that contains the error message that corresponds to the errornumber argument.

Error Statement

Error errornumber

Causes an error to occur. The errornumber argument indicates the type of error that should occur.

Event Statement

[Public] Event procedurename [(arglist)]

Declares a user-defined event with the name procedurename. The optional Public keyword indicates that the Event should be visible throughout the project, even though that is the default. The optional argument list (arglist) should contain one or more arguments defined using the syntax:

   [ByVal | ByRef] varname[()] [As type]

where varname is the name of the argument, As type indicates the data type of the argument, and the optional ByRef or ByVal keywords specify whether the argument should be passed by reference (ByRef) or by value (ByVal). If ByRef and ByVal are not specified, then the argument will be passed by reference.

Exit Statement

Exit Do
Exit For
Exit Function
Exit Property
Exit Sub

Exits a procedure (Exit Function, Exit Property, or Exit Sub) or looping structure (Exit Do or Exit For).

Exp Function

Exp(number)

Returns a Double value that is e (the base of natural logarithms) raised to the power specified by number.

FileAttr Function

FileAttr(filenumber, returntype)

Returns a Long value that indicates the file mode for a file opened using the Open statement. The argument filenumber is the file number for the open file, and returntype indicates the type of information to be returned. Although returntype can be set to 2 to return the operating system file handle for the open file, it only works on 16-bit systems and should be avoided in VB5. Instead, use a value of 1 for returntype to return the open file type. The possible values returned by the FileAttr function for indicating file type are: 1 for Input, 2 for Output, 4 for Random, 8 for Append, and 32 for Binary.

FileCopy Statement

FileCopy source, destination

Copies the filename and path specified by the source argument to the filename and path specified by the destination argument.

FileDateTime Function

FileDateTime(pathname)

Returns a Variant of subtype Date that indicates the date and time when the file specified by the pathname argument was last modified.

FileLen Function

FileLen(pathname)

Returns a Long value that contains the file size (in bytes) of the file specified by the pathname argument.

Fix Function

Fix(number)

Returns the integer portion of the number specified by the number argument. If number is negative, then Fix returns the first negative integer greater than or equal to number.

For Each...Next Statement

For Each element In group
    [statements]
    [Exit For]
    [statements]
Next [element]

Executes one or more statements for each element in the array or collection specified by group. The optional Exit For can be used to immediately exit the looping structure.

For...Next Statement

For counter = start To end [Step step]
    [statements]
    [Exit For]
    [statements]
Next [counter]

Executes one or more statements a specified number of times. The counter argument is a variable used to increment from start to end. By default, counter is incremented by 1 each time the loop is executed, although the optional step argument can be used to specify a different increment. The optional Exit For can be used to immediately exit the looping structure.

Format Function

Format(expression[, format[, firstdayofweek[, _  firstweekofyear]]])

Returns a Variant of subtype String that contains the value specified by expression using a format defined by the format argument. The format argument uses codes (for example, d for days or # for numbers) to determine how expression will be formatted. The optional firstdayofweek and firstweekofyear arguments are used when formatting certain values.

FreeFile Function

FreeFile[(rangenumber)]

Returns an Integer value the represents the next file number available for use with the Open statement. The optional rangenumber argument can be used to specify which range of file numbers should be used: 0 (the default) for file numbers in the range of 1-255, or 1 for file numbers in the range of 256-511.

Function Statement

[Public | Private | Friend] [Static] Function name _ [(arglist)] [As type]
    [statements]
    [name = expression]
    [Exit Function]
    [statements]
    [name = expression]
End Function

Declares the various parts of a Function procedure. The optional Public, Private, and Friend keywords can be used to define the Function's scope, and the optional Static keyword indicates that the procedure's local variables are preserved between calls to the Function. The name argument specifies the name of the Function procedure and can be assigned a value (name = expression) that will be returned by the procedure. The data type of the return value can be specified using the As type clause. The optional Exit Function can be used to exit the Function 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.

FV Function

FV(rate, nper, pmt[, pv[, type]])

Returns a Double value that indicates the future value of an annuity based on a number (nper) of periodic fixed payment amounts (pmt) and a fixed interest rate (rate). The optional pv argument specifies a present value or lump sum of a series of future payments, and the optional type argument specifies when payments are due (0 for end of the payment period, the default; 1 for beginning of the payment period).

Get Statement

Get [#]filenumber,[ recnumber,] varname

Reads data from the open disk file corresponding to the filenumber argument into a variable (varname). Get works with files open as Random or Binary, and a record number (recnumber) can be specified when retrieving data from a Random file. When using Binary files, recnumber can alternatively be used to specify the byte position from which the data is to be read.

GetAllSettings Function

GetAllSettings(appname, section)

Returns a list of key settings and their values from a specific application (appname) entry and section (section) in the System Registry.

GetAttr Function

GetAttr(pathname)

Returns an Integer value that represents the attributes for the file, directory, or folder specified by the pathname argument. The value returned can be compared bitwise with several VB constants (vbNormal, vbReadOnly, vbHidden, vbSystem, vbDirectory, and vbArchive) to determine which attributes are set.

GetAutoServerSettings Function

object.GetAutoServerSettings([progid], [clsid])

Returns a Variant array that contains information concerning the state of an ActiveX object's registration. The optional progid and clsid can be included to specify the object's ProgID and CLSID, respectively. The values of the elements of the Variant array that are returned by GetAutoServerSettings are, in order: local/remote registration of object (True if the object is registered remotely), the remote machine name, the RPC network protocol name, and the RPC authentication level.

GetObject Function

GetObject([pathname] [,class])

Returns a reference to an object of type class. The pathname argument can be included to specify the path and filename from which the object should be retrieved; however, if it is omitted, then the class name must be specified.

GetSetting Function

GetSetting(appname, section, key[, default])

Returns a single key setting value from a specific application (appname) entry and section (section) in the System Registry. If no value is set for the key setting specified, then the optional default value can be returned. If default is omitted, then the default value returned will be a zero-length string.

GoSub...Return Statement

GoSub line
    ...
    line
    ...
Return

Transfers program control to the subroutine indicated by the line label or line number line until the Return statement is reached; then returns control to the line of code immediately following the GoSub statement.

GoTo Statement

GoTo line

Transfers program control to the line of code specified by the line label or line number line. The line must be inside the procedure that contains the GoTo statement.

Hex Function

Hex(number)

Returns a String value that represents the hexadecimal value of the argument number.

Hour Function

Hour(time)

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

to be continued.............

No comments: