Solved

Random Number Length

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

756 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