• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

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
0
rinkydink
Asked:
rinkydink
1 Solution
 
rinkydinkAuthor Commented:
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
 
Jaime OlivaresCommented:
Text1 = chr$(Rnd*10+48)+chr$(Rnd*10+48)+chr$(Rnd*10+48)+chr$(Rnd*10+48)+chr$(Rnd*10+48)
0
 
JR2003Commented:
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
 
JR2003Commented:
Alternativley just change the line:
Text1 = num
to
Text1 = Format(num,"00000")
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now