|
-
Mar 12th, 2004, 12:03 AM
#1
Thread Starter
Hyperactive Member
right
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?
-
Mar 12th, 2004, 12:40 AM
#2
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
-
Mar 12th, 2004, 12:42 AM
#3
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|