Xbasic

Array initialize_properties Method

Syntax

V <array>.initialize_properties(C format,C data[,L append])

Arguments

formatCharacter

Defines the structure of the Data string and also defines the names of the array properties. The names of the array properties are separated by a delimiter (a non alphanumeric character or string, such as "|", "@", or "~~"). A property name may be followed by an optional type designation in the format Property_Name:Type_Designation. The default type is character. The following type designations are possible.

Format
Meaning
C

Character

N

Numeric

D

Date

L

Logical

B

Blob

F

Function

*

Supplied with the data element.

dataCharacter

A CR-LF delimited string of data values.

appendLogical

If .t., data will be appended to existing data in the array.

Description

Initialize property array subfields from a string of newline separated 'rows'.

Discussion

The <array>.initialize_properties() method loads field values from a data string into a property array. The format parameter defines the structure of the data parameter and also defines the names of the array properties. data is a CR-LF delimited string of data values. Each format element can be followed by an optional type.

For example, assume you supplied the following format string:

"Name + Age:N + Occupation"

Alpha Anywhere would create an array with three properties: name, age and occupation. It would look in the data string for values separated by the " + " separator. The Age property is Numeric.

For example, the following data string could be used with the above format string:

"Fred + 23 + Sales
Tom + 45 + Development
Joanne + 55 + President"

The optional type in the format string can also be '*' (in addition to 'C' 'N' 'D' 'L' 'B' and 'F' (for Function) ). If you use the '*' type, then it is assumed that the data that you are reading in is prefixed with the type (see example below). The array element is initialized with the type specified in the data that is being read in.

Example 

The following script initializes a property array:

Data = <<%string%
Stephanie + 23 + Sales
Joanne + 45 + Development
Rita + 55 + President
%string%
dim name[3] as P
name.initialize_properties("Name + Age:N + Position",data)

This creates the following array:

Element

Name

Age

Position

Name[1]

Stephanie

23

Sales

Name[1]

Joanne

45

Development

Name[1]

Rita

55

CEO

The following example shows the use of the '*' parameter in the format string.

dim p[3] as P
p[1].NAME = "name"
p[1].VALUE = "fred"
p[2].NAME = "age"
p[2].VALUE = 47
p[3].NAME = "dob"
p[3].VALUE = {12/18/52}

string = p.dump_properties("name::value:*")

? string
= name::Cfred
age::N47
dob::D12/18/1952
::

dim s[3] as P
s.initialize_properties("name::value:*",string)
? s[1].VALUE
= "fred"

? s[2].VALUE
= 47

? s[3].VALUE
= {12/18/1952}

? typeof(s[3].VALUE)
= "D"