473,734 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ 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 6089
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.mindfiresol utions.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(K eyAscii 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
18196
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 reserve the spaces for the number if the number of digits are fewer than the number of placeholders. My simplified example: included within a loop such that it displays two columns
0
1440
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 add items to the ListView when a new line is entered in the TextBox (these items are the line numbers). What I am not able to figure out is how to update the view of the ListView when the TextBox starts scrolling vertically. I would like the...
13
1515
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
4624
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 23578 the label would say: Sumof odd number is: 15 Sum of even number is: 10 any ideas?
5
27581
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 and select the first color. .ControlSouce =fRowNum(False) .Name = RowNum 2nd step: Add the following function to the form module: (for row numbers) Public Function fRowNum(Reset As Boolean) As Long Static I As Integer
5
1512
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 entered in the TextBox. If the TextBox doesn't get validated, I want to display messages to the user which should be as precise as possible for the user to easily identify where he erred. This is how I did it: ...
1
2365
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 sure that nothing else besides numbers are typed in the textbox
2
7962
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 characters: If txtname.Text = "" Then MsgBox "enter the name", vbOKOnly, "PAYROLL"
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 and cannot find such an example of how to accomplish this. What I am trying to do it type in a set of numbers (e.g. 10 20 30....) and fill in an array with those numbers.
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.