Results 1 to 3 of 3

Thread: right

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Pilipinas
    Posts
    441

    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?

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    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:
    1. Private Sub Command1_Click()
    2. Dim MyText As String
    3. Dim MyNumber As String
    4. MyNumber = 5
    5. MyText = Text1.Text
    6. MyText = InStr(1, MyText, MyNumber)
    7. MsgBox Mid(Text1.Text, MyText, 1)
    8.  
    9. End Sub

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    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:
    1. Dim strTemp As String
    2.  
    3. strTemp = "123456"
    4.  
    5. Debug.Print Right$(Left$(strTemp, Len(strTemp) - 1), 1)
    6.  
    7. Debug.Print Left$(Right$(strTemp,2),1)
    8.  
    9. Debug.Print Mid$(Right$(strTemp,2),1,1)
    10.  
    11. 'if want to return the 5th character of a string
    12. 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
  •  



Click Here to Expand Forum to Full Width