943,603 Members | Top Members by Rank

Ad:
Aug 25th, 2009
0

If any of item in Array

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
raavi.munaf is offline Offline
4 posts
since Aug 2008
Aug 25th, 2009
0

Re: If any of item in Array

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
Reputation Points: 156
Solved Threads: 296
Posting Virtuoso
vb5prgrmr is offline Offline
1,670 posts
since Mar 2009
Aug 25th, 2009
0

Re: If any of item in Array

Dear Friend
Thanks!

I will surely add you as a friend in my array.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
raavi.munaf is offline Offline
4 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: SQL command and vb6
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Auto Increent Value and Then Save it.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC