473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

getting only numbers by textbox.

hi, myself vandana. is there any property of textbox that can allow textbox to accept only numbers. i tried it by setting dataformatting property to number but nothing happens.
thx in adv.
Mar 21 '07 #1
6 6061
Shailja
123 100+
hi, myself vandana. is there any property of textbox that can allow textbox to accept only numbers. i tried it by setting dataformatting property to number but nothing happens.
thx in adv.

Use Isnumeric function. If character is enetered check by following code:
If not Isnumeric(text1.text) then
MsgBox "Only numeric value is allowed"
End if
Mar 21 '07 #2
ansumansahu
149 100+
hi, myself vandana. is there any property of textbox that can allow textbox to accept only numbers. i tried it by setting dataformatting property to number but nothing happens.
thx in adv.
You can also write a separate sub / function that will trap the Ascii value of the key pressed and check it if its a number. Ascii value 48 To 57 allow numbers.

thanks
ansuman sahu
www.mindfiresolutions.com
Mar 21 '07 #3
vijaydiwakar
579 512MB
hi, myself vandana. is there any property of textbox that can allow textbox to accept only numbers. i tried it by setting dataformatting property to number but nothing happens.
thx in adv.
No
here i'm giving u the best solution so far
Expand|Select|Wrap|Line Numbers
  1.  
  2. if instr(validstr,chr(skeyascii))=0 then 
  3. 'code to supress the keyascii
  4. else
  5. 'return same keyascii
  6. end if
  7.  
See this is the help line only now its ur duty to implement it further
Good Luck
Mar 21 '07 #4
cmrhema
375 256MB
No
here i'm giving u the best solution so far
Expand|Select|Wrap|Line Numbers
  1.  
  2. if instr(validstr,chr(skeyascii))=0 then 
  3. 'code to supress the keyascii
  4. else
  5. 'return same keyascii
  6. end if
  7.  
See this is the help line only now its ur duty to implement it further
Good Luck
How do anyone rate this code
Private Sub txtR_KeyPress(KeyAscii As Integer)
If (KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii = 8) Then
'keyascii =8 stands for backspace
txtR.Locked = False
Else
txtR.Locked = True
End If
End Sub
Mar 21 '07 #5
devonknows
137 100+
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtR_KeyPress(KeyAscii As Integer)
  2. If  (KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii = 8) Then
  3. 'keyascii =8 stands for backspace
  4. txtR.Locked = False
  5. Else
  6. txtR.Locked = True
  7. End If
  8. End Sub
Instead of locking it change the KeyAscii to 0 which classes as no key was pressed. The other thing i may suggest thinking about is adding something to the txtR_Change() sub so that they cant right click and paste in

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtR_KeyPress(KeyAscii As Integer)
  2.     If Not ( _
  3.         (KeyAscii >= "48" And KeyAscii <= "57") Or (KeyAscii = "8")) Then
  4.         KeyAscii = 0
  5.     End If
  6. End Sub
  7.  
Kind Regards
Devon.
Mar 21 '07 #6
cmrhema
375 256MB
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtR_KeyPress(KeyAscii As Integer)
  2. If  (KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii = 8) Then
  3. 'keyascii =8 stands for backspace
  4. txtR.Locked = False
  5. Else
  6. txtR.Locked = True
  7. End If
  8. End Sub
Instead of locking it change the KeyAscii to 0 which classes as no key was pressed. The other thing i may suggest thinking about is adding something to the txtR_Change() sub so that they cant right click and paste in

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtR_KeyPress(KeyAscii As Integer)
  2.     If Not ( _
  3.         (KeyAscii >= "48" And KeyAscii <= "57") Or (KeyAscii = "8")) Then
  4.         KeyAscii = 0
  5.     End If
  6. End Sub
  7.  
Kind Regards
Devon.


Good suggestion Devon
Thanks
Mar 21 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rookie | last post by:
I need to display several columns of numbers in a textbox. I wish to display the columns with the decimal point position aligned vertically. I have found that the # digit placeholders do not...
0
by: Navin | last post by:
Hi, I am making a code editor in C# and want to display line numbers to the left. I have a UserControl with a ListView docked to the left edge and a TextBox that makes up the rest. I am able to...
13
by: Supra | last post by:
how do i get 2 different number in same row? using random example: 4 2 5 6 7 4 1 7 9 8 3 3 <===== i want different number but not same as opposite 8 5
17
by: Ron | last post by:
I want to write a program that will accept a number in a textbox for example 23578 and then in a label will display the sum of the odd and even number like this... the textbox containsthe number...
5
by: Michael R | last post by:
Searching the net I've found a simple technique to add row numbers and alternate colors (for the even and the uneven row) to a continuous form. 1st step: Create a textbox, send it to background...
5
by: rn5a | last post by:
A Web Form has a TextBox within a DataGrid wherein users are expected to enter only whole numbers. It should be validated so that the TextBox doesn't remain blank or any non-numeric data is...
1
by: Luzuko | last post by:
I would like to know how can i restrict textbox input in VB.net using code instead of VB.net controls. e.g If i want a user to type numbers only in a textbox(ID number textbox), how can i make...
2
by: Vbbeginner07 | last post by:
Hi all Wonder if anyone can help me out to solve this: please find the code of textbox that accepts only characters and one textbox that accepts only numbers: (vb) textbox for accepting...
9
by: =?Utf-8?B?R2Vla0JveQ==?= | last post by:
I did not see another group for this so I presume this is the correct one to ask such a question. Anyway, I need to get data entered into a textbox and put it all into an array. I have looked...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.