If any of item in Array

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2008
Posts: 4
Reputation: raavi.munaf is an unknown quantity at this point 
Solved Threads: 0
raavi.munaf raavi.munaf is offline Offline
Newbie Poster

If any of item in Array

 
0
  #1
Aug 25th, 2009
Dim Friends(0 To 10) As String

Private Sub Command1_Click()
If Friends(any) = text1.text Then   '(what should I put here instead of any?)
MsgBox "You already have " &  text1.text " in the list 
else

end if
End Sub

In above code
I have an empty array of 10 friends
I have a button,
on pressing it I can add a new friend in any array

I want such a code:

While adding a new friend, it should prompt if the friend is already available in array.

Please Help!
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 865
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 157
vb5prgrmr vb5prgrmr is offline Offline
Practically a Posting Shark

Re: If any of item in Array

 
0
  #2
Aug 25th, 2009
You will need a variable to keep track of how many friends have been entered.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim MyFriendCount As Integer, LoopCounter As Integer
Then you will need to initialize your friend counter
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. MyFriendCount = -1
Then you will need to test to see if you haved entered any friends yet...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim FoundFriend As Boolean
  2. If MyFriendCount = -1 Then 'no friend have been entered
But if they have then you need to test if you have reached the limit...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ElseIf MyFriendCount > 10 Then 'too many friends or you need to redimension array so notify user...
Then of course if you have not exceeded the friend count...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Else 'need to check to see if you have already entered friend
  2. For LoopCounter = 0 To MyFriendCount
  3. If UCase(Text1.Text) = UCase(Friends(LoopCount)) Then
  4. FoundFriend = True
  5. Else
  6. FoundFriend = False
  7. End If
  8. Next LoopCount
  9.  
  10. If FoundFriend = True Then
  11. 'notify user
  12. Else
  13. MyFriendCount = MyFriendCount + 1
  14. Friends(MyFriendCount) = Text1.Text
  15. End If
  16. End If


Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 4
Reputation: raavi.munaf is an unknown quantity at this point 
Solved Threads: 0
raavi.munaf raavi.munaf is offline Offline
Newbie Poster

Re: If any of item in Array

 
0
  #3
Aug 25th, 2009
Dear Friend
Thanks!

I will surely add you as a friend in my array.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC