How to use the array?

asked Jan 7 in GUI Development by Tonny

Hello Paul,

     I have seen this document( i still don't understand.

1.How to output the array data?

I define the array is float type.How to modify the code to let trace output array data ?


2.If i want to use array with HorizontalSlider,How these values should be overwritten ?

for example the WaveformGenerator,if  StepSize is irregular ,but a lot of data.Now,I defined a array.How I need to change HorizontalSlider is the data I need ?



Best regards,




1 Answer

0 votes
answered Jan 8 by Paul Banach

Hello Tonny,

regarding the first question: the error code indicates a type mismatch with the '+' operator. When you double click on the message, the corresponding location will be shown in the Code Editor. I suppose your array is declared with float as data type. With the + operator you intend to add an integer 1 to it. Chora consideres such combinations are problematic because they may result in two different values. To avoid such situations, Chora reports this as an error. In fact, compared with C, Java, etc. Chora is much more stricter.

To disable the error message and to satisfy the Chora compiler, you have to ensure that the operands are of the matching type. In your case try to change the integer 1 to float 1.0 (with the .0). Also what I see from the screenshot is that the effect of the for-loop is limited to the line number 6 only. If you want all values from the array to be displayed you need to enclose the lines belonging to the for-loop within a block - exactly as you do in C, Java, etc. Try following:

var int32 inx;
var float caption;

for ( inx = 0; inx < Application::Device.numbers.size; inx = inx + 1 )
  Application::Device.numbers[inx] = Application::Device.numbers[inx] + 1.0;
  trace "Execute data()", caption; 

Regarding your second question: I do not really understand your application case. I suppose, you want the slider to change a value within the array, right? In such case:

Step 1: Within the component where you have the slider add a slot method.

Step 2: Connect the slot method to the property OnChange of the slider.

Step 3: Implement the slot method as demonstrated below:

// Change the value in the array element #0
numbers[0] = Slider.CurrentValue;

I hope it helps you further.

Best regards

Paul Banach

commented Jan 8 by Tonny

Hello Paul

       Thanks for your help,The first problem has been solved .

       For the second question, What I'm trying to say is,For the example of WaveformGenerate.

We can use the HorizontalSlider to control the change of the Text value .

However,the Text value  is the result of the (minimum and maximum values and StepSize)on HorizontalSlider .  My question is :

If the Text value is  erratic,(for example:1.1 ,1.2 ,1.3 ,1.4 ,2 ,2.5 ,3 ,3.8...I set this data to an array.)

Now,How can I display this array data in text value through the HorizontalSlider?

Best regards,


commented Jan 8 by Paul Banach

Hello Tonny,

ok understood. In such case you can prepare an array with all the values and then use the Slider's CurrentValue to select within the array. For this purpose:

Step 1: Add a new array to your GUI component.

Step 2: Configure the capacity and the data type of the array (e.g. to 8 items and float as data type)

Step 3: Initialize the array entries with the values (e.g. 1.1, 1.2, ...). The following figure demonstrates the resulting situation:

Step 4: Configure the Slider properties MinValue to 0 and MaxValue to the number of array entries - 1. In our case with 8 entries you configure MaxValue to 7.

Step 5: Within the slot method connected to Slider's OnChange property select the right array entry:

var float theValue = numbers[ Slider.CurrentValue ];

trace theValue;

So far the implementation with an array. Depending on the series of numbers you can achieve the same results by other options:

Option 1: If possible, implement a mathematical function f(x) where x is the integer value of the Slider in range between MinValue and MaxValue. Based on this parameter the function could calculates the resulting number e.g. 3.8.

Option 2: If the series of numbers do not follow any mathematical function you can use if-condition and switch-case statement to map the values. For example:

var int32 x      = Slider.CurrentValue;
var float number = 0.0;

if      ( x <= 3 ) number = 1.1 + ( float( x ) * 0.1 );
else if ( x <= 6 ) number = 2.0 + ( float( x - 4 ) * 0.5 );
else if ( x == 7 ) number = 3.8;

Does it help you?

Best regards

Paul Banach

commented Jan 8 by Paul Banach

Other aspect I forget to address is how to display the once obtained value in a Text view. For this purpose you convert the number in a string and assign the result to the property String of the affected Text view.To convert the number in a string you use the string() constructors. There you can specify the desired format of the resulting string, e.g. the number of digits after the period sign, etc.:

var float number = ...

// Format the string with one digit precision
TextView.String = string( number, 0, 1 );


commented Jan 9 by Tonny

Hello Paul,

     Thanks for your help,I've solved it .In addition: In this document.


Can int32 be used as a type? I want to calculate the array .Like language C.

Maybe i need defined two arrays?

Can i calculate it this way ?


Best regards,



commented Jan 9 by Paul Banach

Hello Tonny,

the C-like initialization of arrays is not possible. In case of arrays belonging to an object you initialize it in the Inspector window as demonstrated in  one of my preceding comments. In case of local arrays, the array has to be declared by using the array keyword and the items of the local array need to be initialized individually as shown in the example below. The [ 1, 2, 3 ... ] notation is not supported.

array float numbers[8];

number[0] = 1.1;
number[1] = 1.2;
number[2] = 1.4;

Regarding the calculation with arrays, you can implement a loop and iterate through the arrays. Please don't forget to enclose the lines below the for-loop within a block. See my original answer addressing this aspect.

Best regards

Paul Banach

commented Jan 10 by Tonny

Hello Paul,

    Thanks for you help very much,this array problem has been  solved !!

   And there are a few more questions :What you mentioned above 

var float theValue = Application::Device.PEQ_Q[ HorizontalSliderQ.CurrentValue ];

trace theValue;


var float number = ...

// Format the string with one digit precision
TextView.String = string( number, 0, 1 );

The question:  the var float number = ?(Application::Device.PEQ_Q? or One number ? or the Value? )

Can make slider slider change and display the number .

Best regards,


Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint