Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Dim i As Integer
For i = 0 To UBound(userManagement.names)
If userManagement.names(i) = nameTf.Text Then
MessageBox.Show("Name already present in the database" )
Exit For
Else
nameDis = nameTf.Text
userManagement.AddUserPass(firstChar, nameDis)
Exit For
End If
Next

 

userManagement is just a module i made for the storing of values into array.

 

what i'm trying to do is:

If the user enters a name into the textbox, and the name is already in the array, then it will show the error message.

 

what the problem is:

For the first name i enter (eg. Jim). after i reenter the name again, it shows the error message.

But after the first name works, I tried to enter another name (eg. ZC). i can just add the value into the array again and again without showing the error message.

 

anyone can help?

Edited by divil
  • *Gurus*
Posted

Follow your code through, you should see the problem. Stepping through with the debugger would probably help too. Your loop should come first, and do nothing except go through looking for duplicates. If it finds one, it displays the messagebox and exits the entire function (not just that loop).

 

The code after the loop will only be reached if no duplicates were found, and that will simple add to the array.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted
Follow your code through, you should see the problem. Stepping through with the debugger would probably help too. Your loop should come first, and do nothing except go through looking for duplicates. If it finds one, it displays the messagebox and exits the entire function (not just that loop).

 

The code after the loop will only be reached if no duplicates were found, and that will simple add to the array.

 

is it possible you could do an example? cause really dont know where & how to start about it.

  • *Gurus*
Posted
Dim i As Integer

For i = 0 To UBound(userManagement.names)
   If userManagement.names(i) = nameTf.Text Then
       MessageBox.Show("Name already present in the database" )
       Return
   Next
Next

nameDis = nameTf.Text
userManagement.AddUserPass(firstChar, nameDis)

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

divil.. i am interested in your use of the Return statement in that code... I would think that wouldn't work (syntax error or ....)

care to explain?

i'm not lazy i'm just resting before i get tired.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...