Link to home
Start Free TrialLog in
Avatar of rinkydink
rinkydink

asked on

need 0 to always show in text box

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
Avatar of rinkydink
rinkydink

ASKER

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
Text1 = chr$(Rnd*10+48)+chr$(Rnd*10+48)+chr$(Rnd*10+48)+chr$(Rnd*10+48)+chr$(Rnd*10+48)
ASKER CERTIFIED SOLUTION
Avatar of JR2003
JR2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Alternativley just change the line:
Text1 = num
to
Text1 = Format(num,"00000")
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