|
-
Apr 28th, 2008, 09:21 AM
#1
Thread Starter
Frenzied Member
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
-
Apr 28th, 2008, 09:27 AM
#2
Re: How to truncate text
Set MaxLength property to whatever number you wish:
Code:
Private Sub Form_Load()
Text1.MaxLength = 10
End Sub
-
Apr 28th, 2008, 09:35 AM
#3
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.
-
Apr 28th, 2008, 09:38 AM
#4
Thread Starter
Frenzied Member
Re: How to truncate text
How to pop up with messagebox when the input reach to maximum?
-
Apr 28th, 2008, 10:08 AM
#5
Fanatic Member
Re: How to truncate text
 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
-
Apr 28th, 2008, 10:10 AM
#6
Re: How to truncate text
 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
-
Apr 28th, 2008, 10:28 AM
#7
Re: How to truncate text
 Originally Posted by matrik02
How to pop up with messagebox when the input reach to maximum?
Why messagebox? They are annoying.
Show the tooltip instead (something like "Maximum number of characters allowed is 10")
-
Apr 28th, 2008, 10:29 AM
#8
Fanatic Member
-
Apr 28th, 2008, 10:38 AM
#9
Re: How to truncate text
It's property (most controls have it) that you can set at design or runtime.
-
Apr 28th, 2008, 10:42 AM
#10
Fanatic Member
-
Apr 28th, 2008, 10:45 AM
#11
Re: How to truncate text
 Originally Posted by RhinoBull
It's property (most controls have it) that you can set at design or runtime.
-
Apr 28th, 2008, 10:48 AM
#12
Fanatic Member
Re: How to truncate text
 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
-
Apr 28th, 2008, 12:10 PM
#13
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
-
Apr 28th, 2008, 12:10 PM
#14
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
-
Apr 28th, 2008, 03:40 PM
#15
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.
-
Apr 28th, 2008, 07:53 PM
#16
Re: How to truncate text
 Originally Posted by BruceG
... 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.
Exactly. Which is why I suggested tooltip.
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
|