Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

need 0 to always show in text box

Posted on 2004-08-26
5
Medium Priority
?
196 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

618 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