R_Thomas
asked on
Create a random number with now as the seed
hello,
below is the prob plz help.
Dim temp As String
Dim pos As Long
Dim seed As Double
temp = CStr(CDbl(Now))
pos = InStr(1, temp, ".")
seed = CLng(Mid(temp, (pos + 1)))'//i get an error of
'//over flow here..can u pls help
'//help me i think there is somehting
'//wrong with seed variable
'//should it be long o string
'//can u try the ques on vb6 and
'//and correct the error?
Randomize (seed)
'why am i doin this?i need to generate a random number for my access database so that i have a autonumber generated wheneven a record is generated..i need a huge auto number..can u pls help me?
below is the prob plz help.
Dim temp As String
Dim pos As Long
Dim seed As Double
temp = CStr(CDbl(Now))
pos = InStr(1, temp, ".")
seed = CLng(Mid(temp, (pos + 1)))'//i get an error of
'//over flow here..can u pls help
'//help me i think there is somehting
'//wrong with seed variable
'//should it be long o string
'//can u try the ques on vb6 and
'//and correct the error?
Randomize (seed)
'why am i doin this?i need to generate a random number for my access database so that i have a autonumber generated wheneven a record is generated..i need a huge auto number..can u pls help me?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
Dim temp As String
Dim pos As Long
Dim seed As Double
temp = CStr(CDbl(Now))
pos = InStr(1, temp, ".")
seed = CDbl(Mid(temp, (pos + 1)))
'Here U Use CLng Conversion. So U Get Overflow Error.
' Now it Will Work finely.
Randomize (seed)
MsgBox seed
Regards,
Nambi
Dim temp As String
Dim pos As Long
Dim seed As Double
temp = CStr(CDbl(Now))
pos = InStr(1, temp, ".")
seed = CDbl(Mid(temp, (pos + 1)))
'Here U Use CLng Conversion. So U Get Overflow Error.
' Now it Will Work finely.
Randomize (seed)
MsgBox seed
Regards,
Nambi
the code below worked fine for me using vb6...
if you need a huge autonumber you might try generating a dummy records yourself and then deleting them.
-------------------------- ---------- ---------- -
Private Sub Form_Load()
Dim temp As String
Dim pos As Long
Dim seed As Double
temp = CStr(CDbl(Now))
pos = InStr(1, temp, ".")
seed = CLng(Mid(temp, (pos + 1))) '//i get an error of
'//over flow here..can u pls help
'//help me i think there is somehting
'//wrong with seed variable
'//should it be long o string
'//can u try the ques on vb6 and
'//and correct the error?
Randomize (seed)
MsgBox seed 'this works find for me using vb6
End Sub
if you need a huge autonumber you might try generating a dummy records yourself and then deleting them.
--------------------------
Private Sub Form_Load()
Dim temp As String
Dim pos As Long
Dim seed As Double
temp = CStr(CDbl(Now))
pos = InStr(1, temp, ".")
seed = CLng(Mid(temp, (pos + 1))) '//i get an error of
'//over flow here..can u pls help
'//help me i think there is somehting
'//wrong with seed variable
'//should it be long o string
'//can u try the ques on vb6 and
'//and correct the error?
Randomize (seed)
MsgBox seed 'this works find for me using vb6
End Sub
ASKER
actually
Dim temp As String
Dim pos As Long
Dim seed As Double
temp = CStr(CDbl(Now))
pos = InStr(1, temp, ".")
seed = CDbl(Mid(temp, (pos + 1)))
'Here U Use CLng Conversion. So U Get Overflow Error.
' Now it Will Work finely.
this is the solotion..
which was provided by another guy..but actually u tried harder..ppl like u are the good type cause they try their best to help.
thanks for ur help
thanks for not giving up..
god bless
i also wanan be a man who doesnt give up
Dim temp As String
Dim pos As Long
Dim seed As Double
temp = CStr(CDbl(Now))
pos = InStr(1, temp, ".")
seed = CDbl(Mid(temp, (pos + 1)))
'Here U Use CLng Conversion. So U Get Overflow Error.
' Now it Will Work finely.
this is the solotion..
which was provided by another guy..but actually u tried harder..ppl like u are the good type cause they try their best to help.
thanks for ur help
thanks for not giving up..
god bless
i also wanan be a man who doesnt give up
ASKER
good job nambi but i dont intend to cast it into a dbl
Good luck. Glad to help
mlmcc
mlmcc
temp = CStr(CDbl(Now))
msgbox temp
pos = InStr(1, temp, ".")
msgbox pos
What values are you getting?
mlmcc