FlexPro Forum – Discuss Your Topic!

Syntax Loop For

Home > Community > FPScript > Syntax Loop For

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #12374

    Hello,
    I’m new with FlexPro

    Dim A, B
    For j = 0 To 100 Step 0.01 Do
    A[j] = j
    End

    For i = 0 To 100 Step 0.01 Do
    If B < 0.1 then B[i]= 160 else B[i]= 124.6 + (2.77/i) End Signal ( B, A) [/code] I have an error and don't know what is it. What's wrong with my code. Thank you for your help.

    #12916
    Bernhard KantzBernhard Kantz
    Participant

    The syntax error is caused by the missing ‘End’ of the If-Then-Else statement. Correcting it reveals the deeper problems with the formula.
    After Dim A,B both variables are initialized with the datatype Empty. To build a dataset, one can append values at the end (or at the beginning). If one already knows the desired length and datatype, a proper initialization is more efficient. For a dataset of e.g. 100 floating point values (set to the void value) one can use an expression like

    Dim A = ? # 100

    After that, one can access the elements by indices like in your first loop. But be aware, they will be truncated to integers so A[0] will hold 0.99, A[1] 1.99, and so forth. If you need a dataset with 10001 entry from 0 to 100 and increment 0.01, you can append the values like in the following For-loop:

    
    Dim A
    For i = 0 To 100 Step 0.01 Do
    	A := i	// short for A = A : i, append value of i to dataset A
    End
    

    But there is already a FPScript function creating the same dataset with

    
    Series(0, 100, 0.01)
    

    Refering to your second For-loop the variable B has to be initialized first like A to access entries via the index operator. There maybe a typo: since B has no definite value it would make more sense to test if i is less than 0.1 than B. If you intent to build a dataset with 10001 entries, one may code as following:

    
    Dim i = Series(0, 100, 0.01)	// or reuse A
    
    // set all entries for the second case
    Dim B = 124.6 + 2.77 / i
    
    // find all indices where i is not greater or equal 0.1
    Dim idx = ValuesAboveLevel(i, 0.1, EVENT_INDEX + EVENT_COMPLEMENT)
    
    // set those values to the fixed value
    B[idx] = 160
    

    To get into FPScript formula writing, we would suggest to look into the Reference chapter in the section ‘Analyzing Data Mathematically’ in the online help.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.