Correct format issue

Hi,
I encountered an error in this expression with the following error message: “If: Input string was not in a correct format” for this expression :
CountryOutput.Equals(Country_Iteration) = True And Int32.Parse(Supplier_ID_Iteration) = Int32.Parse(SupplierID_Iteration_BL)

for information: the value of “SupplierID_Iteration_BL” is “9999” it is fixed but the value of “Supplier_ID_Iteration” normally a string which contains a number (digits) for the case where I received an error the “Supplier_ID_Iteration” contains an empty string and once string which contains a character string.
how can solve this issue ?

Regards

@aya_lajili1

as per error and info provided looks like SupplierID_Iteration_BL is having some data which are not digits…if so we cannot parse it as integer.please check the same

and condition can be like this

CountryOutput.Equals(Country_Iteration) And Cint(Supplier_ID_Iteration).Equals(Cint(SupplierID_Iteration_BL))

cheers

1 Like

Don’t use Int32.Parse() use CInt()

for the case where I received an error the “Supplier_ID_Iteration” contains an empty string and once string which contains a character string.

Check if it’s numeric first…

If IsNumeric(Supplier_ID_Iteration)

  • Then CInt(Supplier_ID_Iteration)
  • Else not numeric
1 Like

and in the case that “Supplier_ID_Iteration” is a string “ACM_49007949” and i got this error message :
If: Conversion from string “ACM_49007949” to type ‘Integer’ is not valid.

@aya_lajili1

obviously you cannot convert string to integer

cheers

can we compare “99999” with “ACM_49007949” ? without converting

the aim it to see if Supplier_ID_Iteration is eaqual to SupplierID_Iteration_BL what ever the content of this two variables ?

Hi @aya_lajili1

Try this:

Assign isValidSupplierIDIteration = Int32.TryParse(Supplier_ID_Iteration, supplierIDIteration)
Assign isValidSupplierIDIterationBL = Int32.TryParse(SupplierID_Iteration_BL, supplierIDIterationBL)

If CountryOutput.Equals(Country_Iteration) AndAlso isValidSupplierIDIteration AndAlso isValidSupplierIDIterationBL AndAlso supplierIDIteration = supplierIDIterationBL Then
    ' Your code for when the conditions are met
Else
    ' Your code for when the conditions are not met
End If

Hope it helps!!

Hi @aya_lajili1
The error message you’re encountering, “Input string was not in a correct format,” typically occurs when you’re trying to parse a string into an integer, but the string does not contain a valid integer representation. In your case, you are trying to parse the Supplier_ID_Iteration string, which may sometimes be empty or contain non-numeric characters.

You can modify your expression to handle this:

CountryOutput.Equals(Country_Iteration) = True And
If(String.IsNullOrWhiteSpace(Supplier_ID_Iteration), False,
Int32.TryParse(Supplier_ID_Iteration, Nothing)) = True And
Int32.TryParse(SupplierID_Iteration_BL, Nothing) = True

Thanks!

how to put all that on one expression
CountryOutput.Equals(Country_Iteration) = True And
If(String.IsNullOrWhiteSpace(Supplier_ID_Iteration), False,
Int32.TryParse(Supplier_ID_Iteration, Nothing)) = True And
Int32.TryParse(SupplierID_Iteration_BL, Nothing) = True

into one if condition

@aya_lajili1

if you just need to see if they are equals then use Supplier_ID_Iteration.equals(SupplierID_Iteration_BL)

no conversion is needed

cheers

what ever their datatype ?

@aya_lajili1

Then use this if both are not strings

Supplier_ID_Iteration.ToString.Trim.Equals(SupplierID_Iteration_BL.ToString.Trim)

Cheers

the two cases that i got :
Supplier_ID_Iteration = “” : empty
Supplier_ID_Iteration = “ame_1256”

and we have the
SupplierID_Iteration_BL alwayes a number like “897562”

so with this expression Supplier_ID_Iteration.ToString.Trim.Equals(SupplierID_Iteration_BL.ToString.Trim) it will be solved ?

@aya_lajili1

Yes it would work for both…try it out

cheers

Hi,

Try this

CountryOutput.Equals(Country_Iteration) = True And Int32.TryParse(Supplier_ID_Iteration, Supplier_ID_Parsed) And Int32.TryParse(SupplierID_Iteration_BL, SupplierID_Parsed_BL) And Supplier_ID_Parsed = SupplierID_Parsed_BL

Hi ,

it work’s , just i have a quetion because i want to make a check on this variable Supplier_ID_Iteration if it is a number means contain only digits or contain string to exclude from the beginig

@aya_lajili1

To check if it is a number then use String.IsNumeric(stringVariable) this gives true if number else false

cheers

and i want to check numiric and not empty ? toghether

@aya_lajili1

Not String.IsNullOrEmpty(strvar) AndAlso string.IsNumeric(strvar)

Ideally if empty then numeric anyways will be false

Cheers

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