Solved

Random Number Length

Posted on 2012-03-21
3
265 Views
Last Modified: 2012-08-14
When I run this code:
MsgBox (Int((rs!startnumber - rs!endnumber + 1) * Rnd + rs!endnumber) )

it returns the value of 12

When I run this code:
MsgBox (Len(Int((rs!startnumber - rs!endnumber + 1) * Rnd + rs!endnumber)))

it returns the value of 1

The len function is not returning the correct number of characters.  Why? Thanks!
0
Comment
Question by:Sasha42
3 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 37748565
Well, the random number isn't fixed!

Try this:

intN = Int((rs!startnumber - rs!endnumber + 1) * Rnd + rs!endnumber)
MsgBox (Len(intN))

/gustav
0
 
LVL 18

Accepted Solution

by:
Cluskitt earned 500 total points
ID: 37748574
If the numbers are random, it could happen that it returned a number of 0-9, depending on your values.
The best way to test it is:
MsgBox (Int((rs!startnumber - rs!endnumber + 1) * Rnd + rs!endnumber)) & " (Len: " & (Len(Int((rs!startnumber - rs!endnumber + 1) * Rnd + rs!endnumber))) & ")"
which will return both the number and the length.
Also, you might want to convert the number into a string for Len. The len function is a bit quirky with integer/double:
MsgBox (Cstr(Int((rs!startnumber - rs!endnumber + 1) * Rnd + rs!endnumber))) & " (Len: " & (Len(Cstr(Int((rs!startnumber - rs!endnumber + 1) * Rnd + rs!endnumber)))) & ")"
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37748678
To be clear:

MsgBox (Int((rs!startnumber - rs!endnumber + 1) * Rnd + rs!endnumber) )
...returns the actual *Number*

MsgBox (Len(Int((rs!startnumber - rs!endnumber + 1) * Rnd + rs!endnumber)))
...returns the *number of characters* in the number.

So they may rarely be the same...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now