4D v14.3

Using the element zero of an array

Home

 
4D v14.3
Using the element zero of an array

Using the element zero of an array  


 

 

An array always has an element zero. While element zero is not shown when an array supports a form object, there is no restriction(*) in using it with the language.

One example of the use of element zero is the case of the combo box discussed in the section Arrays and Form Objects.

Here is another example: you want to execute an action only when you click on an element other than the previously selected element. To do this, you must keep track of each selected element. One way to do this is to use a process variable in which you maintain the element number of the selected element. Another way is to use the element zero of the array:

  ` atNames scrollable area object method
 Case of
    :(Form event=On Load)
  ` Initialize the array (as shown further above)
       ARRAY TEXT(atNames;5)
  ` ...
  ` Initialize the element zero with the number
  ` of the current selected element in its string form
  ` Here you start with no selected element
       atNames{0}:="0"
 
    :(Form event=On Unload)
  ` We no longer need the array
       CLEAR VARIABLE(atNames)
 
    :(Form event=On Clicked)
       If(atNames#0)
          If(atNames#Num(atNames{0}))
             vtInfo:="You clicked on: "+atNames{atNames}+" and it was not selected before."
             atNames{0}:=String(atNames)
          End if
       End if
    :(Form event=On Double Clicked)
       If(atNames#0)
          ALERT("You double clicked on: "+atNames{atNames}
       End if
 End case
 
(*) However, there is one exception: in an array type List Box, the zero element is used internally to store the previous value of an element being edited, so it is not possible to use it in this particular context.

 
PROPERTIES 

Product: 4D
Theme: Arrays

 
SEE ALSO 

Arrays

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)

Inherited from : Using the element zero of an array ( 4D v11 SQL Release 6)