3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【UiPath】対応OS WindowsでのStrConv

Posted at

対応OSがWindowsレガシからWindowsに移行されて色々なものが変更されていきます。
マルチバイト文字…日本語などの取り扱い方法もその1つです。

全角➡半角や半角➡全角などをStrConv関数を使用して行っていた時にエラーが出たので備忘として回避策を残します。

StrConv関数
https://learn.microsoft.com/ja-jp/office/vba/language/reference/user-interface-help/strconv-function
変換の種類で指定した通りに変換したString型の値を返す関数です。

StrConv
StrConv("カキクケコ", VbStrConv.Narrow)
' 結果:カキクケコ

StrConvで良く調べられるエラーの種類としては大きく分けて2つあると思います。

VbStrConv.Wide and VbStrConv.Narrow are not applicable to the locale specified.

こちらは、変換しようとしたけれど使用している言語が合ってないよというエラーです(かなりザックリですが…)。
こちらのエラーの回避方法は2つあります。
1つ目はStrConv関数にロケールIDを設定してあげる方法です。

StrConv
StrConv("カキクケコ", VbStrConv.Narrow, 1041)

2つ目は「System.Threading.Thread.CurrentThread.CurrentCulture」というプロパティに日本を設定する方法です。

代入(左辺値 = 右辺値)
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("ja-JP")

No data is available for encoding 932. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.

こちらのエラーはEncode 932(Shift-JIS)に対応してないよというエラーです。
このエラーの回避方法は、「System.Text.Encoding.RegisterProvider」というメソッドに「System.Text.CodePagesEncodingProvider.Instance」を渡してあげることでエラーの回避ができます。

「System.Text.Encoding.RegisterProvider」は使えるように設定するメソッド
「System.Text.CodePagesEncodingProvider.Instance」は今の状態だと使えないものよというものを取り出すプロパティ
上記の2つを組み合わせることで、使えない状態のものを使えるようにしてあげるよという感じです。

UiPathでは[メソッドを呼び出し]アクティビティを使用することで設定できます。
Image.png

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?