How to use Strings in Statistica Visual Basic

Statistica Visual Basic supports the use of text values called strings. Strings can be used either directly or by using string variables. When strings are used directly, they need to be enclosed in double quotes. For example:

Call MsgBox("N Is <= 0",vbExclamation,"Warning")

String variables are designated by either adding a "$" character at the end of the variable name or declaring it as a string data type explicitly. For example:

Dim TextString As String
TextString = "N is <= 0"

or

Dim TextString$
TextString$ = "N is <= 0"

This string variable can then be used anywhere strings are expected. For example:

Call MsgBox(TextString$,vbExclamation,"Warning")

Many STATISTICA Visual Basic operations and functions are defined using strings. For example:

Concatenation. The following demonstrates how to join multiple strings into one string:

a$ = "Summary for current"
b$ = "month"

c$ = "quarter"

'TextString1$ becomes "Summary for current month".

'Note the space which was also added to the string.

TextString1$ = a$ + " " + b$

'TextString2$ becomes "Summary for current quarter"

TextString2$ = a$ + " " + c$

Comparisons. The following demonstrates how to compare two strings; the string that is of greater length will be displayed in a message box:

If TextString1$ > TextString2$ Then
MsgBox
(TextString1$)
Else

MsgBox
(TextString2$)
End If

Functions for manipulating variable names. The following demonstrates how to retrieve the current active data set (whether it be an individual window or in a workbook) and change its fifth variable name:

Dim s As Spreadsheet
Set
s = ActiveDataSet

s.VariableName(5) = "New Fifth Variable Name"

Functions which manipulate strings. The following examples demonstrate substring extraction, string insertion, and uppercase conversion functions for strings:

TargetString$ = Mid(SourceString$, 5, 7)

or

Mid(TargetString$, 5, 7) = SourceString$

Returns the substring of SourceString$ starting at the sixth index (note that array indexing begins at zero, unless Option Base 1 has been declared) for seven characters into TargetString$. It can also assign SourceString$ to the substring in TargetString$ starting at the sixth index for seven characters.

TargetString$ = UCase (SourceString$)

Returns a string from SourceString$ to TargetString$ where all the lowercase letters have been converted to uppercase.

String Constants. Specific string constants (which may not be changed once defined) can also be incorporated into your programs. The following demonstrates how to declare a string constant:

const CompanyName$ = "Dell"

See also, Passing Lists of Strings to Statistica Visual Basic Functions.