CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: TextBox Array

  1. #1
    Join Date
    Jul 2001
    Location
    British Columbia, Canada
    Posts
    19

    TextBox Array

    I have an array of four TextBoxes. I made them an array so that I could reduce my code by writing the Validation event sub function only once. Unfortunately, VB seems to insist that I specify a single member of the array for my validation code. If I have to do that, then I'll wind up writing the code four times anyway so what's the point? I'm thinking that there has got to be some way to indicate that the index of the control doesn't matter. Anyway, here's my code so far:

    private Sub txtXY_Validate(Index as Integer, KeepFocus as Boolean)
    If Not IsNumeric(txtXY(0).Text) Or Val(txtXY(0).Text) < -250 Or Val(txtXY(0).Text) > 250 then
    KeepFocus = true
    Call MsgBox("Please enter a number between -250 and 250, inclusive.", , "Line Generator")
    End If
    End Sub



    I would like to avoid writing that If...Then statement three more times, if possible.

    Thanks for any help, and feel free to ask for clarification.





    The more you know, the more you know you don't know.
    The more you know, the more you know you don't know.

  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: TextBox Array

    (Index as Integer) specifies which of the Textboxes you are working with so replace

    If Not IsNumeric(txtXY(0).Text) Or Val(txtXY(0).Text) < -250 Or Val(txtXY(0).Text) > 250 then
    '
    ' with
    If Not IsNumeric(txtXY(Index).Text) Or Val(txtXY(Index).Text) < -250 Or Val(txtXY(Index).Text) > 250 then



    This will then cause your code to be working with whatever textbox the user is playing with.


    John G

  3. #3
    Join Date
    Jul 2001
    Location
    British Columbia, Canada
    Posts
    19

    Thank you!

    That's just what I needed. What a relief. I knew there had to be a simple solution.





    The more you know, the more you know you don't know.
    The more you know, the more you know you don't know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured