?
Solved

If...Then Logic

Posted on 2002-07-19
4
Medium Priority
?
333 Views
Last Modified: 2010-05-02
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
Comment
Question by:jtrapat1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Expert Comment

by:ketapillar
ID: 7165856
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
 
LVL 3

Expert Comment

by:ketapillar
ID: 7165862
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
 

Accepted Solution

by:
CarterMitchell earned 400 total points
ID: 7166715
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
 

Author Comment

by:jtrapat1
ID: 7170031
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question