Multiple if statements

I have a solution for this problem, but looking to improve it or create more elegant way.

Here is the example:
I have one number which will be maximum of 6 digits.
If the number is 4 digits, I must add two 0 at the start of this document -> 001234
If the number is only one digit, I must add five 0 at the start of the documen ->> 000004
I need always to have 6 digit number.

The first solution that come in my mind was this:
Create variable to store the number of digits.
Multiple IF statements where I check the length and
these IF statements will be repetitive until IF Counter = 1

The second one it’s almost the same. I think it’s not good idea, because it’s not even easy readable for the human. In every ELSE statement inside of the IF statement, I put a new IF statement for the next length.

Is there any possible way to make it better and simpler instead of recreate from the first example?

Flowcharts is the Answer for your Query :slight_smile:

and then you make use of Flow Switch -

Please refer the below post - It has an xaml attached explaining Flow Switch.


  • Your Number is a String, I missed that
  • I’m adding an approach for multiple IF


  • Adding Dynamic padding

Just the answer

For you workflow, just use:

String.Format(Number, "000000")

Multiple If

You could create an Array {β€œ000000”, β€œ00000”, β€œ0000”, β€œ000”, β€œ00”, β€œ0”, β€œβ€} and then

DocumentNumber = myArray(Number.Length) & Number

(as you garanty that max length is six)

Dynamic padding

padding = Strings.StrDup(LENGTH - Number.Length, β€œ0”)
documentNumber = padding & Number

@Veselin_Ganchev - you can try with string.format option

like String.format("%02d" , number) - will add 2 zero’s in front…

try below and check
String.format("%"+(6-Number.Count)+β€œd” , Number)

It looks like you want to react on the numbers individually

Have a look on the switch activty

From the understanding of you want to achieve that you want fill up on begin with zeros. So this can be done with the padleft function and you can avoid the nested if else


And if the goal is to full up a tring to certain length with 0 so it can be done directly with padleft on the string:

1 Like

@mukeshkala, @msan, @GBK, @msan, @ppr

First, thanks to all people who send me proposal.
I read all of them and you give me topics to read/understand for new knowledge.

But the most simpler solution was: Number.padleft(6,CChar(β€œ0”)).
Always fill the first digits with zero based on the max length. In this case it’s 6.
I really appreciate every single comment from this topic.

Thank you!