?
Solved

need 0 to always show in text box

Posted on 2004-08-26
5
Medium Priority
?
195 Views
Last Modified: 2010-05-02
num = Int(Rnd * 10) & Int(Rnd * 10) & Int(Rnd * 10) & Int(Rnd * 10) & Int(Rnd * 10)
Text1 = num

with the above code, my 0's do not always appear

i am not sure why

i need five numbers everytime from 0 to 9

any ideas?

thanks for any help
0
Comment
Question by:rinkydink
[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
5 Comments
 
LVL 1

Author Comment

by:rinkydink
ID: 11910131
just thought i'd add that num is declared as Long

and it seems like i am always missing 0's at the end of my number

i need them to show so i have a 5 digit number everytime

thanks
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11910150
Text1 = chr$(Rnd*10+48)+chr$(Rnd*10+48)+chr$(Rnd*10+48)+chr$(Rnd*10+48)+chr$(Rnd*10+48)
0
 
LVL 18

Accepted Solution

by:
JR2003 earned 400 total points
ID: 11910166
num is probably a variant assuming itself as a number type variable and missing off leading zeros.
You need to explicitly define your variable 'num' to be a String.
i.e.
Dim num as String
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11910170
Alternativley just change the line:
Text1 = num
to
Text1 = Format(num,"00000")
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11910185
Option Explicit

Private Sub Form_Load()
    Randomize Timer
End Sub

Private Sub Command1_Click()
    ' Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
    Dim lngNum As Long
    Dim strNum
   
    lngNum = CLng((99999 - 0 + 1) * Rnd + 0)
    strNum = Format(lngNum, "00000")
    Label1.Caption = strNum
End Sub

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

800 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