Solved

If...Then Logic

Posted on 2002-07-19
4
324 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

11 Experts available now in Live!

Get 1:1 Help Now