Функція Mid, інструкція Mid

Повертає вказану частину рядка (функція Mid) чи замінює цю частину рядка іншим рядком (інструкція Mid).

Синтаксис:


Mid (Text As String, Start As Long [, Length As Long])
Mid (Text As String, Start As Long, Length As Long, Text As String)

Повертає значення:

String (тільки для функції)

Параметри:

Текст: довільний рядок, котрий потрібно змінити.

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 опущено, повертаються всі символи рядкового виразу від початкової позиції до кінця рядка.

Якщо параметр Довжина інструкції Mid менший, ніж довжина замінюваного тексту, то його буде скорочено до вказаної довжини.

Текст: рядок, який повинен замінити рядковий вираз (інструкція Mid).

Коди помилок:

5 Неправильний виклик процедури

Приклад:


Sub ExampleMid_Function_and_Statement
  original_text = "This is the original Text"
' Mid as function 
  msgbox Mid( original_text , 13, 8) ' returns the word original
  msgbox original_text               ' original_text not modified
' Mid as statement 
  Mid( original_text, 13, 8, "new" )
  msgbox original_text               ' returns This is the new Text
End Sub