Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Check Digit Help Post Reply Post New Topic
Author Message
DaBoujibo
Newbie
Newbie


Joined: 21 Feb 2012
Online Status: Offline
Posts: 28
Quote DaBoujibo Replybullet Topic: Check Digit Help
     Posted: 03 Aug 2012 at 11:21am
Hi.  I am having difficulty in getting 2 of my variables to return a value: intCheckDigit1 & intCheckDigit2.  I changed all of my variables to Global in case it was having a problem. 
 
I confirmed that I am able to pull strAccount, strDueDate, & strTotalDueFinal for the final variable strScanLine.  However, intCheckDigit1 & intCheckDigit2 are only populating as zero. 
 
Can someone help me out?
 
***BACKGROUND ON CODE***
I am creating a 30 digit scanline with 2 check digits.  One at position 14 and one at 30.  The check digit will incorporate the first check digit in its calculation. 
 
***CHECK DIGIT ARITHMETIC***
I'm able to do the check digit in Excel, so I am not sure why it is not working here. Here is the arithmetic for calculating the check digit.
 
Pos 14 Check Digit: SUM(10-(MOD(SUM(POSITION1:POSITION13),10)))
Pos 30 Check Digit: SUM(10-(MOD(SUM(POSITION1:POSITION29),10)))
 
***CODE***
Global StringVar strAccount:= {Table1.strArea} & {Table1.strProj} & {Table1.strUnit} & (IF ({Table1.intTenNum}<10) THEN LEFT("0"&{Table1.intTenNum},2) ELSE LEFT(""&{Table1.intTenNum},2));
Global StringVar strDueDate:= ToText({?prmDueDate},"MMddyy");
Global StringVar strTotalDueA:= ToText(
    (
        IF {@TotalfrmTotalDue} < 0
        THEN {@TotalfrmTotalDue} * -1
        ELSE {@TotalfrmTotalDue}
    ),"0000000",2,"","");
Global StringVar strTotalDueB:= RIGHT(ToText({@TotalfrmTotalDue},2,"",""),2);
Global StringVar strTotalDueFinal:=strTotalDueA&strTotalDueB;
Global NumberVar intCheckDigit1;
Global NumberVar intCheckDigit2;
 
//strAccount is Position 1 - 13 in scanline
//intCheckDigit1 is Position 14 in scanline
//strDueDate is Position 15-20 in scanline
//strTotalDueB is Position 21-29 in scanline
//intCheckDigit2 is Position 30 in scanline
 
//Get each position and convert to a number, and apply weight (2 or 1)
Global NumberVar intPOS1= (ToNumber(LEFT(strAccount,1))*2);
Global NumberVar intPOS2= (ToNumber(MID(strAccount,2,1))*1);
Global NumberVar intPOS3= (ToNumber(MID(strAccount,3,1))*2);
Global NumberVar intPOS4= (ToNumber(MID(strAccount,4,1))*1);
Global NumberVar intPOS5= (ToNumber(MID(strAccount,5,1))*2);
Global NumberVar intPOS6= (ToNumber(MID(strAccount,6,1))*1);
Global NumberVar intPOS7= (ToNumber(MID(strAccount,7,1))*2);
Global NumberVar intPOS8= (ToNumber(MID(strAccount,8,1))*1);
Global NumberVar intPOS9= (ToNumber(MID(strAccount,9,1))*2);
Global NumberVar intPOS10= (ToNumber(MID(strAccount,10,1))*1);
Global NumberVar intPOS11= (ToNumber(MID(strAccount,11,1))*2);
Global NumberVar intPOS12= (ToNumber(MID(strAccount,12,1))*1);
Global NumberVar intPOS13= (ToNumber(MID(strAccount,13,1))*2);
Global NumberVar intPOS15= (ToNumber(LEFT(strDueDate,1))*2);
Global NumberVar intPOS16= (ToNumber(MID(strDueDate,2,1))*1);
Global NumberVar intPOS17= (ToNumber(MID(strDueDate,3,1))*2);
Global NumberVar intPOS18= (ToNumber(MID(strDueDate,4,1))*1);
Global NumberVar intPOS19= (ToNumber(MID(strDueDate,5,1))*2);
Global NumberVar intPOS20= (ToNumber(MID(strDueDate,6,1))*1);
Global NumberVar intPOS21= (ToNumber(LEFT(strTotalDueFinal,1))*2);
Global NumberVar intPOS22= (ToNumber(MID(strTotalDueFinal,2,1))*1);
Global NumberVar intPOS23= (ToNumber(MID(strTotalDueFinal,3,1))*2);
Global NumberVar intPOS24= (ToNumber(MID(strTotalDueFinal,4,1))*1);
Global NumberVar intPOS25= (ToNumber(MID(strTotalDueFinal,5,1))*2);
Global NumberVar intPOS26= (ToNumber(MID(strTotalDueFinal,6,1))*1);
Global NumberVar intPOS27= (ToNumber(MID(strTotalDueFinal,7,1))*2);
Global NumberVar intPOS28= (ToNumber(MID(strTotalDueFinal,8,1))*1);
Global NumberVar intPOS29= (ToNumber(MID(strTotalDueFinal,9,1))*2);
 
//Begin to get the 1st check digit after the account number
 
Global NumberVar intChkDig1SUM= (intPOS1 + intPOS2 + intPOS3 + intPOS4 + intPOS5 + intPOS6 + intPOS7 + intPOS8 + intPOS9 + intPOS10 + intPOS11 + intPOS12 + intPOS13);
 
Global NumberVar intChkDig1MOD=(intChkDig1SUM MOD 10);
intCheckDigit1=(10-intChkDig1MOD)*1;
 
//Begin to get the 2nd check digit after the account number
 
Global NumberVar intChkDig2SUM= (intPOS1 + intPOS2 + intPOS3 + intPOS4 + intPOS5 + intPOS6 + intPOS7 + intPOS8 + intPOS9 + intPOS10 + intPOS11 + intPOS12 + intPOS13 + intCheckDigit1 + intPOS15 + intPOS16 + intPOS17 + intPOS18 + intPOS19 + intPOS20 + intPOS21 + intPOS22 + intPOS23 + intPOS24 + intPOS25 + intPOS26 + intPOS27 + intPOS28 + intPOS29);
 
Global NumberVar intChkDig2MOD=(intChkDig2SUM MOD 10);
intCheckDigit2=10-intChkDig2MOD;
 
//Final Scanline result
Global StringVar strScanLine:=
strAccount & ToText(intCheckDigit1,0,"","") & strDueDate & strTotalDueFinal & ToText(intCheckDigit2,0,"","");
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 06 Aug 2012 at 4:46am
the first problem that I see is that most of your assignments are comparing (=) and not assigning (:=), otherwise I trust that the math is correct.
IP IP Logged
DaBoujibo
Newbie
Newbie


Joined: 21 Feb 2012
Online Status: Offline
Posts: 28
Quote DaBoujibo Replybullet Posted: 06 Aug 2012 at 6:23am
Doh!  Something so simple. hehe.  It now populates the check digits but the result is wrong.  But, hey, at least I can see that it is wrong now.  So now I can figure out where it is wrong.
 
Thanks so much!
IP IP Logged
DaBoujibo
Newbie
Newbie


Joined: 21 Feb 2012
Online Status: Offline
Posts: 28
Quote DaBoujibo Replybullet Posted: 06 Aug 2012 at 8:15am
I figured out the math problem. I forgot to transfer a part from my psuedocode to my actual code. In case anyone ever has a similar issue, here is my final code. (I cleaned it up some as well.)
 
Thank you again to Lockwelle for your help!
***CODE***
Global StringVar strAccount:= {Table1.Area} & {Table1.Proj} & {Table1.Unit} & (IF ({Table1.TenNum}<10) THEN LEFT("0"&{Table1.TenNum},2) ELSE LEFT(""&{Table1.TenNum},2));
Global StringVar strDueDate:= ToText({?prmDueDate},"MMddyy");
Global StringVar strTotalDueA:= ToText(
     (
        IF {@TotalfrmTotalDue} < 0
        THEN {@TotalfrmTotalDue} * -1
        ELSE {@TotalfrmTotalDue}
     ),"0000000",2,"","");
Global StringVar strTotalDueB:= RIGHT(ToText({@TotalfrmTotalDue},2,"",""),2);
 
Global StringVar strTotalDueFinal:=strTotalDueA&strTotalDueB;
 
//strAccount is Position 1 - 13 in scanline
//intCheckDigit1 is Position 14 in scanline
//strDueDate is Position 15-20 in scanline
//strTotalDueB is Position 21-29 in scanline
//intCheckDigit2 is Position 30 in scanline
 
//Get each position, convert to a number, apply weight (2 or 1)
Global NumberVar intPOS1A:= (ToNumber(MID(strAccount,1,1))*2);
Global NumberVar intPOS2A:= (ToNumber(MID(strAccount,2,1))*1);
Global NumberVar intPOS3A:= (ToNumber(MID(strAccount,3,1))*2);
Global NumberVar intPOS4A:= (ToNumber(MID(strAccount,4,1))*1);
Global NumberVar intPOS5A:= (ToNumber(MID(strAccount,5,1))*2);
Global NumberVar intPOS6A:= (ToNumber(MID(strAccount,6,1))*1);
Global NumberVar intPOS7A:= (ToNumber(MID(strAccount,7,1))*2);
Global NumberVar intPOS8A:= (ToNumber(MID(strAccount,8,1))*1);
Global NumberVar intPOS9A:= (ToNumber(MID(strAccount,9,1))*2);
Global NumberVar intPOS10A:= (ToNumber(MID(strAccount,10,1))*1);
Global NumberVar intPOS11A:= (ToNumber(MID(strAccount,11,1))*2);
Global NumberVar intPOS12A:= (ToNumber(MID(strAccount,12,1))*1);
Global NumberVar intPOS13A:= (ToNumber(MID(strAccount,13,1))*2);
Global NumberVar intPOS15A:= (ToNumber(MID(strDueDate,1,1))*2);
Global NumberVar intPOS16A:= (ToNumber(MID(strDueDate,2,1))*1);
Global NumberVar intPOS17A:= (ToNumber(MID(strDueDate,3,1))*2);
Global NumberVar intPOS18A:= (ToNumber(MID(strDueDate,4,1))*1);
Global NumberVar intPOS19A:= (ToNumber(MID(strDueDate,5,1))*2);
Global NumberVar intPOS20A:= (ToNumber(MID(strDueDate,6,1))*1);
Global NumberVar intPOS21A:= (ToNumber(MID(strTotalDueFinal,1,1))*2);
Global NumberVar intPOS22A:= (ToNumber(MID(strTotalDueFinal,2,1))*1);
Global NumberVar intPOS23A:= (ToNumber(MID(strTotalDueFinal,3,1))*2);
Global NumberVar intPOS24A:= (ToNumber(MID(strTotalDueFinal,4,1))*1);
Global NumberVar intPOS25A:= (ToNumber(MID(strTotalDueFinal,5,1))*2);
Global NumberVar intPOS26A:= (ToNumber(MID(strTotalDueFinal,6,1))*1);
Global NumberVar intPOS27A:= (ToNumber(MID(strTotalDueFinal,7,1))*2);
Global NumberVar intPOS28A:= (ToNumber(MID(strTotalDueFinal,8,1))*1);
Global NumberVar intPOS29A:= (ToNumber(MID(strTotalDueFinal,9,1))*2);
 
//Identify if the result of the weight is greater than 9 to add the 1st and 2nd digits together.
//Otherwise, leave it as the original result.
Global NumberVar intPOS1B:=
     IF intPOS1A > 9
     THEN (ToNumber(MID(ToText(intPOS1A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS1A,0,"",""),2,1)))
     ELSE intPOS1A;
Global NumberVar intPOS2B:=
     IF intPOS2A > 9
     THEN (ToNumber(MID(ToText(intPOS2A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS2A,0,"",""),2,1)))
     ELSE intPOS2A;
Global NumberVar intPOS3B:=
     IF intPOS3A > 9
     THEN (ToNumber(MID(ToText(intPOS3A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS3A,0,"",""),2,1)))
     ELSE intPOS3A;
Global NumberVar intPOS4B:=
     IF intPOS4A > 9
     THEN (ToNumber(MID(ToText(intPOS4A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS4A,0,"",""),2,1)))
     ELSE intPOS4A;
Global NumberVar intPOS5B:=
     IF intPOS5A > 9
     THEN (ToNumber(MID(ToText(intPOS5A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS5A,0,"",""),2,1)))
     ELSE intPOS5A;
Global NumberVar intPOS6B:=
     IF intPOS6A > 9
     THEN (ToNumber(MID(ToText(intPOS6A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS6A,0,"",""),2,1)))
     ELSE intPOS6A;
Global NumberVar intPOS7B:=
     IF intPOS7A > 9
     THEN (ToNumber(MID(ToText(intPOS7A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS7A,0,"",""),2,1)))
     ELSE intPOS7A;
Global NumberVar intPOS8B:=
     IF intPOS8A > 9
     THEN (ToNumber(MID(ToText(intPOS8A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS8A,0,"",""),2,1)))
     ELSE intPOS8A;
Global NumberVar intPOS9B:= 
     IF intPOS9A > 9
     THEN (ToNumber(MID(ToText(intPOS9A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS9A,0,"",""),2,1)))
     ELSE intPOS9A;
Global NumberVar intPOS10B:=
     IF intPOS10A > 9
     THEN (ToNumber(MID(ToText(intPOS10A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS10A,0,"",""),2,1)))
     ELSE intPOS10A;
Global NumberVar intPOS11B:=
     IF intPOS11A > 9
     THEN (ToNumber(MID(ToText(intPOS11A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS11A,0,"",""),2,1)))
     ELSE intPOS11A;
Global NumberVar intPOS12B:=
     IF intPOS12A > 9
     THEN (ToNumber(MID(ToText(intPOS12A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS12A,0,"",""),2,1)))
     ELSE intPOS12A;
Global NumberVar intPOS13B:=
     IF intPOS13A > 9
     THEN (ToNumber(MID(ToText(intPOS13A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS13A,0,"",""),2,1)))
     ELSE intPOS13A;
Global NumberVar intPOS15B:=
     IF intPOS15A > 9
     THEN (ToNumber(MID(ToText(intPOS15A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS15A,0,"",""),2,1)))
     ELSE intPOS15A;
Global NumberVar intPOS16B:=
     IF intPOS16A > 9
     THEN (ToNumber(MID(ToText(intPOS16A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS16A,0,"",""),2,1)))
     ELSE intPOS16A;
Global NumberVar intPOS17B:=
     IF intPOS17A > 9
     THEN (ToNumber(MID(ToText(intPOS17A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS17A,0,"",""),2,1)))
     ELSE intPOS17A;
Global NumberVar intPOS18B:=
      IF intPOS18A > 9
      THEN (ToNumber(MID(ToText(intPOS18A,0,"",""),1,1)) + ToNumber(MID
      (ToText(intPOS18A,0,"",""),2,1)))
      ELSE intPOS18A;
Global NumberVar intPOS19B:=
      IF intPOS19A > 9
      THEN (ToNumber(MID(ToText(intPOS19A,0,"",""),1,1)) + ToNumber(MID
      (ToText(intPOS19A,0,"",""),2,1)))
      ELSE intPOS19A;
Global NumberVar intPOS20B:=
      IF intPOS20A > 9
      THEN (ToNumber(MID(ToText(intPOS20A,0,"",""),1,1)) + ToNumber(MID
      (ToText(intPOS20A,0,"",""),2,1)))
      ELSE intPOS20A;
Global NumberVar intPOS21B:=
      IF intPOS21A > 9
      THEN (ToNumber(MID(ToText(intPOS21A,0,"",""),1,1)) + ToNumber(MID
      (ToText(intPOS21A,0,"",""),2,1)))
      ELSE intPOS21A;
Global NumberVar intPOS22B:=
      IF intPOS22A > 9
      THEN (ToNumber(MID(ToText(intPOS22A,0,"",""),1,1)) + ToNumber(MID
      (ToText(intPOS22A,0,"",""),2,1)))
      ELSE intPOS22A;
Global NumberVar intPOS23B:=
      IF intPOS23A > 9
      THEN (ToNumber(MID(ToText(intPOS23A,0,"",""),1,1)) + ToNumber(MID
      (ToText(intPOS23A,0,"",""),2,1)))
      ELSE intPOS23A;
Global NumberVar intPOS24B:=
      IF intPOS24A > 9
      THEN (ToNumber(MID(ToText(intPOS24A,0,"",""),1,1)) + ToNumber(MID
      (ToText(intPOS24A,0,"",""),2,1)))
      ELSE intPOS24A;
Global NumberVar intPOS25B:=
      IF intPOS25A > 9
      THEN (ToNumber(MID(ToText(intPOS25A,0,"",""),1,1)) + ToNumber(MID
      (ToText(intPOS25A,0,"",""),2,1)))
      ELSE intPOS25A;
Global NumberVar intPOS26B:=
      IF intPOS26A > 9
      THEN (ToNumber(MID(ToText(intPOS26A,0,"",""),1,1)) + ToNumber(MID
      (ToText(intPOS26A,0,"",""),2,1)))
      ELSE intPOS26A;
Global NumberVar intPOS27B:=
      IF intPOS27A > 9
      THEN (ToNumber(MID(ToText(intPOS27A,0,"",""),1,1)) + ToNumber(MID
      (ToText(intPOS27A,0,"",""),2,1)))
      ELSE intPOS27A;
Global NumberVar intPOS28B:=
      IF intPOS28A > 9
      THEN (ToNumber(MID(ToText(intPOS28A,0,"",""),1,1)) + ToNumber(MID
      (ToText(intPOS28A,0,"",""),2,1)))
      ELSE intPOS28A;
Global NumberVar intPOS29B:=
     IF intPOS29A > 9
     THEN (ToNumber(MID(ToText(intPOS29A,0,"",""),1,1)) + ToNumber(MID
     (ToText(intPOS29A,0,"",""),2,1)))
     ELSE intPOS29A;
 
//Begin to get the 1st check digit after the account number
Global NumberVar intChkDig1SUM:= (intPOS1B + intPOS2B + intPOS3B + intPOS4B + intPOS5B + intPOS6B + intPOS7B + intPOS8B + intPOS9B + intPOS10B + intPOS11B + intPOS12B + intPOS13B);
 
Global NumberVar intChkDig1MOD:=(intChkDig1SUM MOD 10);
Global NumberVar intCheckDigit1:=(10-intChkDig1MOD)*1;
 
//Begin to get the 2nd check digit after the account number
Global NumberVar intChkDig2SUM:= (intPOS1B + intPOS2B + intPOS3B + intPOS4B + intPOS5B + intPOS6B + intPOS7B + intPOS8B + intPOS9B + intPOS10B + intPOS11B + intPOS12B + intPOS13B + intCheckDigit1 + intPOS15B + intPOS16B + intPOS17B + intPOS18B + intPOS19B + intPOS20B + intPOS21B + intPOS22B + intPOS23B + intPOS24B + intPOS25B + intPOS26B + intPOS27B + intPOS28B + intPOS29B);
 
Global NumberVar intChkDig2MOD:=(intChkDig2SUM MOD 10);
Global NumberVar intCheckDigit2:=10-intChkDig2MOD;
 
//Final Scanline result
Global StringVar strScanLine:=
strAccount & ToText(intCheckDigit1,0,"","") & strDueDate & strTotalDueFinal & ToText(intCheckDigit2,0,"","");
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 06 Aug 2012 at 8:58am
Also, if you're only going to be using the vars internally to the formula, you can take out all of the "Global"s.  Global is really only needed when you're transferring values back and forth between the main report and subreports.  If you do just "NumberVar" or "StringVar" with no modifier, you should be good.
 
-Dell
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 07 Aug 2012 at 4:31am
Actually, Global is internal to the report, Shared is between subreports and the main report.
 
One would think Global is to all reports, but according to the documentation, global is global only to the report, while Shared means that the variable can be shared among other reports.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 07 Aug 2012 at 4:52am
Interesting.... It's still not needed in this case, though.
 
-Dell
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum