iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🤖

UiPath: Handy Snippets and Tips I Keep Forgetting

に公開
2024/02/14

I always find myself looking these up, so I'm putting them here as a memo for myself. I will add and update this post as needed.
Many of the contents relate more to VB.Net specifications than UiPath specifically (there are basically no mentions of C# mode).

Terminating a Workflow Midway

This is something you often want to insert during development. You can use the System.Activities.Statements.TerminateWorkflow activity. However, it doesn't show up in the activity search when using terms like "interrupt" (中断), "end" (終了), or "complete" (完了). Searching for Terminate is the correct way.

Reference

String Concatenation

You can use the & operator. It's the same as in Excel.

"Today is " & DateTime.Now.ToString("dd") & " day."

Reference

Determining if a Specific String is Included

"Hello, Guys".Contains("ell") '=> True

Numeric Zero Padding (0-padding)

You can do this with the ToString method of the Int32 type. The ToString method is convenient as it seems to double as a formatting function.

123.ToString("00000") '=> "00123"

Alternatively, the following using the PadLeft method of the String type yields the same result.

123.ToString().PadLeft(5,"0"c)
'or
"123".PadLeft(5,"0"c)

Equality Comparison

Both = and == can be used. It is best to standardize on one.

Short-circuit Evaluation of Logical Operators

If you intend to use && and || as found in common languages, use AndAlso or OrElse.

  • Short-circuit version of And → AndAlso
  • Short-circuit version of Or → OrElse
10 == 10 And Foo      ' Foo is also evaluated
10 == 10 AndAlso Foo  ' Foo is not evaluated

10 != 10 Or Foo       ' Foo is also evaluated
10 != 10 OrElse Foo   ' Foo is not evaluated

Reference

Full-width / Half-width Conversion

StrConv function.

Full-width → Half-width

StrConv("ABC123", VbStrConv.Narrow, 1041) '=> ABC123

Half-width → Full-width

StrConv("ABC123", VbStrConv.Wide, 1041) '=> ABC123

Reference

Displaying Modern Activities

For example, even for a "Click" activity, two types exist.

  • UiPath.Core.Activities.Click
  • UiPath.UIAutomationNext.Activities.NClick

In Japanese, the activity names for both are "クリック" (Click) and are identical (though icons differ slightly). However, the latter, which sounds like a Nitori product[1], uses seconds instead of milliseconds for timeout specifications and has other subtle differences.

Modern activities may be hidden by default. In that case, they won't appear even if you search for them.

Check if "Activities" -> "Funnel icon" -> "Show Modern" is enabled.

Modern activities are designed to be completed more within the GUI with as few variables as possible, and new features are actively being added to them. However, based on my experience, it's not always the case that using modern activities is better; they aren't simply "upgraded" versions of the activities.

Reference

Japanese can be used for variable names, but names starting with numbers are not allowed

Perhaps because there are more business people than professional programmers among users, Japanese variable names are often seen. In fact, Japanese is sometimes recommended because it can make the intent clearer.

However, names starting with single-byte numbers cannot be used.

Reference

脚注
  1. https://www.nitori-net.jp/ec/feature/nclick/ ↩︎

Discussion