Results 1 to 7 of 7

Thread: Problem with shared variables

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44

    Problem with shared variables

    I'm trrying to take the total from one subreport and make it divide by the total of another subreport to come out with a certain percentage which is shown in the second subreport. I have declared the shared variable in the main repot and have managed to assign the correct value within the first subreport. However, that value does not seem to be coming out of that subreport as when I go into the second subreport and attempt the division, I get a divide by zero error, which is what the value is set to in the main report. Any suggestions on how I can correct this?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    How do you have the variable declared?

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    Well in the main report it is declared as

    shared numbervar nfg :=0;



    in the subreport it is shared numbervar nfg := fieldname;

    which correctly assigns the field value to the variable nfg.



    in the second subreport it is

    (count of field name)/shared numbervar nfg

    which results in a divide by zero error.

    which says to me that the variable is not carrying out of the subreport.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    This is going to sound stupid, but I think what you will need to do is split the section into two sections, put one sub report in to one, and the other in the other. Because the subs are in the same section at the same level, Crystal tries to render them together. What you need to do is have the first one render first, then deal with the second. It sounds stupid and lame, but I had that very problem once before. To solve it, we put the two reports into different subsections and forced one to render first.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    That does seem to make a lot of sense now that i think about it. I do have them in separate detail lines however, that is what you are are suggesting, correct?

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    He is referring to Sections not Lines. If you were not aware, you can have one or more of each section type.

    Right click on the section name and choose the "Insert Section Below" menu item. You will now see an "a" and "b" section, ie "Details a" and "Details b".

    Crystal processes each section in turn. If you place the second sub-report in "Details b", nothing happens until the "Details a" section has completed. If sub-reports are in the same section, Crystal spawns multiple threads and processes them simultaneously.

    One more thing, its not clear from your posts but did you declare the shared variabe in the second sub-report. Every formula that uses a shared variable must have the exact same declaration.

    Okay, now one more thing. I seem to recall that a line which uses a shared variable must end with a semi-colon;.

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2002
    Posts
    44
    Sorry it took me so long to get back on this issue, but I have been multitasking recently.

    All of the subreports in my report are in different sections and yet it still does not seem to be carrying over any of the relevant data. Ie one report in detail lines a, another report in detail line b... semicolons are after every line of code. Any ideas?

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