Results 1 to 5 of 5

Thread: Out of string range.

  1. #1
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default Out of string range.

    Just me trying to create another function.
    Code:
    [Runtime Error] : Out of string range in line 16 in script D:\Program Files\SCAR\3.20d\SCAR 3.20d\Scripts\My Scripts\Functions\TrimMulti.scar
    SCAR Code:
    function DeleteMulti(Text : string; FromX, ToX : TIntegerArray) : string;
    var
      I, D, C, E : Integer;
      S : string;
     
    begin
      S:= Text
      for I:= 0 to High(FromX) do
      begin
        if I <> 0 then
          begin
            FromX[I]:= C;
            ToX[I]:= E;
            if (Pos(Text[C], S) > Pos(Text[C - 1], S)) then  //Line 16
              D:= D + (Pos(Text[C - 1], S) - Pos(Text[E - 1], S));
          end;
        Delete(Text, FromX[I - D], ToX[I - D]);
      end;
      Result:= Text;
    end;

    As an example, this is how it's meant to be used:
    Code:
    WriteLn(DeleteMulti('Hello everyone!', [1, 7], [3, 9]));
    The idea is that it will delete character 1 to 3, and 7 to 9, but I get the above error.

    Thanks,
    Richard
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  2. #2
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by R1ch View Post
    Just me trying to create another function.
    Code:
    [Runtime Error] : Out of string range in line 16 in script D:\Program Files\SCAR\3.20d\SCAR 3.20d\Scripts\My Scripts\Functions\TrimMulti.scar
    SCAR Code:
    function DeleteMulti(Text : string; FromX, ToX : TIntegerArray) : string;
    var
      I, D, C, E : Integer;
      S : string;
     
    begin
      S:= Text
      for I:= 0 to High(FromX) do
      begin
        if I <> 0 then
          begin
            FromX[I]:= C;
            ToX[I]:= E;
            if (Pos(Text[C], S) > Pos(Text[C - 1], S)) then  //Line 16
              D:= D + (Pos(Text[C - 1], S) - Pos(Text[E - 1], S));
          end;
        Delete(Text, FromX[I - D], ToX[I - D]);
      end;
      Result:= Text;
    end;

    As an example, this is how it's meant to be used:
    Code:
    WriteLn(DeleteMulti('Hello everyone!', [1, 7], [3, 9]));
    The idea is that it will delete character 1 to 3, and 7 to 9, but I get the above error.

    Thanks,
    Richard
    You set FromX[I]:= C;, then you call 'C-1', that's all fine except that strings don't start from the index of 0.

    Strings start from the index of '1', for example the text you have is: Hello, calling text[0] will give you an out of range error. you need to call Text[1] which will give you 'H'

    EDIT: I think you're trying to do something easy too complicated. Is this what, roughly, you want?

    SCAR Code:
    Function DeleteMulti(Text : String; F, T : TIntegerArray) : String;
    Var C : Integer;
    Begin
      Try
        For C := 0 To High(F) Do
        Delete(Text, F[C], T[C]);

        Result := Text;
      Except End;
    End;
    Last edited by Naum; 08-30-2009 at 01:54 AM.

  3. #3
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Sorry to be a pain, but would you mind sorting it out for me? I just can't get it working for some reason.

    Richard.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  4. #4
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    You've got:
    SCAR Code:
    FromX[i]:= C;
            ToX[i]:= E;

    You want:
    SCAR Code:
    C := FromX[I];
            E := ToX[I];

    That solves your out of string range error.

    But you also need to put the Delete(...); line inside the if (I <> 0) then begin, end loop.

    So....:

    SCAR Code:
    function DeleteMulti(Text : string; FromX, ToX : TIntegerArray) : string;
    var
      I, D, C, E : Integer;
      S : string;

    begin
      S:= Text
      for I:= 0 to High(FromX) do
      begin
        if I <> 0 then
          begin
            C := FromX[I];
            E := ToX[I];
            if (Pos(Text[C], S) > Pos(Text[C - 1], S)) then  //Line 16
              D:= D + (Pos(Text[C - 1], S) - Pos(Text[E - 1], S));
            Delete(Text, FromX[I - D], ToX[I - D]);
          end;
      end;
      Result:= Text;
    end;

    SCAR Code:
    writeln(deletemulti('hi how are you today"', [3, 7], [5, 9]));

      hi howtoday"

    EDIT: Hmmm I don't think that works.. but I gtg .

  5. #5
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    You may want to check and make sure the lengths of each array are the same.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •