Results 1 to 6 of 6

Thread: Further Validation Help [Resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127

    Question Further Validation Help [Resolved]

    I have been looking for syntax help with this:

    Code:
    If Val(TextBox1.Text) = (1,99) Then
                TextBox2.Focus()
            End If
    I would like the the part in red to cause the focus to change when text box 1 value = any of the numbers from 1 to 99.

    Thoughts.....
    Last edited by teamdad; Jun 25th, 2004 at 08:49 PM.

  2. #2
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37
    From the top of my head, didn't check code, just typed it

    If InRange(Val(TextBox1.Text)) Then
    TextBox2.Focus()
    End If

    function InRange(value as integer) as boolean
    dim i as integer

    for i = 1 to 99 do
    if value = i then
    InRange = true
    exit function
    end if
    next

    InRange = false
    end function


    If you can't find a standard function, make your own

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Hope this is not too simple:

    VB Code:
    1. If Val(TextBox1.Text) >=1 and val(TextBox1.Text)<=99 Then
    2.             TextBox2.Focus()
    3.         End If
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37
    D@mn I think too complicated

    If it works the same, always go for the solution with less code

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    It works great.... I don't know what I would ever do without the help I have gotten from this forum.

    I just thought I had ran accross something somewhere with a format from my first post that validated a range of numbers.... maybe it was a range of letters?? Who knows what I think.


  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by teamdad
    It works great.... I don't know what I would ever do without the help I have gotten from this forum.

    I just thought I had ran accross something somewhere with a format from my first post that validated a range of numbers.... maybe it was a range of letters?? Who knows what I think.

    MSDN HELP does mention the use of ranges for all types except Boolean using the format 1 to 99, but I can't figure out how to use it

    If you are going to check the entries in several textboxes and/or want to check against more than one range, then a slight amendment to cphoenixc's suggestion is appropriate:

    VB Code:
    1. If InRange(Val(TextBox1.Text), 1, 99) Then
    2. TextBox2.Focus()
    3. End If
    4.  
    5. function InRange(value1 as integer, range1 As Integer, Range2 As Integer) as boolean
    6. If value1>=range1 and value1,=99 then
    7.   return True
    8. Else
    9.   Return False
    10. End If
    11. End Sub


    I altered "Value" to "Value1" because you should never use a key word as an integer name.
    Last edited by taxes; Jun 22nd, 2004 at 07:30 PM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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