Solved

Random Number Length

Posted on 2012-03-21
3
264 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

758 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

16 Experts available now in Live!

Get 1:1 Help Now