i am using vb dot net. i want to store multiple values in a variable and then check whether any of the values held in the variable match what the user inputs. Please help i can not code it , i tried but failed.

This is not homework just a practice task so that i am able to code in vb dot net

could you please elaborate on answers as i do not how i would use arrays in this way thanks

i couldn't do it with arrays so tried with if statements and variable si know it doesn't work but just did it, to show you guys that i tried .

here is my code:

[ code] If voter number = voternumcheck Then
MsgBox("Please choose how you will like your voting to take place by clicking the appropriate button")
btnvotes.Enabled = True
btnpercentage.Enabled = True
Else code]

9 Years
Discussion Span
Last Post by Teme64

Here's a sample how to work with arrays

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)
    MessageBox.Show("Not found", "Vote", MessageBoxButtons.OK, MessageBoxIcon.Information)
  End If

End Sub

Suggested reading: Array Class in MSDN

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.