If condition not giving the right answer

workflow
studio

#1

I have a workflow that reads values of each cell in a table. If the value is greater than 1000 then it should give med a response “Too Large” else “ok”. However, it does not always work. For example the value in the table is 920 and it gives med “Too Large”



#3

please change MaxValue variable type as Double and try.

hope my inputs are useful.


#4

I tried changing the type to double, however i am getting an error :Option strict dissalows implicit conversion from String to Double


#5

Change the datatype of rowValue to int or at the time of comparison do like this in if.

Cint(rowValue) >maxValue

That was not working because you were comparing the string with int.
and you can use int for maxValue.

Regards…!!
Aksh


#6

Thank you @aksh1yadav! That seems to do the trick. However, some of the cells might have blank values, not 0. And i am getting an error:

Anyway to fix this as well? :slight_smile:


#7

Try this: Cint(rowValue)> maxValue and Cint(rowValue)<>" "


#8

Cint(rowValue)> maxValue and rowValue<>" "

or

Cint(rowValue)> maxValue and rowValue.Trim.length >0

Regards…!!
Aksh


#9

Both will still throw on empty value. You need to do a shortcircuited check (AndAlso, not And) and reverse the condition:
Not String.IsNullOrWhitespace(rowValue) AndAlso CInt(rowValue)
Although I’d recommend spltting it to a nested if, so you can handle all 3 scenarios:

  1. Empty string.
  2. Too high value.
  3. OK value.

#10

For me both are working mate @andrzej.kniola


#11

They shouldn’t - CInt should throw on empty argument (as it did for @nbjerke) and that’s the first operation that’s done in that IF … That’s weird.
Don’t have time to check language reference deeper now, but CInt(String.Empty) should throw an InvalidCastException every single time.


#12

Yeah then better to use

Int.TryParse

Int32 op;

Int32.TryParse(String.Empty,out op); // will return op=0 if you will pass an empty string

Int32.TryParse(“1234”,out op); //and will pass converted int value if you will pas a number string.

Int32.Parse(string, out int) method converts the specified string representation of 32-bit signed integer equivalent to out variable, and returns true if it is parsed successfully, false otherwise.
When string is a null reference, it will return 0 rather than throw ArgumentNullException. If string is other than an integer value, the out variable will have 0 rather than FormatException.
In Overflow Exception case also it will return only Zero.

Regards…!!
Aksh


#13

Thanks for all the answers. So what would the syntax be for the Int32.TryParse(string, out int) be? Int32.TryParse(rowValue, out int) > maxValue?


#14

Hi @nbjerke,

I think you should insert Int32.TryParse method in Invoke Code Activity and pass two arguments: input string and output Int32 value. Try this example: example_out_int.xaml (5,1 KB)


#15

Hi there @nbjerke,
The below example may assist in utilising the TryParse functionality.

TryParse Test.xaml (8.7 KB)

Thanks in advance,
Josh


#16

Perfect! That did the trick! Thanks for all the help :slight_smile: