Results 1 to 4 of 4

Thread: Crystal report local variable

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2016
    Posts
    37

    Crystal report local variable

    I have a table with 4 columns (Morning/Afternoon/Evening/Night)char(1) field data will Y/N in the column

    with this table i am creating a crystal report
    the output should be something like this

    if Morning and night is Y

    Mor.........Night (nine dots)

    If only Morning is Y
    Mor ( not dots)

    If Afternoon and Evening
    ...Afternoon...Evening

    if Morning and Evening
    Mor......Evening(6 dots between mor and ever )

    if Morning Afternoon evening and night is Y
    Mor...After...Eve...Night

    like this i want in crystal report
    I tried like this but not working properly
    in cystal report formula editor

    local stringvar flag;
    if {Table.Morning}='Y' then
    flag:='Mor'
    else
    flag:='...'

    if {Table.Afternoon}='Y' then
    flag:=Flag+'after'
    else
    flag:=flag;

    but is not as per desire

  2. #2
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    476

    Re: Crystal report local variable

    In the future you might want to tell us what you get because "not as per desire" does not tell us that you get an error message. Tell us the error message. What you want is also not clear. On one line you want Afternoon, on another you want After. Which is it?

    However, if you have fixed the error message and typed the code here wrong instead of just copying it from your report, you probably are missing the elipses. If that is the case, you just need to go through the logic.

    If Morning is Y then set the flag to Mor if not set the flag to "..."
    If Afternoon is Y add "After" to what is already in flag.

    If flag is Mor then you get MorAfter if Afternoon is Y because that is what you told it to do. Why not tell it to use

    flag:=Flag+'...after'

    instead?

    Because if Mor is not the flag when checking Afternoon, you have already put "..." in the Flag variable.

    Something like this might work but you haven't given us all the options so you will have to expand on this.

    Code:
    local stringvar Mor;
    local stringvar Aft;
    local stringvar Eve;
    local stringvar Night;
    local stringvar times;
    
    if {Table.Morning}='Y' then
    Mor:="Mor";
    
    if {Table.Afternoon}='Y' then
    Aft:="Aft";
    
    if {Table.Evening}='Y' then
    Eve:="Eve";
    
    if {Table.Night}='Y' then
    Night:="Night";
    
    times:=Mor & "..." & Aft & "..." & Eve & "..." & Night;
    
    if Right (times, 3) = "..." then
        times:=Left (times, length (times) - 3);
    
    times

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2016
    Posts
    37

    Re: Crystal report local variable

    I am sorry if I couldn't explain it properly
    but what u have understood is correct only the thing is that
    I ll tell what format I am looking for
    this is almost correct times:=Mor & "..." & Aft & "..." & Eve & "..." & Night;
    but if only morning is Y then
    it should be times:=Mor ( not dots)
    if Mor and Aft is 'Y' then
    times:=Mor & "..." & Aft ( no dots after Aft) you can say after the last var no dots

    if Aft and Eve is 'Y' then
    times:="..." & Aft & "..." & Eve

    if only Night='Y' then
    times:="........." & Night (3 dots for the vacant places which are coming before)

    if Eve and Night ='Y' then
    times:="......" & Eve & "..." & Night

    like this I hope I explained it properly now


    local stringvar Mor;
    local stringvar Aft;
    local stringvar Eve;
    local stringvar Night;
    local stringvar times;

    if {Table.Morning}='Y' then
    Mor:="Mor";

    if {Table.Afternoon}='Y' then
    Aft:="Aft";

    if {Table.Evening}='Y' then
    Eve:="Eve";

    if {Table.Night}='Y' then
    Night:="Night";

    times:=Mor & "..." & Aft & "..." & Eve & "..." & Night;

    if Right (times, 3) = "..." then
    times:=Left (times, length (times) - 3);

    times

  4. #4
    Hyperactive Member
    Join Date
    Jul 2007
    Posts
    476

    Re: Crystal report local variable

    This will likely give you what you want

    Code:
    local stringvar Mor;
    local stringvar Aft;
    local stringvar Eve;
    local stringvar Night;
    local stringvar times;
    local numbervar count;
    
    if {Table.Morning}='Y' then
    Mor:="Mor";
    
    if {Table.Afternoon}='Y' then
    Aft:="Aft";
    
    if {Table.Evening}='Y' then
    Eve:="Eve";
    
    if {Table.Night}='Y' then
    Night:="Night";
    
    times:=Mor & "..." & Aft & "..." & Eve & "..." & Night;
    
    for count := 1 to 4 do 
    
    (if Right (times, 3) = "..." then
        times:=Left (times, length (times) - 3);
    if Left (times, 3) = "..." then
        times:=Mid (times, 4));
    
    times

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