473,480 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

getting only numbers by textbox.

21 New Member
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 6066
Shailja
123 New Member
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 New Member
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 Contributor
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 Contributor
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 New Member
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 Contributor
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
18136
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
1408
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
1491
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
4592
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
27517
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
1493
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
2336
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
7919
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
743
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
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7059
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,...
1
6758
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...
0
7010
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4499
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3011
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3003
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.