Results 1 to 6 of 6

Thread: [RESOLVED] Controlled Input

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    445

    Resolved [RESOLVED] Controlled Input

    Hi
    I have a frame on a form with 6 separate inputs which by design items can be selected in any order.
    They are 2 Textbox's for a cash value, 2 options select one or the other a label with a title and a textbox for a number which is not visible after input.
    Google did not have the answer, this is my code but it fails can you help please.

    Select Case .fmePP.Visible = True
    Case True
    If .txtSP5.Text <> "" And .txtSP6.Text <> "" And _
    .lblPP.Caption <> "" And .txtMonthPP.Visible = True And _
    .optWklyPP.Value = True Or .optMthlyPP.Value = True Then
    ppOk = True
    xVisible = xVisible + 1
    Else
    MsgBox msg, 48 + 0, iTitle
    End If
    End Select

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Controlled Input

    this is my code but it fails can you help please.
    fails on error, or wrong result?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    445

    Re: Controlled Input

    fails with wrong result. eg.allows continue with data missing

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Controlled Input

    When you post code please put it inside code tags so it is displayed in a more readable way - either using the Code/VBCode buttons in the post editor screen (or at the top of the Quick Reply box), or by putting them in manually, like this: [code] code here [/code]


    The problem seems to be your If statement, which contains a mixture of And/Or without any brackets:
    Quote Originally Posted by RocketRon View Post
    Code:
                  If .txtSP5.Text <> "" And .txtSP6.Text <> "" And _
                      .lblPP.Caption <> "" And .txtMonthPP.Visible = True And _
                      .optWklyPP.Value = True Or .optMthlyPP.Value = True Then
    This probably means that the overall result will be true if everything before the Or is true, or everything after it (just one item) is true.

    This is presumably what you wanted:
    Code:
                  If .txtSP5.Text <> "" And .txtSP6.Text <> "" And _
                      .lblPP.Caption <> "" And .txtMonthPP.Visible = True And _
                      (.optWklyPP.Value = True Or .optMthlyPP.Value = True) Then

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2010
    Posts
    445

    Re: Controlled Input

    Hi Si the geek
    Thanks for that works fine.
    Just so I understand for the future I needed the brackets because I changed arguments from And to Or is that correct?

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Controlled Input

    It is because you are using a mixture, which means the order matters - just like it does with a mixture of mathematical operations (eg: 3-1*4 could mean: (3-1)*4 = 8 or: 3-(1*4) = -1 ).

    If you want the checks to be done in a certain order (and when using a mixture of And/Or, you usually do), use brackets to specify the order.
    Last edited by si_the_geek; Dec 5th, 2010 at 09:30 AM.

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