|
-
Dec 5th, 2010, 05:10 AM
#1
Thread Starter
Hyperactive Member
[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
-
Dec 5th, 2010, 05:19 AM
#2
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
-
Dec 5th, 2010, 05:25 AM
#3
Thread Starter
Hyperactive Member
Re: Controlled Input
fails with wrong result. eg.allows continue with data missing
-
Dec 5th, 2010, 08:10 AM
#4
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:
 Originally Posted by RocketRon
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
-
Dec 5th, 2010, 09:06 AM
#5
Thread Starter
Hyperactive Member
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?
-
Dec 5th, 2010, 09:27 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|