Array of number - order check

Antrac1t

Member
Joined
Apr 28, 2014
Messages
13
Programming Experience
Beginner
Hi guys,
i want to ask if is possible to check if user input data in specific order which is specified from array [5,3,7,2,1,4,6] and I want to that user will type 5,3,7,2,1,4,6 and if it will be different then it will call "please follow instructions". I want to avoid select case

thank

Antra
 
That's actually very easy. As the user enters the values, add them to a List(Of Integer). Once all the data has been entered, you can compare that List to your initial Integer array with one line of code:
If myList.SequenceEqual(myArray) Then
    'The two sequences are the same.
Else
    'They are not the same.
End If
 
thanks for your answer,
problem is that the compare loop must be every time when user enter some value

we have [5,3,7,2,1,4,6]

user inputs | system
1,input : 4 | you write 4 but you should 5!!
2,input : 7 | you write 7 but you should 5!!
3,input : 5 | good one
4,input : 3 | good one
5,input : 7 | you already put this number !!! you should hit 2 now!!
etc

if you understand

thanks
 
problem is that the compare loop must be every time when user enter some value

And you thought it would be a good idea to keep that a secret? Ne3xt time, please provide ALL the relevant information in your first post. If you don't tell us that your code has to do something in particular then why would we provide code that does that?

Anyway, I would suggest that you start by declaring a variable to store the index of the number currently being entered. You can then use a Do loop. In each iteration, get the input from the user and compare it to the element of the array at the current index. If they don't match then display the appropriate error message and if they do match then display the confirmation message and increment the index. Once the index goes beyond the upper bound of the array, exit out of the loop.
 
Back
Top