Results 1 to 5 of 5

Thread: [RESOLVED] Whats the problem with this code????

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    95

    Resolved [RESOLVED] Whats the problem with this code????

    i am using VBnet 2002 and crystal v9.1
    Please I am trying to define an expression in my crystal report but still having errors , Can you help me please???
    below is my code,please advice accordingly ;
    VB Code:
    1. Local StringVar message := "";
    2. Local Datevar confdate ={pensioners.date_conf_pens_terms};
    3. Local Datevar hiredate ={pensioners.hiredate};
    4.  
    5. if hiredate = confdate then
    6. message="N/A"
    7. ELSE
    8. confdate
    I simply want to display a message "N/A" on the report when dates are equal and confdate when otherwise.
    Please help.

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Whats the problem with this code????

    Maybe the dates stored in your database include a time portion as well which could be the reason your formula is not working as expected, eg if
    {pensioners.date_conf_pens_terms} = 6/12/2006 19:01:21 and
    {pensioners.hiredate} = 6/12/2006 19:01:20 then they would not be equal.
    Your formula can return either a string or a date, so you would also need to convert the date to a string. You also don't need the message= bit....
    Try doing this:
    Code:
    Local StringVar message := "";
    Local Datevar confdate = Date({pensioners.date_conf_pens_terms});
    Local Datevar hiredate = Date({pensioners.hiredate});
    
    if hiredate = confdate then 
        "N/A"     ' Get rid of message=
    ELSE 
        CStr(confdate)
    Last edited by pnish; Dec 15th, 2006 at 02:33 AM.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    95

    Re: Whats the problem with this code????

    Thanks pete
    I have tried your suggestion,the formula had no error...but the following are my observations;
    Report only evaluates the first condition...(not after else)
    cstr(confdate) doesnt display anything.... even if I pput it as the first condition
    below is the code;

    VB Code:
    1. Local StringVar message := "";
    2. Local Datevar confdate = Date({members.date_conf_pens_terms});
    3. Local Datevar hiredate = Date({members.datehired});
    4.  
    5. if hiredate = confdate then
    6.  "N/A"
    7. Else  
    8. cstr(confdate)

    please help

  4. #4
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Whats the problem with this code????

    Could it be that there are some records with Null dates in these fields? Nulls can play havoc with Crystal if you're not aware of them. Try this:
    Open your report in Crystal, go to the File menu and select Report Options. Check the box labelled Convert Database NULL Values to Default.

    One question, why are you storing your values in variables in the formula? There's really no need, why not just do this...
    VB Code:
    1. If {members.date_conf_pens_terms} = {members.datehired} Then
    2.     "N/A"
    3. Else
    4.     cstr({members.date_conf_pens_terms})
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    95

    Re: Whats the problem with this code????

    Thanks very much it is now working!!!!!!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width