StartIndex cannot be less than zero. (Parameter 'startIndex') count lenght

Hi team

I am doing a Excel Read Range, later I use for each row data table and get row item.

The objective is to make the column format number, and it is required to use the following rules

those that have more than 10 characters, take the 10 characters from right to left
If the field has less than 10 characters, they are removed

To count the number of characters I am using
vph.Length.ToString

To identify if the field has more than 10 characters I am using an if vCountpn>=“10”
To extract the 10 characters from right to left I use the following vCountpn.Substring(vCountpn.Length -10), in this part is where I get the error StartIndex cannot be less than zero. (Parameter ‘startIndex’)

After that, overwrite the column that shows the data of the fields, with the 10 characters
I appreciate you can help me

Best regard

@Julian_Torres_Torres

As per error your length is less than 10 and when you subtract it gets less than 0…so print the vcountpn.length and check the value properly

Cheers

Hello
Using the message box with
assign
vCountpn = vph.Length.ToString , has a value of 16 characters
when using the substring vCountpn.Substring(vCountpn.Length -10), I get the error.

I have something wrong in the substring
StartIndex cannot be less than zero. (Parameter ‘startIndex’)

@Julian_Torres_Torres

You should be doing vph.Substring and not vcountpn.Substring

vcountpn is 16 not the string

Cheers

it worked

How could I eliminate the fields that have less than 10 characters?

Greetings

@Julian_Torres_Torres

On the else side of your condition…assign it with string.Empty

I hope when you say eliminate you want to remove that value and make it empty

Cheers

Its worked

I have other question . I have a column with the information dd/MM/yyyy hh:mm:ss. I want to make parser to the dd/MM/yyyy

I have read range excel of the column date, the save to is vRange
I have for each row in data table , with for each CurrentRow
I have get row item with value vfecha
I have Assign DateTime.ParseExact(CurrentRow(“created_time”).ToString,“dd/MM/yyyy hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”) and the error is String ‘1/6/2023’ was not recognized as a valid DateTime

@Julian_Torres_Torres

The input format is d/M/yyyy and not dd/MM/yyyy

And I believe there are no hours also…if not there then please temove it also

Cheers

Hi @Julian_Torres_Torres

Try this-

  1. Use the “Read Range” activity to read the Excel file and store the data in a DataTable variable, let’s call it dataTable.
  2. Add a “For Each Row” activity to loop through each row in the dataTable.
  3. Within the loop, use an “Assign” activity to get the value of the number column and store it in a variable, let’s call it vph.
  4. Add an “If” activity with the condition vph.Length >= 10 to check if the value has more than 10 characters.
  5. Inside the “Then” section of the “If” activity, use an “Assign” activity to extract the rightmost 10 characters from the value and store it back in vph. You can use vph = vph.Substring(vph.Length - 10).
  6. Outside the “If” activity, use another “Assign” activity to update the value of the number column in the current row with vph. You can use CurrentRow("NumberColumn") = vph.
  7. Finally, outside the loop, use the “Write Range” activity to write the modified dataTable back to the Excel file.

Thanks!!

Its working

Thans

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.