|
-
Mar 9th, 2010, 11:10 AM
#1
Thread Starter
Lively Member
[RESOLVED] Limiting textbox characters
Hi I have a program where i want the texbox only to input numbers i have the ascii coding but the problem is that it is a private sub so even when i dont have to put in data into the textbox it still does the ascii check. here is my coding
Private Sub txtfirstname_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 33 To 64, 91 To 96, 123 To 126
MsgBox ("Only letters supported for this field! Please input a name.")
KeyAscii = 0
Exit Sub
End Select
End Sub
-
Mar 9th, 2010, 11:17 AM
#2
Re: Limiting textbox characters
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
-
Mar 9th, 2010, 11:26 AM
#3
Re: Limiting textbox characters
 Originally Posted by TechKid
Hi I have a program where i want the texbox only to input numbers i have the ascii coding but the problem is that it is a private sub so even when i dont have to put in data into the textbox it still does the ascii check. here is my coding
I don't understand that part of the post. the KeyPress event is only fired when you press a key. So if you have no data to enter you don't press a key. Why would the event trigger ? As a side note, Tabbing through the control will not trigger the event as the TAB key is "special" that way.
Can you clarify what you mean by "when I dont have to put in data into the textbox it still does the ascii check" ?
Kind Regards,
Optional
If you feel this post has helped in answering your question please return the favour and Rate this post.
If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.
VB6 - (DataGrid) Get the Row selected with the right mouse button
-
Mar 9th, 2010, 11:27 AM
#4
Thread Starter
Lively Member
Re: Limiting textbox characters
 Originally Posted by koolsid
I already have the coding and it works. My problem is i only want it to be enabled when I click add and the texbox is able to accept input. At the begining of my program the textbox is not allowed to acced input until i click add. When i start my program even before i click add the texbox is already formatted and that is my problem
-
Mar 9th, 2010, 11:31 AM
#5
Thread Starter
Lively Member
Re: Limiting textbox characters
 Originally Posted by Optional
I don't understand that part of the post. the KeyPress event is only fired when you press a key. So if you have no data to enter you don't press a key. Why would the event trigger ? As a side note, Tabbing through the control will not trigger the event as the TAB key is "special" that way.
Can you clarify what you mean by "when I dont have to put in data into the textbox it still does the ascii check" ?
Ok The boxes are used for displaying and inputting information. When it is only diplaying it still checks if the textbox if it has only letters and if i type a number it gives an error. I want it to only check for letters when i click add. I think the problem is because I have it under the private sub. I need to get it under the Add procedure so that it can only check when i click add
-
Mar 9th, 2010, 11:43 AM
#6
Re: Limiting textbox characters
I'm assuming when you only display data your textbox.enabled property is set to false ?
Would a validation of the enabled property help ?
VB Code:
Private Sub txtfirstname_KeyPress(KeyAscii As Integer) If (Not (txtfirstname.Enabled)) Then Exit Sub Select Case KeyAscii Case 33 To 64, 91 To 96, 123 To 126 MsgBox ("Only letters supported for this field! Please input a name.") KeyAscii = 0 Exit Sub End Select End Sub
Kind Regards,
Optional
If you feel this post has helped in answering your question please return the favour and Rate this post.
If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.
VB6 - (DataGrid) Get the Row selected with the right mouse button
-
Mar 9th, 2010, 11:45 AM
#7
Re: Limiting textbox characters
Ok... Remove that code from Keypress and validate the contents of the textbox in the Add event...
Something like
Code:
Private Sub CmdAdd_Click()
For i = 1 To Len(Text1.Text)
If Asc(Mid(Text1.Text, i, 1)) > 47 And _
Asc(Mid(Text1.Text, i, 1)) < 58 Then
MsgBox "Textbox cannot have numbers"
Exit For
End If
Next i
End Sub
Last edited by Siddharth Rout; Mar 9th, 2010 at 11:48 AM.
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
-
Mar 9th, 2010, 11:48 AM
#8
Thread Starter
Lively Member
Re: Limiting textbox characters
Thanks guys It worked. thank you so much
-
Mar 9th, 2010, 11:55 AM
#9
Re: Limiting textbox characters
Edit: - deleted post - Didn't see koolsid already posted the solution.
Kind Regards,
Optional
If you feel this post has helped in answering your question please return the favour and Rate this post.
If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.
VB6 - (DataGrid) Get the Row selected with the right mouse button
-
Mar 9th, 2010, 11:58 AM
#10
Thread Starter
Lively Member
Re: [RESOLVED] Limiting textbox characters
Im going to use both of them
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
|