• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

If...Then Logic

I'm using VB6 against an SQL Server database.
Here are the specs I'm using to try and write an if..then block but I just can't get the logic down.
------------------------------------------------------
Specs:
If ParentCode = "MISCA" AND AgencyCode <> "MISCA" Then SubCommittee and AppropBill textfields must be filled in.
If ParentCode <> "MISCA" AND ParentCode = AgencyCode Then
If AgencyCode = "MISCA" Or ParentCode <> AgencyCode Then ParentCode can be blank.
-------------------------------------------------------
Here's what I have so far but I know it's very wrong:
(My GetDescription function simply looks up the SubCommittee code and populates the SubComm textbox)
And I wanted Check_Textboxes to popup a message field to alert the user that the SubCommittee and AppropBill textfields must be filled in.
-------------------------------------------------------
'By Default, move Agency Code into Parent Code
                If txtParentCode = "" Then
                    txtParentCode = txtCode
                Else
                    If txtParentCode = "MISCA" And txtCode <> "MISCA" Then
                        Check_Textboxes
                    Else
                        cmbSubComDesc = GetDescription("SubCommittees", txtSCCode, "")

                        If txtParentCode <> "MISCA" And txtParentCode <> txtCode Then
                           
                        End If
                    End If
                End If
-----------------------------------------------------

Can someone help with this logic?
Thanks in Advance
John
0
jtrapat1
Asked:
jtrapat1
  • 2
1 Solution
 
ketapillarCommented:
Was this what you were wanting?

If txtParentCode = "" Then
    txtParentCode = txtAgencyCode
ElseIf txtParentCode = "MISCA" And txtAgencyCode = "MISCA" Then
    'Code goes here
ElseIf txtParentCode <> "MISCA" And txtParentCode = txtAgencyCode Then
    'Code goes here
ElseIf txtAgencyCode = "MISCA" Or txtParentCode <> txtAgencyCode Then
    'Code goes here
End If
0
 
ketapillarCommented:
err... retry (had = where there was supposed to be <>)

If txtParentCode = "" Then
    txtParentCode = txtAgencyCode
ElseIf txtParentCode = "MISCA" And txtAgencyCode <> "MISCA" Then
    'Code goes here
ElseIf txtParentCode <> "MISCA" And txtParentCode = txtAgencyCode Then
    'Code goes here
ElseIf txtAgencyCode = "MISCA" Or txtParentCode <> txtAgencyCode Then
    'Code goes here
End If
0
 
CarterMitchellCommented:
There appears to be a probelem in the formulation of your specs. The statements:

If (ParentCode <> "MISCA" AND ParentCode = AgencyCode) Then

If AgencyCode = "MISCA" Or ParentCode <> AgencyCode Then ParentCode can be blank.

seem to be contradictory. If the first statement is true (ParentCode = AgencyCode), which must evaluate to true to satisfy the AND operator, the last part of the second statement cannot be true (ParentCode <> AgencyCode) and doesn't need to be included.

Break down the first two spec statements, where "value"  means "MISCA":
ParentCode = "value"....
ParentCode <> "value"....
These are mutually exclusive conditions, and can be expressed as

IF PC = "value" THEN

ELSE
    ' statements for ParentCode NOT EQUAL "value"
END IF

Next,
ParentCode = "value" AND AgencyCode <> "value"....

IF txtParentCode = "value" THEN
     IF txtCode <> "value" THEN
          ' statements
          ' text fields must be filled in - programmatically or by the user
     ELSE
          ' not addressed by specs
     ENDIF
ELSE
     'ParentCode <> "value"
END IF

Next, expand the second branch of the condition
ParentCode <> "value" AND ParentCode = AgencyCode.


ELSE     ' ParentCode NOT equal to "value"  represents the first part of the statment in the second spec.

     ' This statement is the second part of the AND in the second spec
     IF txtParentCode = txtCode    THEN     ' ParentCode EQUAL AgencyCode
         
          ' This next statement codes the first part of the third spec, based on the "Then" at the
          ' end of the second spec can only be evaluated if both
          '          ParentCode <> "value" AND ParentCode = AgencyCode
         
          IF txtCode = "value"
               ' this condition can never attain because this branch has already established that
               ' 1) ParentCode EQUAL "value" and
               ' 2) AgencyCode IS EQUAL ParentCode

          ELSE    
              '  Another case
          END IF
     
     ELSE    
         ' What about the case where ParentCode <> "value" AND ParentCode <> AgencyCode ?
     END IF
END IF

You may need to reconsider your specs, based on what you wrote here.
0
 
jtrapat1Author Commented:
Carter,

Thanks for the response.
You're right  - I do need to go thru my logic some more.

I'll check with my boss and probably post again later.

Thanks
John
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now