how to loop this code?

Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Dec 2008
Posts: 14
Reputation: asif786 is an unknown quantity at this point 
Solved Threads: 0
asif786 asif786 is offline Offline
Newbie Poster

how to loop this code?

 
0
  #1
Jan 3rd, 2009
i want to loop this could because i do not have a fixed number of values:

  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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: how to loop this code?

 
0
  #2
Jan 5th, 2009
You don't need a loop. Use a stack, and use the .contains method to see if the stack contains the voter number.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
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