Mid Function


string = Mid( strgvar,begin,length )

Returns a substring within a string.

Example:

    Sub Main()

 

    Dim LWord, Msg, RWord, SpcPos, UsrInp   ' Declare variables.

 

        Msg = "Enter two words separated by a space."

        UsrInp = InputBox(Msg)   ' Get user input.

        print UsrInp

        SpcPos = InStr(1, UsrInp, " ")   ' Find space.

        If SpcPos Then

            LWord = Left(UsrInp, SpcPos - 1)   ' Get left word.

            print "LWord: ";  LWord

            RWord = Right(UsrInp, Len(UsrInp) - SpcPos)   ' Get right word.

            Msg = "The first word you entered is " & LWord

            Msg = Msg & "." & " The second word is "

            Msg = "The first word you entered is <" & LWord & ">"

            Msg = Msg & RWord & "."

        Else

            Msg = "You didn't enter two words."

        End If

        MsgBox Msg   ' Display message.

        MidTest = Mid("Mid Word Test", 4, 5)

        Print MidTest

    End Sub