If statement!

Leeus

Regular
Joined
Dec 23, 2002
Messages
50
Code:
Do While DR.Read()

            If Not DR.Item("Date Due") Is DBNull.Value Then
                If DR.Item("Date Due") < ThisMoment Then
                    If Not DR.Item("org_account_mgr") Is DBNull.Value Then
                        If Not DR.Item("org_account_mgr") = "RESELLER" Then
                            If Not DR.Item("org_account_mgr") = "none" Then
                                TextBox1.Text &= vbCrLf & DR.Item("SupportKey") & "," & DR.Item("Date Due") & "," & DR.Item("ShortDesc") & ",OVERDUE," & DR.Item("org_account_mgr") & " - " & txttime.Text
                                msgbody &= "Support Key: <A HREF='http://kermit/support/default.asp?LogNumber=" & DR.Item("SupportKey") & "'>" & DR.Item("SupportKey") & "</A>, Due on Date: " & DR.Item("Date Due") & "<BR>For Company: " & DR.Item("org_name") & ", With Description: " & DR.Item("ShortDesc") & "<BR><BR>"
                                mailsender(DR.Item("org_account_mgr") & "@twang.net", "Support Key: <A HREF='http://kermit/support/default.asp?LogNumber=" & DR.Item("SupportKey") & "'>" & DR.Item("SupportKey") & "</A>, Due on Date: " & DR.Item("Date Due") & "<BR>For Company: " & DR.Item("org_name") & ", With Description: " & DR.Item("ShortDesc") & "<BR><BR>", "Support has an overdue item for one of your customers")
                            Else
                                TextBox1.Text &= vbCrLf & DR.Item("SupportKey") & "," & DR.Item("Date Due") & "," & DR.Item("ShortDesc") & ",OVERDUE" & " - " & txttime.Text
                                msgbody &= "Support Key: <A HREF='http://kermit/support/default.asp?LogNumber=" & DR.Item("SupportKey") & "'>" & DR.Item("SupportKey") & "</A>, Due on Date: " & DR.Item("Date Due") & "<BR>For Company: " & DR.Item("org_name") & ", With Description: " & DR.Item("ShortDesc") & "<BR><BR>"
                            End If
                        End If
                    End If
                Else
                    TextBox1.Text &= vbCrLf & DR.Item("SupportKey") & "," & DR.Item("Date Due") & "," & DR.Item("ShortDesc") & " - " & txttime.Text
                End If
            End If

        Loop

This is causing me grief, what I essentially want it to do is if that account manager is not blank, or "RESELLER" or "none" then don't send an e-mail using the sub mailsend, but always but an audit in the textbox1.text.

At present it seems to miss off records, etc. Is there a better way to do this, i.e. one that works?
 
Why are all these records coming back from the database? You have five separate conditions that you're bringing all the records back only to exclude. Seems like you'd be better off using a where clause in the DB instead. Either way, it's kinda tough to tell exactly what you want to happen with all of the nested conditionals. It looks like some should be sibling conditionals (ie. Condition1 AND Condition2) instead of nested. I guess the question is what do you want to happen if they are a RESELLER? none? null?
 
I have used the following "design pattern" ages ago to avoid deeply nested if-clauses:

Visual Basic:
Private processMe as boolean

For each obj in LargeCollection
  processMe = true
  if (condition) then 
    perfom exit actions
    processMe = false
 end if
 
 if processMe then 
   if (nextCondition) then
     perform exit actions
     processMe = false
   end if
end if

 if processMe then 
   if (thirdCondition) then
     perform exit actions
     processMe = false
   end if
end if

etc. 

next obj
 
That's a little clearer, albeit quite verbose, method, but I still think this many nested conditionals indicates a larger problem, in this case possibly working with more data than he needs. If for whatever reason, he can't just only bring back the data he actually needs, then I'd suggest throwing some Boolean operators in the equation.
 
Back
Top