Solved

If...Then Logic

Posted on 2002-07-19
4
325 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
  • 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now