Int32.TryParse not returning reference integer


#1

When using the int32.tryparse(string, int) or integer.tryparse(string, int) method, the integer being returned is always 0.

Example below using the assign activity:
variables:
string a = "838"
bool b
int c

b = int32.tryparse(a, c)

Returned Results:
b = true
c = 0

I have tried changing up the variables to be arguments since arguments have an In and Out feature and still having the same results. Is there anything I am missing here? I am new to Workflow Foundation and UiPath but have developing background.


#2

I think c is still 0 because the ByRef isn’t working to store the new integer to the variable.

Usually I use Convert.ToInt32(string) or CInt(string)
and that makes more sense to me.

You can also do IsNumeric(string) to determine if it is a number.

Regards.


#3

Thanks @ClaytonM for the response. Yes I agree with you but its better coding practice to use TryParse in regards to error handling. The question is why isn’t the ByRef not working? Do you have the same results when trying the TryParse?


#4

same issue regarding Double.TryParse as well. The ByRef does not seem to be working at all.


#5

Yeah, I’m not sure why it doesn’t work in UiPath. Maybe it works if you use Invoke Code.


#6

I found this article at Stack Overflow. Seem to be the same issue in regards to Workflow Foundation. Arguments should seem to resolve this issue though.


#7

@ClaytonM, I was able to solve this by using the Invoke Method as mentioned in the Stack Overflow link above. I need to take a deeper dive into Workflow Foundation to understand why ByRef values have reference issues.