View Single Post
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