Mid Function, Mid Statement

文字列表式の中から指定部分を取得して返す (Mid 関数) か、該当部分を他の文字列に置き換えます (Mid ステートメント)。

Syntax:


Mid (Text As String, Start As Integer [, Length As Integer]) または Mid (Text As String, Start As Integer , Length As Integer, Text As String)

Return value:

文字列 (関数のみ)

Parameters:

Text: 操作対象とする文字列表式。

Start: Numeric expression that indicates the character position within the string where the string portion that you want to replace or to return begins. The minimum allowed value is 1. The maximum allowed value is 2,147,483,648.

Length: Numeric expression that returns the number of characters that you want to replace or return. The maximum allowed value is 2,147,483,648.

Mid 関数 の場合、Length パラメーターを指定しないと、指定文字列の開始位置から末尾までが返されます。

Mid ステートメント の場合、Length パラメーターの値が置き換えるテキストよりも短いと、この長さにテキストが切りつめられます。

Text: 文字列表式を置き換える文字列 (Mid ステートメント)。

Error codes:

5 無効なプロシージャー呼び出しです

Example:


Sub ExampleUSDate
Dim sInput As String
Dim sUS_date As String
    sInput = InputBox("Please input a date in the international format 'YYYY-MM-DD'")
    sUS_date = Mid(sInput, 6, 2)
    sUS_date = sUS_date & "/"
    sUS_date = sUS_date & Right(sInput, 2)
    sUS_date = sUS_date & "/"
    sUS_date = sUS_date & Left(sInput, 4)
    MsgBox sUS_date
End Sub

ご支援をお願いします!