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

text box problems..

1
I am a beginner at making programs.
I am learning visual basic bymyself . I was making a conversion program and i wanted only numericals should be entered into the textbox. Can anyone please answer in brief.
Jul 29 '06 #1
8 4320
BSOB
77
i think there is a way to limit the things that are put into a text box with text1.dataformat but what ive always used is:

text1_lostfocus()
text1.text = val(text1.text)
end sub

ins>outs:
k>0
1.3>1.3
k2>0
3.90k>3.9
3 2>3
(im using k as a random letter representing any text that is not numerical)
Jul 30 '06 #2
sashi
1,754 Expert 1GB
Hi there,

i would suggest to use the IsNumeric function by means to validate numeric data instead of Val function.. :)

Expand|Select|Wrap|Line Numbers
  1.   If IsNumeric(text1.text) = False Then
  2.     ..  some message here ..
  3.   EndIf
  4.  
Jul 30 '06 #3
If IsNumeric(text1.text) = True[u] Then
.. some message here ..
End If

sashi, questioner want to enter only numeric values. so make a little bit change

Mahesh
Jul 31 '06 #4
Stampy
3
You may also want to try just using the maskedtextbox control instead of the textbox. This control has a mask property that you can customize to only allow numeric input, zip code/ telephone number formats, etc.
Jul 31 '06 #5
sashi
1,754 Expert 1GB
Hi Mahesh,

i understood the question clearly as it sounds.. IsNumeric function will help when it comes to datatype validation.. if numeric data is entered proceed with the nextstep or else prompt an error message asking the input to be corrected.. :)
Aug 1 '06 #6
BSOB
77
ive always tried not to bother my users with messaging telling them they are incompitant. they usualy already know that. i use val, so if they enter bad data, it goes to a default zero or null. the default value can be changed in code as desired. or, the default could be to clear the feild to let them know the data has not been set:
if str(val(text1)) <> text1 then text1 = ""
Aug 1 '06 #7
this one filters the textbox from any non-numerical values:
"If IsNumeric(text1.text) = false then..."

this one filters the keypress in the textbox: (you can press backspace and enter)
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 58 Or (KeyAscii <= 47 And KeyAscii <> 8 And KeyAscii <> 13)_
Then
KeyAscii = 0
End If
End Sub

hope that help you...
Aug 2 '06 #8
JWL48
1
You may also want to try just using the maskedtextbox control instead of the textbox. This control has a mask property that you can customize to only allow numeric input, zip code/ telephone number formats, etc.
Great reply!!! The "normal textbox" DataFormat seems to be very weakly implemented. Why butt your head against it when the other control is begging to be used! Thanks again - and a free cold "cyber beer" to you!
Oct 31 '06 #9

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

Similar topics

0
by: Pierre Jelenc | last post by:
I have a blog script that is a customized version of Word Press (wordpress.org) at http://www.web-ho.com/blog/ Because of the way it evolved, some of the CSS may not be the best, I have tended...
8
by: levski | last post by:
As obviously vertical allign is not meant to do this, what are my options ?
3
by: Wade G. Pemberton | last post by:
Help!: I use javascript to format repetitive data from a web page input FORM into a long string , and save it as lines of comma delimited data in a text file on a Unix server. The text...
4
by: sweep | last post by:
Hi there, I have a problem with some CSS I'm writing and I was looking for a little help. I have a nav bar at the top and left side of my page in CSS which work fine. The remaining space has a...
31
by: Claude Yih | last post by:
Hi, everyone. I got a question. How can I identify whether a file is a binary file or an ascii text file? For instance, I wrote a piece of code and saved as "Test.c". I knew it was an ascii text...
0
by: David | last post by:
Hello all. I am trying to implement my first server control and have run into two problems that I cannot solve. I need the assistance of someone with more experience. My goal was to create an...
29
by: list | last post by:
Hi folks, I am new to Googlegroups. I asked my questions at other forums, since now. I have an important question: I have to check files if they are binary(.bmp, .avi, .jpg) or text(.txt,...
2
by: Slain | last post by:
I have a big list of HTML files, which need to be updated with a common text. <script language=JavaScript src="./highlight.js"></script> I need to add the above line in each of the html...
1
by: Xah Lee | last post by:
Text Processing with Emacs Lisp Xah Lee, 2007-10-29 This page gives a outline of how to use emacs lisp to do text processing, using a specific real-world problem as example. If you don't know...
7
by: kirkgilbert | last post by:
I am trying to do an onchange event in a form using a text field. The form is tied to a record set that is part of a repeated region. One the first record when I edit the data it works perfectly. ...
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:
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?
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
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.