Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Nested Ifs Post Reply Post New Topic
Author Message
steve728
Newbie
Newbie


Joined: 26 Mar 2008
Location: United States
Online Status: Offline
Posts: 4
Quote steve728 Replybullet Topic: Nested Ifs
     Posted: 26 Mar 2008 at 1:33pm

I'm really having trouble using Nested Ifs in the Formula editor.  I'm trying to convert MS Access VBA coding with nested if 3-4 deep.  I need help with the proper use of brackets or parenthesis so that Crystal Reports XI understands what I am doing.  Will someone please send me some examples for me to study?Ouch

Steve728

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 26 Mar 2008 at 3:28pm
If you'll post the If statement you're trying to convert, I might be able to help.
 
-Dell
IP IP Logged
steve728
Newbie
Newbie


Joined: 26 Mar 2008
Location: United States
Online Status: Offline
Posts: 4
Quote steve728 Replybullet Posted: 26 Mar 2008 at 3:40pm
Wow.  Thank you!
 
    Dim strCert As String
    Dim dteMOCCertDate As Date
    Dim blnCert As Boolean
    Dim strMOCExpire As String
    Dim strMOCField As String
    Dim blnInactive As Boolean
    Dim blnActive As Boolean
    Dim strSQL As String
    Dim rstName As Recordset
    Dim rstTemp As Recordset
    Dim blnChangeDOB As Boolean
    Dim i As Integer
    txtCert = ""
    strCert = ""
    i = 0
    blnCert = False
    strCert = strCert '+ vbCrLf
       
        If rstTemp![AppStatus] = "Active" Then
           
            If blnCert = True Then
               
                If InStr(1, rstTemp!FieldCode, "M") > 0 Then
                    strMOCField = rstTemp!CertifName
                    dteMOCCertDate = rstTemp!AppStatusDate
                    strMOCExpire = CStr(rstTemp!ExpireYear)
                    blnChangeDOB = True
                Else
                    strCert = strCert + "In the examination process in " + rstTemp!CertifName
                    txtCert = strCert
                End If
     
            Else
               
                If rstTemp!FieldCode = "PA" Then
                Else
                    If (InStr(1, rstTemp!FieldCode, "M") = 0 And InStr(1, rstTemp!FieldCode, "Z") = 0) Then
                        strCert = strCert + "In the examination process in " + rstTemp!CertifName
                        strCert = strCert + vbCrLf
                        txtCert = strCert
                        blnActive = True
                    Else
                        blnChangeDOB = True
                    End If
                End If
            End If
           
        ElseIf rstTemp![AppStatus] = "Certified" Then
           
            blnCert = True
            i = i + 1
            strCert = strCert + vbCrLf + "Certified:  "
           
            If rstTemp!FieldCode = "DS" Then
                strCert = strCert + rstTemp!CertifNameFormal & ", " & DatePart("yyyy", rstTemp![AppStatusDate])
            Else
                strCert = strCert + rstTemp![CertifName] & ", " & DatePart("yyyy", rstTemp![AppStatusDate])
            End If
            If Not IsNull(rstTemp![ExpireYear]) Then
                strCert = strCert & vbCrLf & Space(16) & "Maintenance of Certification: " _
                    & DatePart("yyyy", rstTemp![AppStatusDate]) & " - " & rstTemp![MOCExpireYear]
                strCert = strCert & " - valid through 12/31/" & rstTemp![ExpireYear] & vbCrLf
                dteMOCCertDate = rstTemp!AppStatusDate
            Else
                strCert = strCert + ", Lifetime"
                strCert = strCert + vbCrLf
            End If
       
       
        ElseIf rstTemp!AppStatus = "Inactive" Then
           
            blnInactive = True
       
        End If
           
IP IP Logged
steve728
Newbie
Newbie


Joined: 26 Mar 2008
Location: United States
Online Status: Offline
Posts: 4
Quote steve728 Replybullet Posted: 27 Mar 2008 at 10:52am

Dear hilfy

To make things easier you can just place the parenthesis in the VBA code so that I have a better idea of how to handle the formulas in CR.  People are discouraging me from using the nested ifs and instead altering the back end SQL stored proc.  Any advise will be helpful.

 
The following is just the top end of my starting conversion:
 
StringVar strCert := '' ;
DateTimeVar dteMOCCertDate ;
BooleanVar blnCert := False ;
StringVar strMOCExpire ;
StringVar strMOCField ;
BooleanVar blnInactive := False ;
BooleanVar blnActive := False ;
NumberVar i := 0 ;
StringVar strTest := '' ;
If {ltrPC_VerificationLetter;1.MOCFlag} = 1 Then     // If MOC
    (
    If {ltrPC_VerificationLetter;1.MOCStatus} = 'Active' Then       
        (
        If blnCert Then
            (
            If InStr({ltrPC_VerificationLetter;1.Field_ID}, "M") > 0 Or InStr({ltrPC_VerificationLetter;1.Field_ID}, "Z") > 0 Then
                (
                strMOCField := {ltrPC_VerificationLetter;1.CertifName} ;
                dteMOCCertDate := {ltrPC_VerificationLetter;1.StatusDate} ;
                strMOCExpire := {ltrPC_VerificationLetter;1.tblMOCExpireYear}
                )       
            Else
                (
                strCert := strCert & "In the examination process in " & {ltrPC_VerificationLetter;1.CertifName})
                )
        Else
            (
            If {ltrPC_VerificationLetter;1.Field_ID} = "PA" Or {ltrPC_VerificationLetter;1.Field_ID} = "PB"
                Or {ltrPC_VerificationLetter;1.Field_ID} = "PC" Or {ltrPC_VerificationLetter;1.Field_ID} = "PE"
                Or {ltrPC_VerificationLetter;1.Field_ID} = "PF" Or {ltrPC_VerificationLetter;1.Field_ID} = "PG" Then
                (
                strTest := "X"
                )
            )
        )
            Else
 
Steve728
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 27 Mar 2008 at 12:26pm
Do you need the variables for other formulas?  Or are the just to put data on the report?
 
This is not really the kind of thing that lends itself well to Crystal formulas - you're trying to calculate a whole bunch of different values in one long If statement and not all values are calcluated for all conditions.  So, because of the way Crystal works, the variables that you're not setting default values for will contain the data from the previous record where they were set.  Also, it doesn't look like bInCert ever has a value of True in the first part of your if statement, so the whole part of the "If bInCert Then..." statement will never be evaluated (even in your original procedure!)
 
So, the question is, what are you really trying to do here?  What is the problem you're trying to solve or the question(s) you're trying to answer?
 
-Dell
IP IP Logged
steve728
Newbie
Newbie


Joined: 26 Mar 2008
Location: United States
Online Status: Offline
Posts: 4
Quote steve728 Replybullet Posted: 27 Mar 2008 at 12:36pm

I'm altering the code with some success.  I will let you know what I came up with when done.  Thank you so much for your replies thus far.

Steve728

IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum