Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Random Number Length

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 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