FlexPro
HistoryBase
Engineering
Training
Downloads
FlexPro Support
Knowledge
Community
About us
References
Jobs
General Contact
List Of Retailers
FlexPro Support
EN
DE
FR
Placeholder
Products and Solutions
Support and Downloads
Company
Magazine
Contact Us
Language
MyWeisang

Account settings

Topic

Syntax Loop For

Home page Community FPScript Syntax Loop For

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #33628
    kamil ABDOUL MADJID
    Participant

    Hello,
    I’m new with FlexPro
    [code]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[i] < 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.

    #33629
    Bernhard 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
    [code]Dim A = ? # 100[/code]
    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:
    [code]
    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
    [/code]
    But there is already a FPScript function creating the same dataset with
    [code]
    Series(0, 100, 0.01)
    [/code]

    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[i]. If you intent to build a dataset with 10001 entries, one may code as following:
    [code]
    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
    [/code]

    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.