Skip to Content

How to get element from Array

Hello...

I have this string where is parsing mark ' | '

F1E|I21|R|4|30|50|180|35|BG340SR|S10|D11|T10|1P|PVC|PZS-Z25|HS|/|F11|R20|K7035|T7035|/|SNAL|/,|/,/|TOB,S|H,2|/|VZKT|VZKT|SD|

this string elements I need to insert into Array, so I created Formula:

Global StringVar Array myString;
Redim myString [32];
myString:= Split({Command.Parameter},'|');

but now I do not know how can I get n-element/index from the Array

Thank You for any hint

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Sep 27, 2017 at 11:13 AM

    Try

    WhilePrintingRecords ;
    Shared NumberVar Qty := Sum({Command.Quantity},{Command.Parameter});
    Global StringVar Array myString;
    Redim myString [32];
    myString:= Split({Command.Parameter},'|');
    If UBound(myString)>=4
    Then Tonumber(myString[4]) * Qty
    
    Or
    WhilePrintingRecords ;
    Shared NumberVar Qty := Sum({Command.Quantity},{Command.Parameter});
    Global StringVar Array myString;
    Redim myString [32];
    myString:= Split({Command.Parameter},'|');
    Global Numbervar Amt:=0;
    If UBound(myString)>=4
    Then Amt:= Tonumber(myString[4]);
    
    Amt* Qty
    
    
    
    Add comment
    10|10000 characters needed characters exceeded

    • SUPER!

      Thank You Master, both works perfectly!

      how it will be in case when the element will not be Number, but string?

      in such case will not be possible use UBound

      Regards ZAJDAN

  • Sep 27, 2017 at 09:23 AM

    Global StringVar Array myString;

    myString[n];

    Ian

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 27, 2017 at 10:06 AM

    I also tried this:

    If UBound(myString)>=4 
    Then myString[4] 
    

    it returns correct value/element, but I need somehow pass the value into variable for next use (multiplication)

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 27, 2017 at 11:45 AM

    how it will be in case when the element will not be Number, but string?

    in such case will not be possible use UBound

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 27, 2017 at 10:32 AM

    Just use it as you have

    If UBound(myString)>=4
    
    Then myString[4] * yourfield or formula
    Ian
    Add comment
    10|10000 characters needed characters exceeded

    • This I already tried:

      WhilePrintingRecords ;
      Shared NumberVar Qty := Sum({Command.Quantity},{Command.Parameter});
      Global StringVar Array myString;
      Redim myString [32];
      myString:= Split({Command.Parameter},'|');
      If UBound(myString)>=4
      Then myString[4] * Qty

      but it returns:

      'A number, or currency amount is required here.'

      strange, because UBound returns Number and also the variable Qty is datatype Number.