Solved

Random Number Length

Posted on 2012-03-21
3
272 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
[X]
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
3 Comments
 
LVL 50

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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…

738 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