index 2 is out of range

index 2 is out of range

  


Good evening, I'm getting one or several messages by NotifyGetMessage, but I'm getting this error as an answer someone has already gone through?

Solution

Hi Daianne,

When you use the [X] on a list you need to be carefull. That error means that when you try to access the position 2 of the list there is nothing there. that means that the list has 2 or less elements (because of position 0). Your erro is to use this String_Split.List[2] when sometimes the list doesnt have enough elements

Hope this helps.

Regards,

Marcelo

Solution

Marcelo Ferreira wrote:

Hi Daianne,

When you use the [X] on a list you need to be carefull. That error means that when you try to access the position 2 of the list there is nothing there. that means that the list has 2 or less elements (because of position 0). Your erro is to use this String_Split.List[2] when sometimes the list doesnt have enough elements

Hope this helps.

Regards,

Marcelo

Hi Marcelo I still do not understand how that could solve the problem, would it catch what I'm getting NotifyGetMessage and put in a list to then do the for?


Hi,

I was only explaining the error you are getting. For solution you should have a for to go through all the elements from string_split. If that is not possible just check if the list has the correct size before doing list[X]

Regards,

Marcelo

Hi Daianne,

Indexing a list by using the [n] notation, like Marcelo explained, must be done with cause: you can only index something that is there. If you have only a single element in a list, there's only List[0], but not e.g. List[1]. Trying to access List[1] will lead to an Exception like you got. The same for a list with two elements, which are List[0] and List[1], but List[2] doesn't exist and trying to access it will lead to the Exception.

String_Split has, as Output Parameter, a List of tokens. If, as you said, there's 1 or several messages, String_Split will produce a List with 1 or more elements. If there's code (e.g. an Expression or Assignment) that references String_Split.List[2] while there's less than three elements ([2] is the third element: [0] is the first, [1] the second), that code will cause an Exception to occur. In general, before you use [n], you must make sure that n is smaller than List.Length.

Hi Daianne,

That error means that you are trying to access to the 3rd element of your list, but your list have less than 3 elements. That's the meaning of that error.

Hi Daianne,


In your Assign,you are trying to access the position 2 in your list... And the error show us Please, do a debug and show us your list.


Thanks

Daianne Caetano Figueredo Souza wrote:

Daianne Caetano Figueredo Souza wrote:

Paulo Cação wrote:

Hi Daianne,


In your Assign,you are trying to access the position 2 in your list... And the error show us Please, do a debug and show us your list.


Thanks

Good afternoon, I'll share the file opa. If you can help me, I'll be grateful.



I can't open file..Invalid Intellectual Property.. 

I think it's enough to share a printscreen with the debug to run and with the list


@Nelson, @Paulo: Please check whether the answer you're about to give hasn't been given before, to avoid situations like the above, where you both restate the answer that three people already gave.

@Daianne: I'm not sure what help you need now. It has already been explained what the problem is (like, 5 times already) and the solution has also been given already (avoid accessing indexes that aren't there). So what is it you need help with?

Kilian Hekhuis wrote:

@Nelson, @Paulo: Please check whether the answer you're about to give hasn't been given before, to avoid situations like the above, where you both restate the answer that three people already gave.

@Daianne: I'm not sure what help you need now. It has already been explained what the problem is (like, 5 times already) and the solution has also been given already (avoid accessing indexes that aren't there). So what is it you need help with?

Sry about that, but I tried to analyse the Assign in the flow (I didn't explained the error) and I asked for more information... Anyone asked for more information?

I didn't ask for more information, since I already provided the OP with an answer. I think they should be able to figure out on their own how to take it from there :).