1. Starting Guide

<< Click to Display Table of Contents >>

Navigation:  1. Starting Guides >

1. Starting Guide

1.5.1.5. Organizing data items in blocks

Previous Top Next


Starting Guide

 

Organizing data items in blocks

How to use Blocks (sort of data arrays)

 

 

Normally a variable can hold just one item. For example:

 

VAR.$$TXA=Rainer

 

 

 

graphic

 

 

That is definitely ok for most uses. There are however situations when you want to store multiple items in the same variable, to handle them as one item.

 

For example, this is a set of three variables:

 

VAR.$$PRN=Rainer

VAR.$$LAS=Gottwald

VAR.$$JOB=Diver

 

Now we want to put all three items into one variable. We want to handle them like they are one thing, one block of data. What we do is,  we put them into a block (data-block).

Later we will see how we get them out there again.

 

First we tell the robot that we want to have data block. And that we have three items. And that we want to have the data-block in the variable $$BLOC. You can choose any variable name for a block variable.

 

' Tell the computer we want have a data-block for three items

CNB.$$BLO|3

 

Now we would go on and set the Block items, to values. We can use the SBE. or the SIB. command for that purpose. For example:

 

' Using SIB. we can set many block items in one strike

SIB.Element 01|Element 02|Element 03

 

graphic

 

 

' Using SBE. we are more flexible.

' The following will just set Element Nr.3

SBE.$$BLO|3|Element 03

 

Imagine you have Data that belongs together. For example, two names and a number.

 

Rainer Gottwald   3456

Anthon Robinson  3498

Oskar Schellbach  2467

 

Now how could we store them in variables and keep them together?

Of course you could store them in a delimited variable:

 

VAR.$$TXA=Rainer Gottwald 3456*Anthon Robinson 3498*Oskar Schellbach 2467

 

This way we would have them delimited with the asterisk-sign * and  we could get them easily out using the SBD. or the SBM. command. This is safe so long we are working with text.

 

If we have Binary data, that contains any of the 256 ASC-Characters this is not going to work. We can not use delimiters with Binary data. Thats where blocks enter the game.

Using blocks things are easy!

 

 

Lets first create a Block for each Name and number:

 

CNB.$$BLO|3

 

Then we set the values into this block

 

SIB.$$PRE|$$NAM|$$NUM

 

Now the complete name and address data is in one block, $$BLO. We can add $$BLO to another block, just as we can add any variable to a block.

 

Blocks can be large, 10000 Elements per block is no problem possible.If blocks get larger, you may need too much time to change or retrieve single elements. After all it depends on your hardware, and on the size of the single elements.

 

' We create our two blockvariables

CNB.$$ADR|3

CNB.$$MAI|1

VAR.$$ITE=1

VAR.$$PRE=Rainer

VAR.$$NAM=Gott

VAR.$$NUM=3456

GSB.block

VAR.$$PRE=Anthon

VAR.$$NAM=Rob

VAR.$$NUM=3498

GSB.block

 

MBX.Ready

END.

 

:block

' Tell which block we want to fill

SBE.$$ADR

' Use the easy way to fill all elements in

SIB.$$ADR|$$PRE|$$NAM|$$NUM

' Now we fill the whole BLock into another one

SBE.$$MAI|$$ITE|$$ADR

VIC.$$ITE

RET.

 

What you can also see is, that we have "dimensioned" the Main Block $$MAI with only one element at start.

 

How do we extend a data-block?

 

Later we added a second element using SBE. Because we have added more items then the data block was dimensioned at this time, we have "extended" the data-block.

Internally the data-block is going to be resized to the new size.

 

You can extend the element number of a block at any time by just adding the element using SBE. Extending a data-block will also work with SIB. Here is an example where SIB. extends a data-block to 3 items.:

 

CNB.$$BLO|1

SIB.Hallo|Thomas|Lange

GBN.$$BLO|$$RES

'GBE.$$BLO|3|$$E01

DBP.Blo hat $$RES Elemente

GFB.$$E01|$$E02|$$E03

DBP.$$E01- $$E02 - $$E03

MBX.Blo hat $$RES Elemente

ENR.

 

Blocks are internally checked for authenticity. This is done to prevent hard to track errors.

If you change bytes or the length of a block variable externally, the block may not be unpacked anymore.

 

Data blocks can contain all 256 ASC Characters (even binary files) and are binary-compatible. Therefore whether special folders nor system variables are resolved inside blocks. Variables are resolved one time.

 

There is no explicit limit on data-items per block. However timing considerations may set you  a limit at around 10000 Items, depending on your available hardware. For a larger number of non-binary items, Member-Operations, using SBD. FEM. and SBM. may be significantly faster.

 

There is no Limit, on Data-Block nesting. You can put a data-block into another data-block and so on. The only limit is the overall variable size. And this depends on the amount of Memory in the computer, as well as the actual memory fragmentation.

On a strong system, data-blocks can easily reach a size of several hundreds of Megabyte.

 

 

 

See also:

 

    1.5.1.3. Using Variables

    CNB. - Create New Block

    GBN. - Get Block Number

    GBE. - Get Block Element

    SBE. - Set Block Element

    SIB. - Set-In-Block

    GFB. - Get-From-Block