943,568 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 497
  • VB.NET RSS
Jan 3rd, 2009
0

how to loop this code?

Expand Post »
i want to loop this could because i do not have a fixed number of values:

vb Syntax (Toggle Plain Text)
  1.  
  2. Private VoteArray() As Integer ' Array for items (integers in this case)
  3. Private Const VOTE_ARRY_SIZE As Integer = 3 ' Number of items in the array
  4. ' A help variable to hold "voted number"
  5. Private Voted As Integer
  6.  
  7. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  8. ' Set array size. Notice: arrays are zero-based
  9. ReDim VoteArray(VOTE_ARRY_SIZE - 1)
  10. ' If you have continuous values, use a loop to fill the array
  11. VoteArray(0) = 2
  12. VoteArray(1) = 3
  13. VoteArray(2) = 4
  14.  
  15. End Sub
  16. Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
  17. ' Notice: Voted value is now hard coded, you'll use textbox or something like that
  18. Voted = 2
  19. If [Array].IndexOf(VoteArray, Voted) >= 0 Then
  20. MessageBox.Show("Found", "Vote", MessageBoxButtons.OK, MessageBoxIcon.Information)
  21. Else
  22. MessageBox.Show("Not found", "Vote", MessageBoxButtons.OK, MessageBoxIcon.Information)
  23. End If
  24. End Sub
thanks alot
Last edited by Ancient Dragon; Jan 5th, 2009 at 3:36 pm. Reason: correct code tags and removed manual line numbers
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asif786 is offline Offline
19 posts
since Dec 2008
Jan 5th, 2009
0

Re: how to loop this code?

You don't need a loop. Use a stack, and use the .contains method to see if the stack contains the voter number.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004

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 VB.NET Forum Timeline: Problem with simple ComboBox
Next Thread in VB.NET Forum Timeline: about outlook express





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


Follow us on Twitter


© 2011 DaniWeb® LLC