General Statistica Visual Basic Language Features Data Types Subroutines Functions Classes Objects
- What are local variables vs. global variables?
Variables declared in a Visual Basic program are visible (i.e., they can be referenced) inside the "scope" where they are defined. The scope is the program unit inside of which the variable is defined. For example, variables declared inside a subroutine are only visible inside that subroutine. Variables declared outside any routines, before any program code, are visible to all subroutines and functions in the same file. In the programs shown below, variable a is either defined inside the Main routine, and then must be passed to the subroutine that displays its value, or it is declared as a global variable, outside the Main routine, in which case it is visible in all subroutines and functions in the same file. - What is the difference between passing variables to subroutines and functions by value and by reference?
If you want to pass a variable to a subroutine, run computations on it, and alter its contents, then the variable must be passed by reference (this is the default method how arguments are passed to subroutines or functions). Essentially, passing a variable by reference means passing the variable itself to the subroutine, and any changes made to it in the subroutine will be permanent. By contrast, if you want to pass a variable, run computations on it, and alter the temporary instance of it within the subroutine without affecting the original variable, then you must pass the variable by value. When a variable is passed by value to a function or subroutine, only a copy of the variable is passed, not the actual variable. If any changes are applied to the variable within the called function, then those changes will only pertain to the copy of the original variable. When passing a variable by value, its value will always be preserved, no matter what is done within the called function. To illustrate, instead of making ComputeSumOfSqrs in this example a function, we could make it a subroutine and pass the variable SumValue as an argument by reference; by using this approach, SumValue will be directly altered by the subroutine without needing to return a value. Note that the ByRef keyword in the example below would be optional, since the default method of passing arguments to subroutines or function is by reference. - How do I specify a conditional instruction (if ... then)?
The following program illustrates various general features of the Visual Basic (VB, and SVB) language including a conditional instruction. - How do I execute an expression in a loop?
Here is an example of a simple (For...Next) loop. The loop is used to fill array x with values between 1 and 10. - What are collections?
- I already know about Visual Basic; Does SVB support advanced language features?
- What are subroutines and functions?
Typically, complex applications written in Statistica (or any other) Visual Basic are structured. In other words, most programs will not consist of a single routine, but of many separate routines that will call each other. Every macro program (events, etc. are discussed in What are application events and how can they be controlled from Statistica Visual Basic?) consists of a Main program inside a Sub Main ... End Sub block. Inside the main program you can call subroutines and functions to perform repetitive tasks, or just to keep the structure of your program transparent. Here is an example program that consists of several subroutines and functions; note that the main program performs no computations, and only contains calls to the subroutines. - How do I assign a value to a variable?
Here are examples of simple declarations of variable types, and how to assign values to them: - Which data types are supported in SVB?
- Can I expand my SVB by calling external DLLs?
There are two ways in which you can access external libraries from Statistica Visual Basic. The first method is the easiest, but relies on the external DLL's compliance with Visual Basic standards. In other words, if the external DLL (program) supports Visual Basic (e.g., such as Microsoft Excel), you can select Tools - References from the Statistica Visual Basic toolbar to load the respective libraries. The objects, functions, methods, etc. in that library are now accessible like all Statistica Visual Basic functions. So you could, for example, create from within Statistica Visual Basic an Excel Spreadsheet, perform some spreadsheet operations and computations, and then transfer the results back to a Statistica Spreadsheet (e.g., via the .Copy and .Paste methods). - Can I define my own class modules and object modules?
Copyright © 2021. Cloud Software Group, Inc. All Rights Reserved.