473,804 Members | 3,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SENSING TEXT BOX DATA TYPE?

hi,

I HAVE A TEXT BOX THAT I WANT THE USER TO ENTER A NUMBER IN.
HOW DO I PREVENT RUN TIME ERROR IF THEY ENTER A STRING INSTEAD?
I GUESS I NEED SOME TYPE OF DATA TYPE SENSING COMMAND BUT I
DONT KNOW WHAT IT IS.
jco
Jul 17 '05 #1
3 4542
Private Sub Text1_KeyPress( KeyAscii As Integer) If (KeyAscii < 48 Or
KeyAscii > 57) And KeyAscii <> 46 Then KeyAscii = 0 End IfEnd
Sub"J. C. O'Connell" <hi******@gate. net> wrote in message
news:3f******** ******@news.gat e.net...> hi,

I HAVE A TEXT BOX THAT I WANT THE USER TO ENTER A NUMBER IN.
HOW DO I PREVENT RUN TIME ERROR IF THEY ENTER A STRING INSTEAD?
I GUESS I NEED SOME TYPE OF DATA TYPE SENSING COMMAND BUT I
DONT KNOW WHAT IT IS.
jco

Jul 17 '05 #2
Kris,

Whoops ... I left off a conversion (chr$(KeyAscii) ). Use this instead.

It's a few more keystrokes than the other example (which is also valid
except for the backspace) but it is good programming practice to write your
code so if someone else comes along they can understand the intent. While
this is an overly simple section of code, developing that habit will pay
off. The extra time making code clear can pay off big-time later when
trying to find bugs.

Private Sub Text1_KeyPress( KeyAscii As Integer)
'
' Invalidate keystroke if not a digit, decimal point or backspace.
'
If (Not IsNumeric(chr$( KeyAscii)) And (chr$(KeyAscii) <> "." And
KeyAscii <> vbBack)) Then
KeyAscii = 0
Endif

End Sub

HTH,

-bruce

"Kris M" <ma******@yahoo .com> wrote in message
news:bY******** ************@co mcast.com...
Private Sub Text1_KeyPress( KeyAscii As Integer) If (KeyAscii < 48 Or
KeyAscii > 57) And KeyAscii <> 46 Then KeyAscii = 0 End IfEnd
Sub"J. C. O'Connell" <hi******@gate. net> wrote in message
news:3f******** ******@news.gat e.net...> hi,

I HAVE A TEXT BOX THAT I WANT THE USER TO ENTER A NUMBER IN.
HOW DO I PREVENT RUN TIME ERROR IF THEY ENTER A STRING INSTEAD?
I GUESS I NEED SOME TYPE OF DATA TYPE SENSING COMMAND BUT I
DONT KNOW WHAT IT IS.
jco


Jul 17 '05 #3
Close ... the user needs to be able to backspace as well. Also - write the
code so someone else can read it.

Private Sub Text1_KeyPress( KeyAscii As Integer)
'
' Invalidate keystroke if not a digit, decimal point or backspace.
'
If (Not IsNumeric(chr$( KeyAscii)) And (KeyAscii <> "." And KeyAscii <>
vbBack)) Then
KeyAscii = 0
Endif

End Sub

"Kris M" <ma******@yahoo .com> wrote in message
news:bY******** ************@co mcast.com...
Private Sub Text1_KeyPress( KeyAscii As Integer) If (KeyAscii < 48 Or
KeyAscii > 57) And KeyAscii <> 46 Then KeyAscii = 0 End IfEnd
Sub"J. C. O'Connell" <hi******@gate. net> wrote in message
news:3f******** ******@news.gat e.net...> hi,

I HAVE A TEXT BOX THAT I WANT THE USER TO ENTER A NUMBER IN.
HOW DO I PREVENT RUN TIME ERROR IF THEY ENTER A STRING INSTEAD?
I GUESS I NEED SOME TYPE OF DATA TYPE SENSING COMMAND BUT I
DONT KNOW WHAT IT IS.
jco


Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
6936
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the JavaScript in this code from a couple different sites but I'm not 100% sure what each line is doing...This is the ASP code that I'm using for the page....Take a look at the JavaScript code and please let me know what each line is doing....I have been...
6
2713
by: Rod Snyder | last post by:
I'm trying to set up an asp.net (vb.net) that will allow a user to insert/update a bio/profile. I wanted to create a SQL Server 2000 table that includes their contact info and bio info. However, I'm not getting SQL Server to accept more than about two paragraphs of info. I've tried the datatypes of ntext and nvar char to no success. I'm presuming most people will be cutting and pasting from a Word document also. Does anyone have any...
14
2371
by: Joe | last post by:
Hello All: I am trying to dynamically populate a web page with literal content and controls (textboxes and checkboxes (and eventually two buttons - the buttons do not appear in the code yet). I read an xml file and, using the values retrieved from it, determine what text should be displayed and which controls should be rendered and - most importantly - where those controls should be rendered. The ultimate goal is to have some text...
2
936
by: Strah | last post by:
Is there a way to make my VB.NET application aware when user is logging off? I would like to have my app save some data to the network's database before the user logs off without closing application. Currently, if the user logs off my app will close without any saving data, which I would like to precede. Thanks, Strah
2
2138
by: Sethos | last post by:
I am sure that this has been covered, hashed, and rehashed, but a search on the group did not produce the answer, so forgive me if this seems like a "newbie" type question... Besically, I have a form on which the users can click on a button to add text boxes dynamically. That all works without a hitch. The problem comes in trying to verify the information in the boxes. Below is a very abbreviated example of the code I have in the form:
4
1551
by: srikanthv | last post by:
I have below Sample text. I need find in the text specfic "Key name" its Value "HKEY_CURRENT_USER\Control Panel\International", If I find this I need to go inside of this and read Value 0 (Name: Its value and Data: Its value),Value 1 (Name: Its value and Data: Its value)....Value N (Name: Its value and Data: Its value). Please provide me same code for this. Sample -------
1
1700
by: Jamad | last post by:
I want to extract some information in a text file that is not tab, comma and space separated. The format of the text file is actually unknown. The problem now is, i want to extract like three lines from each section of the text file content, break the lines into different part and use the broken info to populate an already created table in ms access ( all these should be carried out at a press of a cmd button using VBA code in access or VB...
3
2667
by: jonniethecodeprince | last post by:
Hi all, I have trouble getting an array of data stored in a separate javascript file i.e. a file called books.js into a table of data for a .xhtml file. There are 50 Records in this file. There are 5 colums of data I wish to display. I want to display these records in groups of 10. Based on the fact that the records I want are located in a separate file, how can I get these details to show on the form and manipulate the data to...
0
9704
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
10562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
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
10303
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,...
1
7608
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5508
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
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
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.