String to Double (Input string was not in a correct format.)

Dear UiPath friends!

I am currently breaking my head over the error below.

What I want:

  • Retrieve information from a website percentage (as a String) that could be positive and negative (for example 0,08 or -0,05);
    *Write it to a dt column so I can reuse the information easily for a further analyses;
  • Get the information from the dt and assign a value to another column based on the result of the above mentioned value (string) using a If statement activity.

Other info:

  • I do not have this issue when I write the information into the dt myself.
  • This is how I get the information:

Error:
Source: Assign 5 min

Message: Input string was not in a correct format.

Exception Type: System.FormatException

RemoteException wrapping System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at lambda_method(Closure , ActivityContext )
at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context) at System.Activities.CodeActivity1.InternalExecuteInResolutionContext(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance, Activity1 expressionActivity) at System.Activities.InArgument1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityExecutor executor)
at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance targetActivityInstance, ActivityExecutor executor, Object argumentValueOverride, Location resultLocation, Boolean skipFastPath)
at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
β€” End of stack trace from previous location where exception was thrown β€”
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at UiPath.Executor.BaseRunner.EndExecute(IAsyncResult result)
at UiPath.Executor.InProcessRunner.EndExecute(IAsyncResult result)
at UiPath.Core.Activities.ExecutorInvokeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

I have tried changing the culture without any succes. Can somebody please please please help me out?! Thank you in advance!

Kr, NotARobot

Welcome to the community!
your data seems to have comma for the digit separation but you are using a dot…

Hello @bcorrea,

Thank you so much for your reply! Do you mind giving me a suggestion on what I need to change?
I have added a .Replace(",", β€œ.”) to the assign activity above the convertion to the double. I feel I am missing the point.

Thank you a lot in advance!

Kr, NotARobot

Along with this add this also and try
Convert.ToDouble(Yourvariable.ToString.Replace(β€œ,”,”.”).Replace(β€œ-β€œ,””))

Cheers @NotaRobot

Hello @Palaniyappan,

Thank you for getting involved as well! I really appreciate it!
I am getting the following error below.

Questions:

  • Does this mean that you need the convert the format in the same assign activity instead of the one above? Can you maybe tell me how this makes a difference? Still learning every day!
  • I would like to use a If statement with negative numbers (percentages like betweeb -0,08 and 0,10) for the next sequences. What do you recommend for this in terms of variable/ argument type? I could use the contains("-") but I prefer not to use this when possible.

Error:
19.11.0-beta.2+Branch.release-v2019.11.0.Sha.a63f04440c571d1ce4db01f500029852a5448737

Source: Assign 5 min

Message: Input string was not in a correct format.

Exception Type: System.FormatException

RemoteException wrapping System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Convert.ToDouble(String value)
at lambda_method(Closure , ActivityContext )
at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context) at System.Activities.CodeActivity1.InternalExecuteInResolutionContext(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance, Activity1 expressionActivity) at System.Activities.InArgument1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityExecutor executor)
at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance targetActivityInstance, ActivityExecutor executor, Object argumentValueOverride, Location resultLocation, Boolean skipFastPath)
at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
β€” End of stack trace from previous location where exception was thrown β€”
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at UiPath.Executor.BaseRunner.EndExecute(IAsyncResult result)
at UiPath.Executor.InProcessRunner.EndExecute(IAsyncResult result)
at UiPath.Core.Activities.ExecutorInvokeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

@bcorrea and @Palaniyappan,

Do you guys have any idea what I can be missing.
I have a strong feeling that I am overseeing something and I am pretty desperate about it.
Look forward hearing from you or anybody else.

Kr, NotARobot

Hey @Palaniyappan and @bcorrea,

I have tried the following scenario’s.

five_min = String
dbl_five_min = System.Double

Scenario 1
Assign
five_min TO five_min.Replace("-", β€œβ€).Replace(",",".").Trim
also tried with five_min TO five_min.Replace("-", β€œβ€).Trim

then

Assign
dbl_five_min TO CDbl(five_min)

Scenario 2
five_min TO five_min.Replace("-", β€œβ€).Replace(",",".").Trim
also tried with five_min TO five_min.Replace("-", β€œβ€).Trim

then

Assign
dbl_five_min TO CDbl(five_min)

Scenario 3
Assign
dbl_five_min TO Convert.ToDouble(five_min.ToString.Replace(β€œ,”,”.”).Replace(β€œ-β€œ,””))
also tried TO Convert.ToDouble(five_min.ToString.Replace(β€œ-β€œ,””))

Scenario 4
Assign
five_min TO five_min.Replace("-", β€œβ€).Replace(",",".").Trim
also tried with five_min TO five_min.Replace("-", β€œβ€).Trim

then

Assign
dbl_five_min TO Double.Parse(five_min)

Scenario 5
Assign
five_min TO five_min.Replace("-", β€œβ€).Replace(",",".").Trim
also tried with five_min TO five_min.Replace("-", β€œβ€).Trim

then

Assign
dbl_five_min TO System.Double.Parse(five_min)

Scenario 6
Assign
five_min TO five_min.Replace("-", β€œβ€).Replace(",",".").Trim
also tried with five_min TO five_min.Replace("-", β€œβ€).Trim

then

Assign
dbl_five_min TO Convert.ToDouble(five_min, Culture)

Culture =
	Variable type = system.Globalization.CulturInfo
	Default = new CultureInfo("nl")

As you probably can imagine… I am pretty lost by now. I hope you guys can help me out.

Hi @NotaRobot,

I tested with the following inputs, 0,08 or -0,05

Working fine for me…! Can you have look into this xaml…!

strToDoubl.xaml (6.4 KB)

Thanks!

Hello @kadiravan_kalidoss,

Thank you for trying to help me out. Somehow when it’s in my xaml I am getting the following:
β€œAssign: Conversion from string β€œβ€Ž-0.01β€Žβ€ to type β€˜Double’ is not valid.”

afbeelding

Can it have something to do with the Get Text? I am pretty confused about it all.

Can you print the get text output using writeline? and show me exactly what u r getting as string. @NotaRobot

Thanks!

Sure! -0,01β€Ž and within the assign its β€œβ€Ž-0,01β€Žβ€

I am getting the following error:
RemoteException wrapping System.InvalidCastException: Conversion from string β€œβ€Ž-0.01β€Žβ€ to type β€˜Double’ is not valid. β€”> RemoteException wrapping System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat)
β€” End of inner exception stack trace β€”
at Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) at lambda_method(Closure , ActivityContext ) at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context) at System.Activities.CodeActivity1.InternalExecuteInResolutionContext(CodeActivityContext context) at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance, Activity1 expressionActivity) at System.Activities.InArgument1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityExecutor executor) at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance targetActivityInstance, ActivityExecutor executor, Object argumentValueOverride, Location resultLocation, Boolean skipFastPath) at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Int32 startIndex) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Hey @kadiravan_kalidoss,

Your xaml works until I use the get text activity although the text is captured. Still workin on this issue. any advice? I have also recaptured the get text activity. Any advice?

strToDoubl.xaml (8.5 KB)

@Palaniyappan @kadiravan_kalidoss @bcorrea

I have found a solution. It turns out to work perfectly with the Get OCR Text activity instead of the Get Text Activity. Logically still shouldn’t make the difference to my opinion, but it does the trick. Thank you for you effort!

2 Likes

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