-
Jun 21st, 2006, 02:07 PM
#1
Thread Starter
Hyperactive Member
Validation in a TextBox
Hi All
how to make to entries only for numbers - I know
but how to prevent entries to textbox first character as the dot
e.g.
.125
also how to prevent entries many of the dots
e.g.
1.25..2
this I don't know
I wanted that permissible an record would be only something like this e.g.:
0.569 or 1.23 or 125.123 or 33.45 or 1.236547 or 0.0034 etc, etc
how to make?
Thanks in advance
I know, I know, my English is bad, sorry .....
-
Jun 21st, 2006, 02:17 PM
#2
Re: Validation in a TextBox
would a simple
VB Code:
Private Sub Text1_Validate(Cancel As Integer)
Cancel = Not IsNumeric(Text1.Text)
End Sub
suffice?
-
Jun 21st, 2006, 03:00 PM
#3
Addicted Member
Re: Validation in a TextBox
well this will stop more than 1 "." ill have a look at the formatting
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 8 Then
If InStr(1, Text1, ".") And KeyAscii = 46 Then KeyAscii = 0
If Not IsNumeric(Chr$(KeyAscii)) And KeyAscii <> 46 Then KeyAscii = 0
End If
End Sub
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.
-
Jun 21st, 2006, 03:09 PM
#4
Addicted Member
Re: Validation in a TextBox
Code:
Private Sub Form_Load()
Text1.Alignment = 1
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 8 Then
If InStr(1, Text1, ".") And KeyAscii = 46 Then KeyAscii = 0
If Not IsNumeric(Chr$(KeyAscii)) And KeyAscii <> 46 Then KeyAscii = 0
End If
If Mid$(Text1, 1, 1) = "." Then
Text1.Text = "0" & Text1
Text1.SelStart = Len(Text1)
End If
End Sub
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.
-
Jun 21st, 2006, 03:13 PM
#5
Thread Starter
Hyperactive Member
Re: Validation in a TextBox
thanks for replies for both
@Rich2189 - your code it works fine
@Bush - hmmm, maybe that your code it's a very good, but ...sorry I don't know how I can it use.
Thanks
I know, I know, my English is bad, sorry .....
-
Jun 21st, 2006, 03:28 PM
#6
Thread Starter
Hyperactive Member
Re: Validation in a TextBox
Me again, Tamgovb
I wonder how I can with one code "to make short of" all the textboxes on a form
I know, I know, my English is bad, sorry .....
-
Jun 21st, 2006, 03:44 PM
#7
Re: Validation in a TextBox
Explain "make short of". Make them all blank?
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jun 21st, 2006, 04:30 PM
#8
Thread Starter
Hyperactive Member
Re: Validation in a TextBox
No, ah my English!
I don't know how it should be in a language of English
"to take care of", "to fix" , " to arrange an.." or "I'll arrange for..."- I expressed probably not correctly, it not has properly a essential meaning
Saying simply - I thought about making
hope that you understand me
thanks
Last edited by Tamgovb; Jun 21st, 2006 at 04:35 PM.
I know, I know, my English is bad, sorry .....
-
Jun 21st, 2006, 05:12 PM
#9
Fanatic Member
Re: Validation in a TextBox
Try making your text boxes in an array, then just change the code to fit that.
VB Code:
Private Sub Text_KeyPress(Index as Integer, KeyAscii As Integer)
If KeyAscii <> 8 Then
If InStr(1, Text(Index), ".") And KeyAscii = 46 Then KeyAscii = 0
If Not IsNumeric(Chr$(KeyAscii)) And KeyAscii <> 46 Then KeyAscii = 0
End If
If Mid$(Text(Index), 1, 1) = "." Then
Text(Index).Text = "0" & Text1
Text(Index).SelStart = Len(Text(Index))
End If
End Sub
Just make all of your text boxes named "text"
BTW, "To take care of" is a perfect description. If I had to explain myself in another language, I wouldn't even come close to being able to.
Visit here to learn to make the VB interface fit you!.
"I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
"The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge
-
Jun 21st, 2006, 05:15 PM
#10
Re: Validation in a TextBox
I'm still not understanding you, but if you want to do something to all text boxes on a form
VB Code:
Dim txt As Control
For Each txt In Controls
If TypeOf txt Is TextBox Then
txt.Text = "This is a textbox" 'or whatever you want to do with them
'if you want to do different things to some of them ...
If txt.Name = "Text1" Then
'do something with textbox Text1
End If
End If
Next txt
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jun 22nd, 2006, 02:15 PM
#11
Thread Starter
Hyperactive Member
Re: Validation in a TextBox
Hi All
I want to be able to write into textboxes only any numbers with the sign of dot (it's decimal) and I want to make only one the code for these all of textbox on a form.
sorry, please about the leniency for me, I have very hard a week (I broke my car, damn...) and a difficult it me understand something, I'm sorry
I got the code but where I should it to put, sorry, I don't know
Simply, I don't know how to do
thanks in advance
I know, I know, my English is bad, sorry .....
-
Jun 22nd, 2006, 02:18 PM
#12
Addicted Member
Re: Validation in a TextBox
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.
-
Jun 22nd, 2006, 02:32 PM
#13
Thread Starter
Hyperactive Member
Re: Validation in a TextBox
Thanks, but I get the error
'Argument not optional'
in a line
VB Code:
Text(Index).Text = "0" & Text1
P.S. I wanted to use with post #10
Last edited by Tamgovb; Jun 22nd, 2006 at 02:36 PM.
I know, I know, my English is bad, sorry .....
-
Jun 22nd, 2006, 03:10 PM
#14
Addicted Member
Re: Validation in a TextBox
well in order to use the code in post 9 you need to make your textboxes into a control array. Or if you dont want to do that use the code in post 10 .
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.
-
Jun 22nd, 2006, 03:13 PM
#15
Thread Starter
Hyperactive Member
Re: Validation in a TextBox
Me again
okay, I found mistake
in this line it should be:
VB Code:
Text(Index).Text = "0" & Text[B](Index).Text[/B]
thanks
I know, I know, my English is bad, sorry .....
-
Jun 22nd, 2006, 03:21 PM
#16
Re: Validation in a TextBox
I do it a completely different way.
I made a custom control using one textbox, checking for numbers and "." only, only 1 ".", allowing backspace, arrow and delete keys, etc. (and I can set the number of decimal places the control will allow). Then I use that control instead of a textbox. The control does all its own checking, so the program using it doesn't have to.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jun 22nd, 2006, 03:36 PM
#17
Thread Starter
Hyperactive Member
Re: Validation in a TextBox
I wonder still how I can use a code from the post # 10, in what place (event) I should then use it.
Where to use the code refer to all controls of the same type, for e.g.
I want to use something like this:
VB Code:
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is CommandButton Then
If ctrl.Tag = "1" Then
ctrl.Enabled = False
End If
End If
Next
or
VB Code:
Dim txt As Control
For Each txt In Controls
If TypeOf txt Is TextBox Then
txt.Text = "This is a textbox" 'or whatever you want to do with them
'if you want to do different things to some of them ...
If txt.Name = "Text1" Then
'do something with textbox Text1
End If
End If
Next txt
where to place this?
Because alone this code will not to work, must be in a some the event, where? I don't understand this
Thanks
I know, I know, my English is bad, sorry .....
-
Jun 22nd, 2006, 03:39 PM
#18
Re: Validation in a TextBox
In the Form_KeyPress event. You have to make Form.KeyPreview True, either during design, or during form load.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jun 22nd, 2006, 03:45 PM
#19
Thread Starter
Hyperactive Member
Re: Validation in a TextBox
If I will place in form only this code, then not will be working.
It to what ( you could or one should) to connect this?
thanks
I know, I know, my English is bad, sorry .....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|