1 Replies - 293 Views - Last Post: 27 October 2020 - 12:10 PM Rate Topic: -----

#1 leomarrg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 26-November 19

How to validate data in a nested loop?

Posted 27 October 2020 - 12:06 PM

This is what i have. I'm trying to validate numeric input from the input box and add those numbers to a 5x4 vector
For Index = 0 To 4
                For InnerIndex = 0 To 3

                    Try

                        TempInt = CInt(Question)
                        StudentsScores(Index, InnerIndex) = TempInt
                        lstStudentsScores.Items.Add(StudentsScores(Index, InnerIndex))
                    Catch ex As Exception
                        MessageBox.Show("Error!")
                    End Try

                    ' StudentsScores(Index, InnerIndex) = InputBox("Enter students scores:", "Students Scores")
                    ' lstStudentsScores.Items.Add(StudentsScores(Index, InnerIndex))

                Next
            Next

When i input a number i get the same number added to the listbox and the 5x4 vector. Also if i get the wrong input message i get the error message 20 times how do i stop this?

Is This A Good Question/Topic? 0
  • +

Replies To: How to validate data in a nested loop?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15965
  • View blog
  • Posts: 63,898
  • Joined: 12-June 08

Re: How to validate data in a nested loop?

Posted 27 October 2020 - 12:10 PM

You don't use a loop for your input. Your program would have two global variables for row and column. Each time a value is entered, increment those accordingly until your limit is met.

Alternatively you could have the user enter a lot of numbers, separated by spaces or commas, and use 'string.split' to get those values in an array.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1