Simplify Code

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
lmangcahan
Posts: 25
Joined: September 7th, 2021, 3:45 am

Simplify Code

Post by lmangcahan »

Hi CSPro Team,
Hope all is well. Can you help me simplify my code below? I declared F2001...F2004 individually since when I try displaying their values using concat("F2",edit("999",x)) it display the value F2001 and not the value stored to this variable.

Thank you in advance.
Numeric F2001,F2002,F2003,F2004;
filewrite(summary_file," TOTAL ERRORS PER ERRORCODE: ");
filewrite(summary_file," F2001: %d", F2001);
filewrite(summary_file," F2002: %d", F2002);
filewrite(summary_file," F2003: %d", F2003);
filewrite(summary_file," F2004: %d", F2004)
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: Simplify Code

Post by aaronw »

The assignments to F2001, F2002, F2003, and F2004 are what are of interest here. Have you just tried displaying them with an error message?
errmsg("%d, %d, %d, %d", F2001, F2002, F2003, F2004);
If these values are incorrect you need to take a step back and look why that is.
lmangcahan
Posts: 25
Joined: September 7th, 2021, 3:45 am

Re: Simplify Code

Post by lmangcahan »

Hi Aaronw,

The code below actually works but I was thinking if I can simplify it in CSPRO. I have over hundred errorcodes to declare and maybe there's a shorter steps to take. Thank you.
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Simplify Code

Post by Gregory Martin »

You can potentially use the getvalue function. Something like this:
do numeric ctr = 2001 while ctr <= 2004
    string item_name = maketext("F%d", ctr);
    summary_file.write("%s: %d", item_name, getvalue(item_name));
enddo;
Post Reply