The following code returns the version number of an instance of Excel running on a remotenetwork computer named "myserver":Function GetVersionDim XLAppSet XLApp = CreateObject("Excel.Application", "MyServer")GetVersion = XLApp.VersionEnd FunctionAn error occurs if the specified remote server does not exist or cannot be found.
Declares variables and allocates storage space.Dimvarname[([subscripts])][,varname[([subscripts])]] . . .
ArgumentsvarnameName of the variable; follows standard variable naming conventions.subscriptsDimensions of an array variable; up to 60 multiple dimensions may be declared. Thesubscripts argument uses the following syntax:upperbound [,upperbound] . . .The lower bound of an array is always zero.RemarksVariables declared with Dim at the script level are available to all procedures within the script.At the procedure level, variables are available only within the procedure.You can also use the Dim statement with empty parentheses to declare a dynamic array. Afterdeclaring a dynamic array, use the ReDim statement within a procedure to define the number of dimensions and elements in the array. If you try to redeclare a dimension for an array variable whosesize was explicitly specified in a Dim statement, an error occurs.Note When you use the Dim statement in a procedure, you generally put the Dim statementat the beginning of the procedure.The following examples illustrate the use of the Dim statement:Dim Names(9) ' Declare an array with 10 elements.Dim Names() ' Declare a dynamic array.Dim MyVar, MyNum ' Declare two variables.
Reinitializes the elements of fixed-size arrays and deallocates dynamic-array storage space.Erase arrayThe array argument is the name of the array variable to be erased.RemarksIt is important to know whether an array is fixed-size (ordinary) or dynamic because Erasebehaves differently depending on the type of array. Erase recovers no memory for fixed-size arrays.Erase sets the elements of a fixed array as follows:Type of arrayEffect of Erase on fixed-array elementsFixed numeric arraySets each element to zero.Fixed string arraySets each element to zero-length ("").Array of objectsSets each element to the special value Nothing.Erase frees the memory used by dynamic arrays. Before your program can refer to thedynamic array again, it must redeclare the array variable's dimensions using a ReDim statement.The following example illustrates the use of the Erase statement.Dim NumArray(9)Dim DynamicArray()ReDim DynamicArray(9) ' Allocate storage space.Erase NumArray ' Each element is reinitialized.Erase DynamicArray ' Free memory used by array.
On Error Statement
Enables or disables error-handling.On Error Resume NextOn Error GoTo 0RemarksIf you don't use an On Error Resume Next statement anywhere in your code, any run-timeerror that occurs can cause an error message to be displayed and code execution stopped. However,the host running the code determines the exact behavior. The host can sometimes opt to handle sucherrors differently. In some cases, the script debugger may be invoked at the point of the error. In stillother cases, there may be no apparent indication that any error occurred because the host does not tonotify the user. Again, this is purely a function of how the host handles any errors that occur.