Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3635890
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:57:41+00:00 2026-05-19T00:57:41+00:00

I have a global variable which was declared in a formula in the Report

  • 0

I have a global variable which was declared in a formula in the Report Header section of my document. I then try to reference that variable to use it in a for loop, and I get the error:

A number, currency amount, boolean,
data, time, date-time, or string is
expected here.

What is wrong here and how can I correct? Code follows:

Header Formula:

Global StringVar Array items;
redim items [1];

Global StringVar Array jobs;
redim jobs [1];

Global StringVar Array POs;
redim POs [1];

Global StringVar Array Qty;
redim Qty [1];

Global NumberVar numRecordsPrinted;
numRecordsPrinted := 0;

""

Detail Formula:

    Local NumberVar occurances;
    Local StringVar poTOuse;
    Local NumberVar i;

    if {%Line_PO_Test} <> ''
    and {PackingSlipHeader.CompanyCode} <> '10063'
    and {PackingSlipHeader.CompanyCode} <> '10017'
    then 
        //Count the number of occurances 
        For i := 0 To numRecordsPrinted Do       //Error on numRecordsPrinted
        (
            if items[i] = {PS_DETAIL_FOR_PRINT.DTSItemNumber}
                AND jobs[i] = {PS_DETAIL_FOR_PRINT.JobNumber}
                And Qty[i] = {PS_DETAIL_FOR_PRINT.Quantity_Shipped}
                THEN
                    occurances := occurances + 1
        )

        //Use the # of occurances to get the right PO number
Select occurances 
        case 0: poTOuse := {@LinePOnum}
        case 1: poTOuse := {@Line_PO_3}
        case 2: poTOuse := {@Line_PO_2}

        default: poTOuse := "";


        //Save data into the array and increment for next time
        numRecordsPrinted := numRecordsPrinted + 1
        items[numRecordsPrinted] := {PS_DETAIL_FOR_PRINT.DTSItemNumber}
        jobs[numRecordsPrinted] := {PS_DETAIL_FOR_PRINT.JobNumber}
        Qty[numRecordsPrinted] :=   {PS_DETAIL_FOR_PRINT.Quantity_Shipped}

    //Print to the report
    'PO#: ' + poTOuse;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:57:42+00:00Added an answer on May 19, 2026 at 12:57 am

    In crystal reports syntax, the variables have to be declared each time you use them. I wasn’t aware that I have to declare the variables both in the header formula, and the detail formula. I made some other small syntax errors, but that was the main problem.

    I didn’t even consider this as a possibility because in most languages, declaring a variable more than once will cause the program to not even compile, let alone run.

    Header Section

    BeforeReadingRecords;
    
    Global StringVar Array items;
    
    Global StringVar Array jobs;
    
    Global StringVar Array POs;
    
    Global NumberVar Array Qty;
    
    Global NumberVar numRecordsPrinted;
    
    ""
    

    Detail Section

    WhileReadingRecords;
    Global StringVar Array items;
    
    Global StringVar Array jobs;
    
    Global StringVar Array POs;
    
    Global NumberVar Array Qty;
    
    Global NumberVar numRecordsPrinted;
    Global NumberVar occurances;
    occurances := 0;
    
    Global StringVar poTOuse;
    Global NumberVar i;
    
    ReDim Preserve items[CDbl(Ubound(items) + 1)];
    ReDim Preserve jobs[CDbl(Ubound(jobs) + 1)];
    ReDim Preserve POs[CDbl(Ubound(POs) + 1)];
    ReDim Preserve Qty[CDbl(Ubound(Qty) + 1)];
    
    if {%Line_PO_Test} <> ""
    and {PackingSlipHeader.CompanyCode} <> "10063"
    and {PackingSlipHeader.CompanyCode} <> "10017"
    then 
        //Count the number of occurances
        For i := 1 To (numRecordsPrinted + 1) Do
        (
            if items[i] = {PS_DETAIL_FOR_PRINT.DTSItemNumber}
                AND jobs[i] = {PS_DETAIL_FOR_PRINT.JobNumber}
                And Qty[i] = {PS_DETAIL_FOR_PRINT.Quantity_Shipped}
                THEN
                    occurances := occurances + 1
        );
    
        //Use the # of occurances to get the right PO number
        Select occurances 
            case 0: poTOuse := {%Line_PO_Test}
            case 1: poTOuse := {%Line_PO_3}
            case 2: poTOuse := {%Line_PO_2}
    
            default: poTOuse := "";
    
        //Save data into the array and increment for next time
        numRecordsPrinted := numRecordsPrinted + 1;
        items[numRecordsPrinted] := {PS_DETAIL_FOR_PRINT.DTSItemNumber};
        jobs[numRecordsPrinted] := {PS_DETAIL_FOR_PRINT.JobNumber};
        Qty[numRecordsPrinted] :=  {PS_DETAIL_FOR_PRINT.Quantity_Shipped};
    
    //Print to the report
    if poTOuse <> "" THEN
    'PO#: ' + poTOuse
    ELSE
    "";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python module that makes use of a huge dictionary global variable,
I have a variable in my xsl that may or may not be declared.
I am trying to design header only library, which unfortunately needs to have global
I have a module named module.py, which checks a global variable in context. module.py:
When you have a static global variable in a C++ header file, each translation
I'm having problem with global variable in PHP. I have mysqli config file which
I have used a static global variable and a static volatile variable in file
I have some global variables in a Python script. Some functions in that script
I have a big list of global variables that each have their own setup
I have a javascript function (function1) that checks some global variables (can the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.