Re: Newbie Question
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Thu, 01 Jun 2006 13:52:08 GMT
"Frank Swarbrick" <Frank.Swarbrick@xxxxxxxxxxxxxx> wrote in message news:4e6oshF1dhkbjU1@xxxxxxxxxxxxxxxxx
Oliver Wong<owong@xxxxxxxxxxxxxx> 05/31/06 11:05 AM >>>
"Michael Mattias" <michael.mattias@xxxxxxx> wrote in message
news:qPjfg.2694$VE1.1338@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I had this small cobol routine dropped on my desk and need to convert
it into a vb app, but I am not all that familiar with most of cobol. I
can read most of it and decipher what is going on, but having trouble
with this move.
var1 pic 9 comp.
var2 pic 9(10)
If var2 had the value of 138755482 and
MOVE VAR2 TO VAR1 is executed, what is actually stored in var1.
I apologize if this is a no brainer.
MOVE= assignment
MOVE A TO B (cobol) ===> [ LET] B = A (BASIC)
DIM VAR1 AS LONG, VAR2 AS LONG
VAR1 = VAR2
WARNING: a long integer will not hold Var2, where PIC 9(10) specifies a
numeric data item with ten digits before the decimal. You may need to go
to
a SINGLE or DOUBLE here.
It takes 34 bits to store an unsigned 10 digit number, and 35 bits to
store a signed 10 digit number, so you're right that LONG INTEGER (32 bit
signed) won't be enough to store all values of the PIC 9(10). However, if
you move to floating point numbers (e.g. SINGLE or DOUBLE), you're opening
yourself up to problems with rounding, which may also yield big headaches.
In such a case, you'll want to use a "Big Integer" package, such as the
one which can be downloaded from
http://www.codeproject.com/com/BigInteger.asp
Seems to me it might make most sense to treat it as a character string and
loop through it digit by digit, doing the proper calculation.
I haven't done BASIC since jr high, but... (And this assumes we're doing a
mod-11 check...)
Loop through the string, converting each character to its corresponding
integerdata type (ASCII 030 becomes 0, ASCII 031 becomes 1, etc - most
likely VB offers some function to perform this conversion). Multiply that
integer by the proper "weight" and add the result to a long integer data
type (which had been initialized to zero prior to entering the loop). When
you're done your "result" will be the long integer, which you will then
"mod" by the modulus value (11 in this case). If the result is zero then
your account number has passed the mod-11 test.
You can use a string instead of BigInt, but the BigInt class is likely to provide some helper functions to do arithmatic.
Converting the string into a long might get you into problems though. VB's long is a 32 bit signed integer, which means it can store values between -2'147'483'648 and 2'147'483'647. Since the OP is working with 10 digit numbers, he might, for example, have to deal with 3'000'000'000 which won't fit in a long.
- Oliver
.
- Follow-Ups:
- Re: Newbie Question
- From: Frank Swarbrick
- Re: Newbie Question
- References:
- Re: Newbie Question
- From: Frank Swarbrick
- Re: Newbie Question
- Prev by Date: Re: Newbie Question
- Next by Date: Re: Efficient timers in Net Express or Object COBOL
- Previous by thread: Re: Newbie Question
- Next by thread: Re: Newbie Question
- Index(es):
Relevant Pages
|