Chris Bipes skrev:
public void generateDocKey(

String storeID,

String sessionID,

String newDocKey)
throws Exception {


String dk =
DocKey_V2(storeID,sessionID);

set(3,dk);

return;

}
This invokes DocKey_V2 and stores the return value in 3 (most likely the current record or so).

The third argument is not used.





private String DocKey_V2(String vID, String sessionID) {

String sTmp;

String DocKey_V2 = "";

String sessionIDNumericOnly = "";


int i = 0;

for (i = 0; i <= sessionID.length();
i++) {

try {

int x =
Integer.parseInt(sessionID.substring(i, i + 1));

sessionIDNumericOnly =

sessionIDNumericOnly + Integer.toString(x);

} catch (Exception e) {

}

}
Accumulates all digits in "sessionID" to "sessionIDNumeric". Other characters are silently discared.

if (sessionIDNumericOnly.length() < 6) {

for
(i=sessionIDNumericOnly.length(); i <= 6; i++) {

sessionIDNumericOnly =

sessionIDNumericOnly + "9";

}

}
Pad sessionIDNumericOnly with "9" characters (trailing) if needed up to the length 6.

try {

int length = 0;

int position = 0;

int nID = 0;


try {

nID =
Integer.valueOf(vID).intValue() * 3;

} catch (Exception e) {

nID = 0;

}

Set "nID" to the value of "storeID" as an integer multiplied by 3. If for any reason "storeID" is not a valid integer, then set nID to 0.



DecimalFormat df = new
DecimalFormat("00");

double sessionLength =
sessionIDNumericOnly.length();

String storeString =
Integer.toString(nID);

double storeIDLength =
storeString.length();


sTmp = "2" +
df.format(sessionLength) + df.format(storeIDLength);

Set "sTmp" to a five digit string. Position 1 is "2", position 2-3 is the length of the sessionIDNumeric string, position 4-5 is the length of "nID" as a string.

for (position = 0;

length
<= (sessionLength + storeIDLength);

length++) {

if
(!(position >= sessionLength)) {

sTmp =

sTmp

+ sessionIDNumericOnly.substring(

position,

position + 1);

}

if
(!(position >= storeIDLength)) {

sTmp = sTmp + storeString.substring(position, position + 1);

}

position
= position + 1;


}

This is rather unconventional. My best guess is that the loop adds to "sTmp" the _merged_ content of sessionIDNumeric and storeString (by first taking the first character of sessionIDnumeric, the first cahracter of storeString, the second character of sessionIDNumeric etc until all characters have been used. If the given string is not long enough for a given position, it is skipped).



java.util.Calendar c =

new
java.util.GregorianCalendar(1899, 11, 30);

long millis =
c.getTimeInMillis();

long milliseconds =
System.currentTimeMillis();

//long newDate =
milliseconds - millis + 600000;

long newDate =
milliseconds - millis;

long dateInVBFormat =
(newDate / 864000);

sTmp = sTmp +
Long.toString(dateInVBFormat);
and finally add the number of milliseconds since 30/11 1899 (a VB peculiarity?) divided by number of seconds in 10 days to sTmp.

(all this should be digits)
DocKey_V2 =
MakeMOD10(sTmp);
The sTmp string is then processed by MakeMod10 to create the DocKey_V2 value.

} catch (Exception _e_) {

DocKey_V2 = null;

If anything fails, the value is null.

}

return DocKey_V2;

This is the key returned and inserted!
}


private boolean IsMOD10(String sValue) {

boolean IsMOD10 = false;

try {

int nDx = 0;

int nTotal = 0;

int nVal = 0;


nTotal = 0;

for (nDx = 0; nDx <
sValue.length(); nDx++) {

Iterate over each digit in sTmp.
if
(sValue.substring(nDx, nDx + 1).compareTo("0") < 0) {

char c = sValue.charAt(nDx);

nVal = c;
if the character at position nDx is less thatn "0" (!"#€(=/( or similar) then just use its ascii value as nVal.
} else {

if (sValue.substring(nDx, nDx + 1).compareTo("9") > 0) {

char c = sValue.charAt(nDx);

nVal = c;

Same thing for characters larger than "9"


} else {

nVal =

Integer

.valueOf(sValue.substring(nDx, nDx + 1))

.intValue();

if "0".."9" use the integer value as nVal.
}

}

nTotal =
nTotal + nVal;
Sum them up in nTotal.
}

IsMOD10 = (nTotal % 10)
== 0;
And return true if nTotal divided by 10 has a remainder of 0. False otherwise.
} catch (Exception e) {

System.out.println("Error with MOD10");

return false;

}

return IsMOD10;

}


private String MakeMOD10(String sValue) {

String MakeMOD10 = "";

try {

Try the values from 0 to 9 to see if any of them added to sValue gives a string that passes the MOD10 test. If so, return that. If not, just use 9 anyway.
int nDx = 0;


for (nDx = 0; nDx <= 9;
nDx++) {

if
(IsMOD10(sValue + nDx)) {

break;

}

}

MakeMOD10 = sValue +
nDx;

} catch (Exception e) {

System.out.println("Error with MOD10");

}

return MakeMOD10;

}

}



Chris Bipes
Director of Information Services
CrossCheck, Inc.




Might this be a port of a similar mechanism from a Visual Basic program?


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.