Link to home
Start Free TrialLog in
Avatar of R_Thomas
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?
Avatar of Mike McCracken
Mike McCracken

Try this

temp = CStr(CDbl(Now))
msgbox temp
pos = InStr(1, temp, ".")
msgbox pos


What values are you getting?

mlmcc
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

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

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
good job nambi but i dont intend to cast it into a dbl
Good luck.  Glad to help

mlmcc