Right, Right$ Functions

See Also8Z87V9              Example8HQI9KG>Low

Returns the rightmost n characters of a string argument.

Syntax

Right[$](stringexpr, n)

Remarks

Right returns a Variant8PHEAW3; Right$ returns a String.

The Right[$] function has these parts:

Part               Description

 

strexpr           String expression1330R89 from which the rightmost characters are returned.  This can be any string expression.  However, only Right can accept a Variant of VarType7A68ZTZ 1 (Null1DDW7C0) as stringexpr, in which case, a Null is returned.

n                   Long integer expression indicating how many characters to return.  It must be between 0 and approximately 65,535, inclusive.  If n is 0, the return value is a zero-length string.  If n is greater than or equal to the number of characters in strexpr, the entire string is returned.

 

To find the number of characters in stringexpr, use Len(stringexpr).


See Also

Instr FunctionPSLW56

Left, Left$ FunctionGU9X0I

Len FunctionLANLEN

Mid, Mid$ Function3XXKYW5


Right, Right$ Function Example

The example uses the Right function to return the second of two words input by the user.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

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

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

   UsrInp = InputBox(Msg)                      ' Get user input.

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

   If SpcPos Then

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

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

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

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

      Msg = Msg & RWord & "." & """"

   Else

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

   End If

   MsgBox Msg                                  ' Display message.

End Sub