Right Function


Right (stringexpression, n )

Returns the right most n characters of the string parameter.

The parameter stringexpression is the string from which the rightmost characters are returned.

The parameter n is the number of characters that will be returned and must be a long integer.

Example:

    ' The example uses the Right function to return the first of two

    ' words input by the user.

 

    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.

    End Sub


Related Topic:

Len

Left

Mid Function