Variables and constants

Table 169. 

Variable scope


Global, local and instance



Variable declaration syntax


datatype { { size } } { { precision } } 
          variablename { = value } 
          {, variablename2 { = value2 } }

The datatype can be any standard type and system object type.

Declaring multiple variables of the same type at one time is supported.

For example:

integer li_a=5, li_b=10

Naming variables with Non-English characters or numbers.


When a global decimal variable is declared, or a decimal constant is used to declare a variable, the specification of precision for the global decimal or the decimal constant will be ignored.

A variable having the same name as a global variable is or a global function is unsupported.

A global variable cannot have the same name as a control in a window. For example, if there is a GroupBox control named as gb_1, the following syntax is unsupported:

Global Boolean gb_1

Placing a cursor or stored procedure declaration in the declaration of instance variables is unsupported.

Global scope operator (::)


Referring to a global variable by using the global scope operator (::) before the variable name is unsupported; (i.e. The syntax with "::globalname" is unsupported).

Constant type


All of the standard data types

Constant declaration syntax


CONSTANT datatype constname = value

The constant can only be public.

It is supported if the value is an expression.

For example:

constant date ld_date = today()

Access to Instance Variables


When the instance variable is passed by reference to a script and before the execution of this script is finished, if the value of this instance variable is changed, Appeon cannot capture the changes.

When the instance variable is defined in a custom class, it cannot be accessed directly using the class dot notation, for example, the following script will not work on mobile: mle_Result.Text = n_cst_test.COMPANYNAME, n_cst_test is the name of the custom class and COMPANYNAME is its instance variable. But you can work it around by creating an object first and then using the object to access the instance variable.

Initial values of variables and constants


When a variable or constant is declared, a default initial value is automatically assigned or an initial value can be specified in the declaration.

The initial values of enumerated data types are converted to null in JavaScript. Except for the initial values of enumerated data types and the Any data type, the default initial values in PowerScript are supported.


There are different rules in PowerBuilder than in JavaScript if specifying an expression as an initial value:

It is unsupported to use the instance constants of a non-instantiated object.

With the syntax datatype variable = expression, in PowerBuilder, the expression's value is assigned to the variable when the script is compiled (not during execution). In JavaScript, the expression's value is set to the variable during execution. For example, if the declaration is the following:

date d_date = Today( )

The value of d_date is the date when the script is compiled in PowerBuilder, and it is the date when the application is running in JavaScript.

Therefore, making the declaration of a variable and assigning it with the initial value in separate PowerScript statements is recommended.

For example:

date d_date
d_date = Today( )


Declaration syntax
  • The declaration syntax for arrays is supported:

    { access } datatype variablename { d1, ..., dn } { = { valuelist } }
  • The access is always PUBLIC.

  • The datatype cannot be an unsupported data type (refer to the data type section). For decimals, you can specify the precision of the data by including an optional value in brackets after the datatype. For example,

    decimal {2} ld_prices[ ]
  • Both variable-size arrays and fixed-size arrays are supported.

    date ld_birthdays[ ]
    string ls_array[10 ]
  • Arrays with specified lower bound and upper bound are supported, even if the lower bound is a non-integer or a negative value. If the lower bound is not an integer, it will be rounded off.

    string ls_name[-10 to 15]
  • Both single-dimensional and multi-dimensional arrays are supported.

    integer ls_array[10]
    integer li_score[2,3]
  • Using TO to change array index values is supported.

    integer li_staff[100, 0 to 20, - 3 to 5]
  • Multiple arrays of the same type can be declared simultaneously.

    string ls_array1[10], ls_array2[5], ls_array3[100]
  • Assigning an array to an array is unsupported if the array elements of Any data type. For example,

    any la_1[3], la_2[4]
    la_1[1] = la_2[4] // Unsupported
Initialization and assignment


  • Each element of an array can be initialized to the same default value as its underlying data type. The default value for string data type elements is ""; the default value for numeric data type element is 0.

  • The default length of variable-size arrays is 0, which means that the array does not have any elements. Initializing several elements of variable-size array is supported if the element after the several elements is assigned with a value.


    integer li_array []
    li_array[8]=8 //The values of li_array[1], ? li_array[7] are 
    initialized to the default value 0
  • Using arraylists to assign values to an array, or assign values to array elements separately, is supported. There can be expression(s) in the arraylist. The result will be the same as in PowerBuilder.

    li_array[10] = {1,2,3,4,5}
    li_array[3,2] = {1,2,3,4,5}
    ld_date = {today(),relativedate(today(),1), 2002-12-31}
  • Assigning one array to the another is supported. The result will be the same as in PowerBuilder.

    • Assigning a variable-size array to another variable-size array.


      integer li_test1[]={1,2,3,4,5}
      integer li_test2[] ={10,20,21,22,23,24,25,26,27}

      If the array type is NVO, the assignment operation does not trigger the Constructor event.

    • Assigning a fixed-size array to another fixed-size array. It can be between one-dimensional arrays, or between one-dimensional array and a multi-dimensional array, or between multi-dimensional arrays.


      integer li_test0[10] ={21,22,23,24,25,26,27,28}
      integer li_test1[5]={1,2,3,4,5}
      integer li_test2[2,6] = {11,12,13,14,15,16,17,18}
      integer li_test3[2,3,5] = {11,12,13,14,15,16,17,18}
      li_test1=li_test0 //assign a one-dimensional array to 
      another one-dimensional array
      li_test2=li_test1 //assign a one-dimensional array to 
      a multi-dimensional array
      li_test1=li_test2 //assign a two-dimensional array to 
      a one-dimensional array
      li_test3=li_test2 //assign a multi-dimensional array to 
      another multi-dimensional array
    • Assigning a variable-size array to a fixed-size array.


      integer li_test0[] ={21,22,23,24,25,26,27,28}
      integer li_test1[10]={1,2,3,4,5}
    • Assigning a fixed-size array to a variable-size array.


      integer li_test1[10]={1,2,3,4,5}
      integer li_test0[]
      li_test0[30] = 100
      li_test0=li_test1 //the element number of the li_test0 will be 10
  • Reinitializing arrays with the following steps is supported:

    1. Declare a dummy array of the same type (never put any values into the array).

    2. Simply set originalarray = dummyarray.

    This will clear out the original array and cause UpperBound to return the correct value. The same rule applies to PowerBuilder.

  • The index of an array can be an expression.


    for A = 1 to upperbound(ls_array)
    ls_array[A,1] = ......
    end for
    ls_array[integer(] =123


  • Assigning values between instance variables of structure type is unsupported. For example, the following lines of code are unsupported:

    Str_a L1
    Str_b L2
    L1 = L2
  • Assigning structure arrays to non-structure arrays is unsupported. For example, the following lines of codes are unsupported:

    str_dwstruct lst_dwstr[]
    powerobject po_ary[]
    po_ary = lst_dwstr // Unsupported
Passing arrays as arguments

Passing a variable-size or fixed-size array as an argument is supported. For example:

uf_convertarray(a) //integer a[]
uf_convertarray(a) //integer a[10]

Passing array elements as arguments by reference is unsupported; only the first element is passed and used as the value for all other elements. For example, the following code is unsupported:

lnv_bug.of_test( ls_var1, ls_var2, ls_ref[1], ls_ref[2], ls_ref[3], ls_ref[4], ls_ref[5], 
ls_ref[6], ls_ref[7], ls_ref[8], ls_ref[9], ls_ref[10])

The following two syntaxes will get the same result for one-dimensional, multi-dimensional, or variable-size arrays:

li_upper = upperbound(ls_array)            // string 
li_upper = upperbound(ls_array [])         // string 
Complex arrays
  • Structure arrays are supported. The declaration, initialization and assignment of structure arrays comply with the general rules for standard arrays.

  • UserObject arrays are supported. Please refer to the User Object section for details.

  • Nested arrays are supported.

  • Enumerated type arrays are supported.


If arguments of a function are arrays, arguments and corresponding actual parameters cannot be of different dimensions.

External functions


  • Declaring and calling local external functions

  • Declaring and calling global external functions

  • Data types of external function arguments can be the following:

    Array, Boolean, Blob, Char, Date, DateTime, Double, Decimal, Integer, Long, Real, String, Structure, and Void

  • Data types of external function return values can be the following:

    Array, Boolean, Blob, Char, Date, DateTime, Double, Decimal, Integer, Long, Real, String, Structure, Unsigned Integer, Unsigned Long, and Void


  • Access levels (including Public, Protected, & Private) for local external functions are unsupported.