|
-
Aug 22nd, 2008, 05:53 AM
#1
Thread Starter
Addicted Member
[RESOLVED] disallowing text input in a textbox
ok so the first one was a success, but now i want to disallow the user from typing anything but numbers into the textbox, since you cannot multiply, add, divide or subtract a letter, or any other symbol. if there is no way to actually stop the user from typing these, how can i make an elseif statement to only allow the calculator to allow a number between 1 and 13034431, and nothing else, and then display
Code:
msgbox "Please type a proper number"
Last edited by clownboy; Aug 22nd, 2008 at 05:57 AM.
-
Aug 22nd, 2008, 05:59 AM
#2
Re: disallowing text input in a textbox
Something like this...????
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then
'
Else
KeyAscii = 0
End If
End Sub
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Aug 22nd, 2008, 06:01 AM
#3
Re: disallowing text input in a textbox
There are a few ways of doing this.
Easiest would be to add this in your _LostFocus() Event
Code:
If IsNumeric(text1.text) = False then
msgbox "Please type a proper number"
text1.setfocus
End If
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

-
Aug 22nd, 2008, 06:05 AM
#4
Re: disallowing text input in a textbox
Or something like this..????
Code:
Private Sub Text1_Change()
If IsNumeric(Text1.Text) = False Then
MsgBox "Only numbers are allowed..!!"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
End If
If Val(Text1.Text) >= 1 And Val(Text1.Text) <= 13034431 Then
'
Else
Text1.Text = "1"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
MsgBox "The limit is from 1 to 13034431", vbCritical, "Exceeds limit...!"
End If
End Sub
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Aug 22nd, 2008, 06:13 AM
#5
Thread Starter
Addicted Member
Re: disallowing text input in a textbox
akhileshbc, both were good, but disallowed the use of backspace for the first set of code, and the message came up when backspace was pressed for the second one.
some1uk03, worked, but the error still came up after the message arrived.
any solution to allow the backspace as well?
sorry am n00b
-
Aug 22nd, 2008, 06:26 AM
#6
Re: disallowing text input in a textbox
Try this...
Code:
Private Sub Text1_Change()
If Trim(Text1.Text) = "" Then Exit Sub '''''''''''''''''''''''''''''''''''''''''newly introduced
If IsNumeric(Text1.Text) = False Then
MsgBox "Only numbers are allowed..!!"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
End If
If Val(Text1.Text) >= 1 And Val(Text1.Text) <= 13034431 Then
'
Else
Text1.Text = "1"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
MsgBox "The limit is from 1 to 13034431", vbCritical, "Exceeds limit...!"
End If
End Sub
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Aug 22nd, 2008, 06:32 AM
#7
Thread Starter
Addicted Member
Re: disallowing text input in a textbox
is there anything you can't do?? 
legend mate, i'll keep you yet. ^^
-
Aug 22nd, 2008, 06:34 AM
#8
Re: [RESOLVED] disallowing text input in a textbox
Try this (backspace is 8)
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 46 And KeyAscii <> 13 _
And KeyAscii <> 8 Then
MsgBox "Only numbers are allowed for this entries"
KeyAscii = 0
Exit Sub
End If
End Sub
'also, in the change event put this code
'to prevent pasting in non numeric text
Private Sub Text1_Change()
If Not IsNumeric(Text1.Text) Then
MsgBox "Only Numbers Are Allowed"
Text1.Text = vbNullString
Exit Sub
End If
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
|