0

I have created a function :

    Function randomid() As String
    Try
        Dim i As Integer
        Dim temp As String = ""
        Dim rnd As New Random
        i = rnd.Next(100, 99999)
        temp = "ABC" & i
        Dim count As Integer = Dal.ExecuteScalar("select count(*) from property where property_id='" & temp & "'")
        If count > 0 Then
            randomid()
        Else
            Return temp
        End If
    Catch ex As Exception

    End Try
End Function

And i am calling above function from within below sub :

Sub AcresImport()
  For Each ..loop
      Dim propId As String = randomid()
  Next
End Sub

It is working fine sometimes only. I mean it is creating propId randomly for some iterations. For Ex - If there are 3 interations in the above loop, it will randomly create propId for Ist two iterations or only Ist iteration ..means radomly.

But when i debug through it, it will create all 3 propIds for 3 iterations correctly.

So i can't understand when it is working fine when i debug..then why it is not working correctly when i simply run it.

Please help.

David
  • 349
  • 3
  • 13
  • 26
  • 1
    I think you are winning the first prize for the millionth question on this. See this http://stackoverflow.com/questions/767999/random-number-generator-only-generating-one-random-number – Steve May 14 '13 at 12:50
  • Thanks..Actually i have to see before asking..Thank Steve. – David May 14 '13 at 13:40

0 Answers0