Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Int and Fix functions don't strip decimals

Status
Not open for further replies.

huggybear

Technical User
Feb 15, 2001
83
0
0
US
I'll start by saying I'm new at Crystal but have a lot of experience with VB and VBA.

So, I'm using Basic syntax in 8.5 because that's what I'm familiar with. My problem is that I need to manipulate integers to construct an account number with a check digit at the end and all my numbers wind up with 2 decimal points.

Neither of the functions that I believe should leave me with whole numbers are working.

I start with a text field account number of 6 digits. I then must break out each digit so it can be processed. I convert the original account number to a number array using a loop and the mid function like this:

Code:
for i = 1 to len(strAcctNum)
    Redim Preserve x(i)
    x(i) = fix(CDbl(mid(strAcctNum, i, 1)))
    z(i) = fix(x(i)*y(i))
    if z(i) >= 10 then
        dim j as number
        j = fix(z(i))
        z(i) = fix((j mod 10) + (j\10))
    end if
    strAcctChkNum = strAcctChkNum & " " & fix(z(i))
next

I guess you can probably figure out the rest of what I'm doing with the code shown. I have a ton of fix functions in there because so far none has worked and I wanted to make sure there were no places decimals could sneak in. As it is now I'm using fix functions because the int() function didn't work either and that's the one I tried first.

I'd sure be grateful for any help!

Thanks, Bear
 
Posting technical information would be helpful, such as:

Database/connectivity
Example data
Expected output

I'm somewhat at a loss for what the problem is, this doesn't work, or you don't like the code, or?

I would suggest building out a function for this check digit on the database.

If the concern is that you are appending values to a string and getting unwanted decimals, use:

strAcctChkNum = strAcctChkNum & " " & TOTEXT(z(i),0,"")

The totext 0 parameter states the decimal precision and the "" states the thousands seperator.

-k
 
Thanks for the ToText idea. It worked great. You're my best friend for the rest of the afternoon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top