sx_GetVariant

<< Click to Display Table of Contents >>

Navigation:  Apollo API Listing >

sx_GetVariant

VB Declaration

Declare Function sx_GetVariant Lib "Apollo9.dll"

(ByVal cpFieldName As String)

As String

C Declaration

Description

Convert any data type to a string and store in a pre-dimensioned Visual Basic variant.

This function allows Visual Basic programmers to extract the contents of any field without worrying about the data type. As long as the variable receiving the return value has been explicitly declared as a Variant, Visual Basic will automatically convert the returned string into the data type you require.

Some typed sx_Get functions are still necessary. sx_GetVariant will not return the same results as the following functions:

sx_GetByte

sx_GetDateJulian

sx_GetMemo (with print formatting)

sx_GetRecord

sx_GetTrimString

 

Parameters

cpFieldName: The name of the field optionally qualified with an alias.

 

Return Value

Character fields are returned as untrimmed strings. If trimmed strings are required, use sx_GetTrimString.

Date fields are returned as strings formatted according to the settings of sx_SetDateFormat and sx_SetCentury.

Logical fields are returned as strings with "0" representing FALSE and "-1" representing TRUE.

Numeric fields are returned as left trimmed strings.

Memo fields are returned as un-formatted strings. If line formatting characters are required for printing, use sx_GetMemo instead.

Visual Basic will automatically convert strings representing numbers into the appropriate data type (integer, long integer, or double) depending upon the usage context.

Type Conflicts

This function must not be used as direct input to any other function (e.g., sx_PutVariant) without using the CVar Visual Basic function to explicitly cast the return type as a variant. For example, the following is illegal:

sx_PutVariant "master->name", sx_GetVariant("batch->name")

sx_GetVariant returns a string and not a variant. If its return value is equated to an explicitly dimensioned variant, that return value becomes a variant. In the code fragment above, we are attempting to replace a variant with a string, and this is illegal. The code may easily be repaired with

sx_PutVariant "master->name", CVar(sx_GetVariant("batch->name"))

VB Example

Dim gTotal As Double

' calculate total balance

gTotal = 0

sx_GoTop

Do While Not sx_Eof()

gTotal = gTotal + CVar(sx_GetVariant("balance"))

sx_Skip 1

Loop

gTotalBox.Text = gTotal

C Example

See Also

sx_PutVariant