Results 1 to 16 of 16

Thread: How to truncate text

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    How to truncate text

    I have typing the textbox more then 13 character. How I can trancate this character to 8 character?
    For example "ABCDEFGHIJKCVBNE" will become "ABCDEFGH"



    If Len(TxtKrigRasterWorkspace.Text) >= 13 Then

  2. #2

  3. #3
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: How to truncate text

    You can also set the MaxLength property of the textbox at design-time.
    "It's cold gin time again ..."

    Check out my website here.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to truncate text

    How to pop up with messagebox when the input reach to maximum?

  5. #5
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to truncate text

    Quote Originally Posted by matrik02
    How to pop up with messagebox when the input reach to maximum?
    Code:
    Private Sub Text1_Change()
        If Len(Text1.Text) > 8 Then MsgBox "Something"
    End Sub

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: How to truncate text

    Quote Originally Posted by matrik02
    I have typing the textbox more then 13 character. How I can trancate this character to 8 character?
    For example "ABCDEFGHIJKCVBNE" will become "ABCDEFGH"



    If Len(TxtKrigRasterWorkspace.Text) >= 13 Then
    What I understand from above is that no matter what the user enters you want only the 1st 8 characters. If yes, then is this what you want?

    Code:
    Sub aaa()
    
    If Len(Trim(TxtKrigRasterWorkspace.Text)) >= 13 Then
        
        TxtKrigRasterWorkspace.Text = Left(Trim(TxtKrigRasterWorkspace.Text), 8)
    
    End If
    
    End Sub
    by the way Trim suppresses the leading and trailing spaces...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

  8. #8
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to truncate text

    How to show tooltip?

  9. #9

  10. #10
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to truncate text

    How can i show tooltip?

  11. #11

  12. #12
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to truncate text

    Quote Originally Posted by RhinoBull
    I know how can i show it, but is there any way to show it if condition is met.
    Lets say

    If Len(Text1.Text) = 10 then show text1.tooltip

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to truncate text

    Try
    Code:
    Private Sub Text1_Change()
    If Len(Text1.Text) <> 8 Then
       Text1.ToolTipText = vbNullString
    Else
       Text1.ToolTipText = "You can only have 8 characters in the textbox"
    End If
    End Sub

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to truncate text

    Try
    Code:
    Private Sub Text1_Change()
    If Len(Text1.Text) <> 8 Then
       Text1.ToolTipText = vbNullString
    Else
       Text1.ToolTipText = "You can only have 8 characters in the textbox"
    End If
    End Sub

  15. #15
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: How to truncate text

    Also, if you set the MaxLength property, either in code as Rhino has suggested, or in the design-time property sheet as I have suggested, you will not need to show a message of any kind, as the user will simply not be able to enter any more text into the box.
    "It's cold gin time again ..."

    Check out my website here.

  16. #16

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