473,387 Members | 1,864 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,387 software developers and data experts.

how to trap this?

in a textbox, users should input numbers and if letters are inputted, it will create an error that only numbers are accepted. please help me. i am using vb6 and windows xp. thanks.
Sep 30 '08 #1
6 1336
jg007
283 100+
you could catch the ascii code of the entered character and then remove the last character entered if it is not within the right values.

I have got some VB .net code to do this that I have worked out but I would rather you tried to do this yourselft and post any code that you are having problems with as it does not help you if I post the full code

if it is numeric you might also be able to use ' isnumeric ' rather than actually checking the ascii code
Sep 30 '08 #2
There is actually a code that you can place in the keypress event for the text box that will limit it to only accepting numbers, delete and backspace. As jg007 said... attempt to work it out and let us know where you get and we can help you more from there. Or show us what you already have that you're trying to use to do so.
Sep 30 '08 #3
its ok guys.. i used the vbkey constants so that any values entered other than the supposed to be values only would be "cleared" right away.
Oct 2 '08 #4
jg007
283 100+
please can you post your code on here as I don't think I have used that before and it would be interesting to see.
Oct 2 '08 #5
Private Sub BurnText1_KeyUp(KeyCode As Integer, Shift As Integer)

If (KeyCode >= 48 And KeyCode <= 57) Or (KeyCode >= 96 _
And KeyCode <= 105) Or (KeyCode = 8) Or (KeyCode = 32) Or (KeyCode = 191) _
Or (KeyCode = 110) Then
Else
BurnText1.Text = ""
End If
End Sub

that's the code i've used and it works like a charm.. now, if you want to trap for letters only to be inputted, you should change the constant values. not all constant values are readily available in vb6 so you have to research for a list of keycode constant values,.

hope this helps.
Oct 5 '08 #6
jg007
283 100+
your code is great and will work but as a reminder that there are always plenty of way to do something :) , this could be easily amended to allow letters only although would require extra code to avoid special character

this code also avoids clearing the textbox when invalid characters are entered -

that is the fun thing of programming trying to work out how to achieve a goal and although I just use whatever works for me several months down the line I inevitably find another way to do it

Expand|Select|Wrap|Line Numbers
  1.  
  2.  Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  3.  
  4.         If Not IsNumeric(e.KeyChar) Then
  5.             e.KeyChar = Nothing
  6.         End If
  7.  
  8.     End Sub
  9.  
  10.  
Oct 5 '08 #7

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

Similar topics

10
by: Mike D | last post by:
I have a table in SQL 2000 with a composite Primary Key on coulumns Instrument_ID (int) and WeekOf (smalldatetime.) I am running asp on win 2003. I insert values using a stored procedure from...
2
by: aj | last post by:
DB2 WSE LUW 8.1 Fixpak 5 Red Hat AS 2.1 Has anyone ever seen a db2diag.log indicate that a trap file was written, but it is *not* written? For the 3rd time in 18 months, I had a production...
11
by: pemo | last post by:
Ambiguous? I have a student who's asked me to explain the following std text (esp. the footnote). 6.2.6.1.5 Certain object representations need not represent a value of the object type. If...
2
by: ramu | last post by:
Hi, I read the phrase " trap representation" in the topic "Union arrangement" in this group. Can you please tell me what do you mean by it? regards
10
by: pemo | last post by:
As far as I understand it, a trap representation means something like - an uninitialised automatic variable might /implicitly/ hold a bit-pattern that, if read, *might* cause a 'trap' (I'm not...
6
by: temper3243 | last post by:
Hi Can someone explain me what is happening below ? Why is it printing 401380 $ cat scanf.c #include<stdio.h> int main() { int i; scanf(" %d",&i);
17
by: Army1987 | last post by:
If uMyInt_t is an unsigned integral type, is the following a necessary and sufficient condition that uMyInt_t has no trap representation? (uMyInt_t)(-1) >CHAR_BIT*sizeof(uMyInt_t)-1 That is,...
6
by: John | last post by:
In a form how I can I trap for the action that a user opens the built in 'find dialog'? I would like to trap for it and before the dialog shows up, I would like to execute some code, and after that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...

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.