-
VB.NET (
http://www.daniweb.com/forums/forum58.html)
| asif786 | Jan 3rd, 2009 2:56 pm | |
| how to loop this code? i want to loop this could because i do not have a fixed number of values:
Private VoteArray() As Integer ' Array for items (integers in this case)
Private Const VOTE_ARRY_SIZE As Integer = 3 ' Number of items in the array
' A help variable to hold "voted number"
Private Voted As Integer
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Set array size. Notice: arrays are zero-based
ReDim VoteArray(VOTE_ARRY_SIZE - 1)
' If you have continuous values, use a loop to fill the array
VoteArray(0) = 2
VoteArray(1) = 3
VoteArray(2) = 4
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
' Notice: Voted value is now hard coded, you'll use textbox or something like that
Voted = 2
If [Array].IndexOf(VoteArray, Voted) >= 0 Then
MessageBox.Show("Found", "Vote", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Not found", "Vote", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub thanks alot |
| Comatose | Jan 5th, 2009 1:14 am | |
| 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. |
| All times are GMT -4. The time now is 1:17 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC