RSS Forums RSS

how to loop this code?

Please support our VB.NET advertiser: DiscountASP.NET – 3 Months Free on VB.NET Web Hosting
Reply
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?

  #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 2:36 pm. Reason: correct code tags and removed manual line numbers
AddThis Social Bookmark Button
Reply With Quote  
Posts: 2,404
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: 209
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: how to loop this code?

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 326 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:28 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC