For my user system, I require each user to have a unique id. The reading in and saving of the user data is all done, but now I'm focusing on adding new users.

In my add user dialog, I have the information fields required to create a new user, one of which is the ID (which must be unique). For this I have created a function that I thought would always give a unique id but it does not. I'll paste the code below and hopefully you can tell me what I've done wrong!!

Function getnextuserid()
        Dim id As String
        Dim unique As Boolean
        unique = False
        getnextuserid = 1
        Do Until unique = True
            For counter = 1 To maxsize
                Debug.Print(getnextuserid)
                id = userdata(counter).id
                If getnextuserid = id Then
                    unique = False
                    getnextuserid = getnextuserid + 1
                Else
                    unique = True
                End If
            Next
        Loop
    End Function

Many thanks, James

Do you use any data base for your project? If yes then why cant you do it at the backend?

No I don't, all the data is stored in text files. I think I have found the solution, after line 12 you reset the counter back to 1.

Thanks anyway!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.