Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. vb.net, check array elements?

vb.net, check array elements?

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpdata-structures
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    golisarmi
    wrote on last edited by
    #1

    I need to check all element of an array to see if all are equal to 1 or 'T' then do something. how can i do this?

    N 1 Reply Last reply
    0
    • G golisarmi

      I need to check all element of an array to see if all are equal to 1 or 'T' then do something. how can i do this?

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      My first guess would be to iterate over the array and check the values, but of course that may be to simple for you to figure out.


      I know the language. I've read a book. - _Madmatt

      G 1 Reply Last reply
      0
      • N Not Active

        My first guess would be to iterate over the array and check the values, but of course that may be to simple for you to figure out.


        I know the language. I've read a book. - _Madmatt

        G Offline
        G Offline
        golisarmi
        wrote on last edited by
        #3

        loop cant help because, may be I'm missing something for i=0 to array.length-1 if array(0) = 1 then check = true else check = false end if next this doent work for me because if the last element is 1 then the check(boolean variable)becomes true while it is possible that other elements for example first one is not equal to 1. but I need to make sure are all of them (all elements) are equal to 1 or not. Help please

        N G R 3 Replies Last reply
        0
        • G golisarmi

          loop cant help because, may be I'm missing something for i=0 to array.length-1 if array(0) = 1 then check = true else check = false end if next this doent work for me because if the last element is 1 then the check(boolean variable)becomes true while it is possible that other elements for example first one is not equal to 1. but I need to make sure are all of them (all elements) are equal to 1 or not. Help please

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          golisarmi wrote:

          may be I'm missing something

          Yes, you are. This is a good exercise to weed out the pretenders from the performers. Which are you?


          I know the language. I've read a book. - _Madmatt

          G 1 Reply Last reply
          0
          • N Not Active

            golisarmi wrote:

            may be I'm missing something

            Yes, you are. This is a good exercise to weed out the pretenders from the performers. Which are you?


            I know the language. I've read a book. - _Madmatt

            G Offline
            G Offline
            golisarmi
            wrote on last edited by
            #5

            are you here to help people, specially beginners or to blame them. if you don’t know or don't want to say please don’t annoy them. Anybody else could help?

            N 1 Reply Last reply
            0
            • G golisarmi

              loop cant help because, may be I'm missing something for i=0 to array.length-1 if array(0) = 1 then check = true else check = false end if next this doent work for me because if the last element is 1 then the check(boolean variable)becomes true while it is possible that other elements for example first one is not equal to 1. but I need to make sure are all of them (all elements) are equal to 1 or not. Help please

              G Offline
              G Offline
              Gideon Engelberth
              wrote on last edited by
              #6

              You should probably encapsulate this into a function and return false for the first one that does not match and return true if you get to the end of the array without finding one that does not match. Incidentally, if you are using .NET 3.5, the built in All extension method from LINQ will do just that.

              G 1 Reply Last reply
              0
              • G golisarmi

                are you here to help people, specially beginners or to blame them. if you don’t know or don't want to say please don’t annoy them. Anybody else could help?

                N Offline
                N Offline
                Not Active
                wrote on last edited by
                #7

                We are here to help, not give you everything. This is a very simple exercise in logic, don't get upset if you are not up to the task.

                golisarmi wrote:

                or to blame them

                Read the previous posts carefully, there is no blame being assigned You are still new here so I would hold the attitude if I where you.


                I know the language. I've read a book. - _Madmatt

                1 Reply Last reply
                0
                • G Gideon Engelberth

                  You should probably encapsulate this into a function and return false for the first one that does not match and return true if you get to the end of the array without finding one that does not match. Incidentally, if you are using .NET 3.5, the built in All extension method from LINQ will do just that.

                  G Offline
                  G Offline
                  golisarmi
                  wrote on last edited by
                  #8

                  Gideon Thanks for response.

                  1 Reply Last reply
                  0
                  • G golisarmi

                    loop cant help because, may be I'm missing something for i=0 to array.length-1 if array(0) = 1 then check = true else check = false end if next this doent work for me because if the last element is 1 then the check(boolean variable)becomes true while it is possible that other elements for example first one is not equal to 1. but I need to make sure are all of them (all elements) are equal to 1 or not. Help please

                    R Offline
                    R Offline
                    RugbyLeague
                    wrote on last edited by
                    #9

                    check=true for i=0 to array.length-1 if array(0) <> 1 then check = false exit for end if next

                    D 1 Reply Last reply
                    0
                    • R RugbyLeague

                      check=true for i=0 to array.length-1 if array(0) <> 1 then check = false exit for end if next

                      D Offline
                      D Offline
                      Dhyanga
                      wrote on last edited by
                      #10

                      I think this should work. If it doesn't, reply me back.. for i=0 to array.length-1 if array(i) = 1 then check = true else check = false end if next

                      suchitamanandhar@hotmail.com

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups