Susan, 

First off, I'd recommend finding one of the pre-built registration
systems out there (jcode on http://www.ardiri.com, PORT on
http://www.cyberport.com/~tangent/palm/port/, etc).

That aside, when you're doing this kind of thing, you need to follow the
process through step by step.

I might digress a little, I'm suspicious of the loop that you've got. I
can't prove it, but my intuition is telling me that that loop could
generate duplicate nProductID's for different registration names.

Anyway, making nSourceID a double is a good first step, but you need to
look at each time it's used and see if you're overflowing.

In this case, you're multiplying nProductID by that huge number (which
will ake it larger), and stuffing it into an Int32 again, which
truncates the number.

This number is going to be quite large.  I think the size of number a
double will hold is 15 digits (even a long double can only hold 19) An
Int32 could hold 10 digits. Multiplying a double and an Int32 could
easily result in a 25 digit number.  Can even a long double hold that
much?

Let's assume you get abound this by using an arbitrary precision math
package which basically does the math in BCD or in ASCII...once you've
gotten your result, you'll need to convert it to your string format,
cause there won't be a StrXToA for these formats.

Finally, "StrNCopy(sProductID,ProductID,8);" will only copy the first 8
characters, and won't even terminate the string for you.  You're
guaranteed to truncate the number.

Instead of trying to get this code to work, I'd suggest you go with a
registration system that's already done all this dirty work for you
(along with making server-based tools so that the key generation can be
done when the customer purchases rather than a few days later).

-Ken

On Sat, 2003-02-08 at 04:31, Susan wrote:
> Now I want to calculate the nProductID as following codes:
> 
> Int32 nProductID;
> Int32 nSourceID=9093962000;
> Char* sProductID;
> Char* ProductID;
> 
> for(i=1;i<=StrLen(sRegName);i++){
>   n=(UInt16)sRegName[i-1];
>   nProductID=n*i+nProductID;
>  }
> 
> nProductID=nProductID*nSourceID;
> 
> StrIToA(ProductID,nProductID);
> 
> StrNCopy(sProductID,ProductID,8);
> 
> BUT I cant get the exact result.
> 
> Does it because of the overflow?
> How to resolve it?
> 
> Thanks for any help!!!
> 
> Susan
> 
> 
> 
> -- 
> For information on using the Palm Developer Forums, or to unsubscribe, please see 
>http://www.palmos.com/dev/support/forums/
> 




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to