PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Validation in a TextBox-VBForums
Results 1 to 19 of 19

Thread: Validation in a TextBox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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 .....

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Validation in a TextBox

    would a simple
    VB Code:
    1. Private Sub Text1_Validate(Cancel As Integer)
    2.     Cancel = Not IsNumeric(Text1.Text)
    3. End Sub
    suffice?

  3. #3
    Addicted Member
    Join Date
    Feb 2006
    Location
    The Sea of Tranquility
    Posts
    252

    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.

  4. #4
    Addicted Member
    Join Date
    Feb 2006
    Location
    The Sea of Tranquility
    Posts
    252

    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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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 .....

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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 .....

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    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

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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 .....

  9. #9
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking Re: Validation in a TextBox

    Try making your text boxes in an array, then just change the code to fit that.

    VB Code:
    1. Private Sub Text_KeyPress(Index as Integer, KeyAscii As Integer)
    2. If KeyAscii <> 8 Then
    3. If InStr(1, Text(Index), ".") And KeyAscii = 46 Then KeyAscii = 0
    4. If Not IsNumeric(Chr$(KeyAscii)) And KeyAscii <> 46 Then KeyAscii = 0
    5. End If
    6.  
    7. If Mid$(Text(Index), 1, 1) = "." Then
    8. Text(Index).Text = "0" & Text1
    9. Text(Index).SelStart = Len(Text(Index))
    10. End If
    11.  
    12. 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

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    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:
    1. Dim txt As Control
    2.  
    3.   For Each txt In Controls
    4.     If TypeOf txt Is TextBox Then
    5.       txt.Text = "This is a textbox" 'or whatever you want to do with them
    6.       'if you want to do different things to some of them ...
    7.       If txt.Name = "Text1" Then
    8.         'do something with textbox Text1
    9.       End If
    10.     End If
    11.   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

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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 .....

  12. #12
    Addicted Member
    Join Date
    Feb 2006
    Location
    The Sea of Tranquility
    Posts
    252

    Re: Validation in a TextBox

    This post http://www.vbforums.com/showpost.php...26&postcount=9 is the answer to what you require.
    Rich

    A)bort, R)etry, I)nfluence with large hammer.
    Please take a moment to rate useful posts.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: Validation in a TextBox

    Thanks, but I get the error

    'Argument not optional'

    in a line

    VB Code:
    1. 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 .....

  14. #14
    Addicted Member
    Join Date
    Feb 2006
    Location
    The Sea of Tranquility
    Posts
    252

    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.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: Validation in a TextBox

    Me again

    okay, I found mistake

    in this line it should be:

    VB Code:
    1. Text(Index).Text = "0" & Text[B](Index).Text[/B]

    thanks
    I know, I know, my English is bad, sorry .....

  16. #16
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    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

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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:
    1. Dim ctrl As Control
    2. For Each ctrl In Me.Controls
    3.     If TypeOf ctrl Is CommandButton Then
    4.       If ctrl.Tag = "1" Then
    5.          ctrl.Enabled = False
    6.       End If
    7.     End If
    8. Next

    or

    VB Code:
    1. Dim txt As Control
    2.  
    3.   For Each txt In Controls
    4.     If TypeOf txt Is TextBox Then
    5.       txt.Text = "This is a textbox" 'or whatever you want to do with them
    6.       'if you want to do different things to some of them ...
    7.       If txt.Name = "Text1" Then
    8.         'do something with textbox Text1
    9.       End If
    10.     End If
    11.   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 .....

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    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

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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
  •  



Featured


Click Here to Expand Forum to Full Width