My Texbox has 123456
and i use this code;
MsgBox Right(Tex1.Text, 1)
but when i use MsgBox Right(Tex1.Text, 2), it display 56..
how can i display only the number 5 using the "Right" command?
Printable View
My Texbox has 123456
and i use this code;
MsgBox Right(Tex1.Text, 1)
but when i use MsgBox Right(Tex1.Text, 2), it display 56..
how can i display only the number 5 using the "Right" command?
If you only want to find the number 5 then you can use the below. There's probably a better way but it works :)
VB Code:
Private Sub Command1_Click() Dim MyText As String Dim MyNumber As String MyNumber = 5 MyText = Text1.Text MyText = InStr(1, MyText, MyNumber) MsgBox Mid(Text1.Text, MyText, 1) End Sub
Right$ returns X number of characters from the end of a string. You will need a combination of one or more of these functions - Right$, Left$, Mid$ - to return a single character that is the last character in the string.
Some samples that should all return 5.
VB Code:
Dim strTemp As String strTemp = "123456" Debug.Print Right$(Left$(strTemp, Len(strTemp) - 1), 1) Debug.Print Left$(Right$(strTemp,2),1) Debug.Print Mid$(Right$(strTemp,2),1,1) 'if want to return the 5th character of a string Debug.Print Mid$(strTemp,5,1)