Seperate string and setrange

klum
klum Member Posts: 102
Hi All,

I would like to seperate string and setrange to record for find record and sum up amount and change status.

1. I put the no. in text box "Card No."(code20) - 0001,0002,0003,0004
2. I want to seperate each No. by (,) for setrange with VoucherReg Table

At Textbox "Card No."-Onvalidate
//Sum up amount for each voucher
IF SaleHeaderRec2."Payment Method Code" <> '' THEN BEGIN
  VoucherReg.RESET;
  VoucherReg.SETRANGE(Type,VoucherReg.Type::Voucher);
  [b]VoucherReg.SETRANGE("Voucher No.","Card No.");[/b]
  IF VoucherReg.FIND('-') THEN BEGIN
    IF VoucherReg.Status = VoucherReg.Status::Sold THEN BEGIN
      REPEAT
        VoucherAmt += VoucherReg."Amount LCY";
      UNTIL VoucherReg.NEXT = 0;
      ReceiveTmp := VoucherAmt;
    END ELSE
      ERROR('This voucher has status:%1',VoucherReg.Status,FALSE);
  END ELSE
    ERROR('This voucher could not be found',FALSE);
END;

](*,)
I don't know how to cut each No. to setrange with "VoucherReg.SETRANGE("Voucher No.","Card No.")"

If somebody know please guide me with the code ....(I search about SelectStr already but I tell you guys the truth I don't understand much)

Thank in advance
Wanvisa

Answers

  • Albertvh
    Albertvh Member Posts: 516
    Hi Klum

    You could use
    "Card No." := CONVERTSTR("Card No.",',','|');
    CoucherReg.SETFILTER("Voucher No.",'%1',"Card No.");
    
    


    Hope this helps
  • Waldo
    Waldo Member Posts: 3,412
    Well, you should use the SELECTSTR-statement for this, imho.

    E.g.
    commastring := '012,345,567,889,345';
    SELECT(4,commastring)

    This will give you '889', being the 4th part in your string.

    To know how many times you have to loop through your string, you can count the comma's (+1).
    strCommas := DELCHR(String,"=",DELCHR(String,'=',','));
    intNumberOfLoops := STRLEN(strCommas ) + 1;

    Then you can fill a temp table.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • klum
    klum Member Posts: 102
    Hi,

    Thank for your help Albertvh but It's not work for me :cry: so I have to try that difficult for me from Waldo....And one question now ...How to fill a temp table please guide me with some code. :oops:

    Thank a lot for your help guys O:)
    Wanvisa
  • lubost
    lubost Member Posts: 633
    Working with temporary table is the same as with "normal" table. The only difference is that you must set the the Temporary property in record variable definition.
  • Waldo
    Waldo Member Posts: 3,412
    Indeed,

    and you can first fill that table (if you put Temporary=yes, the table is empty), en then filter and get data from the table...

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • Mbad
    Mbad Member Posts: 344
    Well not entirely. You can only transfer the temp table by using var, and it has a bigger scope than normal tables.
  • klum
    klum Member Posts: 102
    Thanks for every reply and Happy Chinese New Year :)


    Now I understand more about String Function because of try and test.....and I also will try to understand about temporary table.


    Best Regards,
    Wanvisa
  • klum
    klum Member Posts: 102
    I have question about something I tested from example that someone posted here...

    From Example : I've got the error "Type conversion is not possible.....Integer := Text"
    Hyphon := STRPOS(COPYSTR(CardStr,'-',1,commaSep));
    
    I dont' understand that what does mean about '-' and I try from online help STRPOS and COPYSTR function

    My example code : (my code doesn't have '-' because i've got same error)
    CardStr := "Card No.";  //Key : 01,0001
    CommaSep := STRPOS(CardStr,',');   //Result : 3
    NewStr := DELCHR(COPYSTR(CardStr,1,CommaSep),'=',',');  //Result : 01
    

    My question is I would like to know about '-' use for what? it should have or should not? (Or if have i will got same error for sure lol)
    If I have code like this :
    NewStr := DELCHR(COPYSTR(CardStr,'-',1,CommaSep),'=',',');  
    

    Thanks in advance
    Wanvisa :)
  • Waldo
    Waldo Member Posts: 3,412
    Don't know if I understand the question exactly, but I can tell you this:
    In the first statement, the COPYSTR is wrong.

    These are the syntaxes of the two statements:
    NewString := COPYSTR(String, Position [, Length])
    Position := STRPOS(String, SubString)

    So when you try the statement:
    Hyphon := STRPOS(COPYSTR(CardStr,'-',1,commaSep));
    you put a '-' on the posistion where C/SIDE expects an integer.
    That's wy it gives the error "Type conversion is not possible.....Integer := Text"

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • klum
    klum Member Posts: 102
    Hi Waldo :),

    Thanks a lot for your clearly suggestion. In the first statement I just try to follow example about string funtion from this :

    http://www.mibuso.com/forum/viewtopic.p ... ing+string

    Then I struck with this statement : Hyphon := STRPOS(COPYSTR(CardStr,'-',1,commaSep));

    But now I understand already ...thanks again.

    Best Regards,
    Wanvisa :)
  • Waldo
    Waldo Member Posts: 3,412
    David said it was an untested sample, so you can't blame him :wink:

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • klum
    klum Member Posts: 102
    Hi Waldo :),

    Who will dare to do that. lol But now it's my good news I can find solution for myself about my question already. It's not nice code but it's work very well for me :wink: It might usefull for somebody(I hope so)
    CardStr := "Card No.";
    CommaSep := STRPOS(CardStr,',');
    strCommas := DELCHR(CardStr,'=',DELCHR(CardStr,'=',','));
    intNumberOfLoops := STRLEN(strCommas ) + 1;
    FOR i := 1 TO intNumberOfLoops DO BEGIN
      VoucherNo := DELCHR(COPYSTR(CardStr,1,CommaSep),'=',',');
      LenStr := STRLEN(VoucherNo)+1;
      VoucherReg.RESET;
      VoucherReg.SETRANGE("Voucher No.",VoucherNo);
      IF VoucherReg.FIND('-') THEN BEGIN
        VoucherReg."Vouchers Payment" := TRUE;
        VoucherReg.MODIFY;
      END;
      CardStr := DELSTR(CardStr,1,LenStr);
    END;
    
    IF "Card No." <> '' THEN BEGIN
      VoucherReg.RESET;
      VoucherReg.SETRANGE(Type,VoucherReg.Type::Voucher);
      VoucherReg.SETRANGE("Vouchers Payment",TRUE);
      IF VoucherReg.FIND('-') THEN BEGIN
        IF VoucherReg.Status = VoucherReg.Status::Sold THEN
          REPEAT
            VoucherAmt += VoucherReg."Amount LCY";
          UNTIL VoucherReg.NEXT = 0;
          ReceiveTmp := VoucherAmt;
          CurrForm.RecieveField.UPDATE;
      END;
    END;
    

    :whistle: I can sum it up ..... :sick: Oop!! but i have a difficult task waiting for me about connection to ADO (now back to feel like a donkey again lol but be a donkey in shrek)

    Thank a lot for every help .....very usefull for me [-o<

    Best Regards,
    Wanvisa
  • Waldo
    Waldo Member Posts: 3,412
    klum wrote:
    Hi Waldo :),

    Who will dare to do that. lol But now it's my good news I can find solution for myself about my question already. It's not nice code but it's work very well for me :wink: It might usefull for somebody(I hope so)
    CardStr := "Card No.";
    CommaSep := STRPOS(CardStr,',');
    strCommas := DELCHR(CardStr,'=',DELCHR(CardStr,'=',','));
    intNumberOfLoops := STRLEN(strCommas ) + 1;
    FOR i := 1 TO intNumberOfLoops DO BEGIN
      VoucherNo := DELCHR(COPYSTR(CardStr,1,CommaSep),'=',',');
      LenStr := STRLEN(VoucherNo)+1;
      VoucherReg.RESET;
      VoucherReg.SETRANGE("Voucher No.",VoucherNo);
      IF VoucherReg.FIND('-') THEN BEGIN
        VoucherReg."Vouchers Payment" := TRUE;
        VoucherReg.MODIFY;
      END;
      CardStr := DELSTR(CardStr,1,LenStr);
    END;
    
    IF "Card No." <> '' THEN BEGIN
      VoucherReg.RESET;
      VoucherReg.SETRANGE(Type,VoucherReg.Type::Voucher);
      VoucherReg.SETRANGE("Vouchers Payment",TRUE);
      IF VoucherReg.FIND('-') THEN BEGIN
        IF VoucherReg.Status = VoucherReg.Status::Sold THEN
          REPEAT
            VoucherAmt += VoucherReg."Amount LCY";
          UNTIL VoucherReg.NEXT = 0;
          ReceiveTmp := VoucherAmt;
          CurrForm.RecieveField.UPDATE;
      END;
    END;
    

    :whistle: I can sum it up ..... :sick: Oop!! but i have a difficult task waiting for me about connection to ADO (now back to feel like a donkey again lol but be a donkey in shrek)

    Thank a lot for every help .....very usefull for me [-o<

    Best Regards,
    Wanvisa

    Thank you for sharing your solution.
    I think you could have simplified the first part with the SELECSTR-statement ... but if it works for you ...

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog