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. Visual Basic
  4. image loop in vb.net

image loop in vb.net

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structureshelp
13 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.
  • A Alan N

    Hi, 1) You load all images into an array (16 not 15 by the way). 2) When the timer event occurs you should load one image into the PictureBox. What is your timer event handler doing? Alan.

    B Offline
    B Offline
    bapu2889
    wrote on last edited by
    #3

    Hello Thanks for your answer you mean some thing like ths

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    For Me.I = 0 To 15
    PictureBox1.Image = (MyImage(I))
    Next I
    End Sub

    if yes then i have tried but still the same i know there is very small mistake but i am not getting there :confused:

    A 1 Reply Last reply
    0
    • B bapu2889

      Hello all I want to loop images in my application when form loads it loads all the images and displays last image in picture box but i want to display all the images in picture box one by one i mean it starts from image 1 to image 15 and when it's image 15 it should start from image 1 again. this is what i have done

      Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      Call LoadImages()
      End Sub

      Private Sub Timer1\_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
      
          For Me.I = 0 To 15
              PictureBox1.Image = (MyImage(I))
          Next I
      End Sub
      Private Sub LoadImages()
          MyImage(0) = My.Resources.G1
          MyImage(1) = My.Resources.G10
          MyImage(2) = My.Resources.G11
          MyImage(3) = My.Resources.G12
          MyImage(4) = My.Resources.G13
          MyImage(5) = My.Resources.G14
          MyImage(6) = My.Resources.G15
          MyImage(7) = My.Resources.G16
          MyImage(8) = My.Resources.G2
          MyImage(9) = My.Resources.G3
          MyImage(10) = My.Resources.G4
          MyImage(11) = My.Resources.G5
          MyImage(12) = My.Resources.G6
          MyImage(13) = My.Resources.G7
          MyImage(14) = My.Resources.G8
          MyImage(15) = My.Resources.G9
      
      End Sub
      

      it should keep displaying images until user close this application but image should be in right order according to myimage array please help :confused:

      0 Offline
      0 Offline
      0x3c0
      wrote on last edited by
      #4

      Look at LoadImages. Assuming that you want the sequence to go in the order G1, G2, G3, G4, etc., you're setting the array in the wrong order. You load G10 before G2, and so on

      Between the idea And the reality Between the motion And the act Falls the Shadow

      B 1 Reply Last reply
      0
      • 0 0x3c0

        Look at LoadImages. Assuming that you want the sequence to go in the order G1, G2, G3, G4, etc., you're setting the array in the wrong order. You load G10 before G2, and so on

        Between the idea And the reality Between the motion And the act Falls the Shadow

        B Offline
        B Offline
        bapu2889
        wrote on last edited by
        #5

        hello thanks for your rep. no the order in array is right order so all the images should display as per array order what i what to do is when i start app it should display images until i close the app. i mean first image in array and then 2nd and 3rd up to 16th and then 1st image again but now it's load all the images and display only 16th image in to the picture box i want it keep displaying images from first image in array to last image in array and then go back to first image and so on waiting for your kind help

        R 1 Reply Last reply
        0
        • B bapu2889

          Hello Thanks for your answer you mean some thing like ths

          Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
          For Me.I = 0 To 15
          PictureBox1.Image = (MyImage(I))
          Next I
          End Sub

          if yes then i have tried but still the same i know there is very small mistake but i am not getting there :confused:

          A Offline
          A Offline
          Alan N
          wrote on last edited by
          #6

          Hi, Every time the timer event fires you want to display a different image, correct? Within your handler you have written a loop that loads all of the images every time it is called, hence you only ever see the last one, MyImage(15). The code should select one index, i.e. one of the values 0 to 15, and then load the image referenced by the index into the picture box. Alan.

          1 Reply Last reply
          0
          • B bapu2889

            hello thanks for your rep. no the order in array is right order so all the images should display as per array order what i what to do is when i start app it should display images until i close the app. i mean first image in array and then 2nd and 3rd up to 16th and then 1st image again but now it's load all the images and display only 16th image in to the picture box i want it keep displaying images from first image in array to last image in array and then go back to first image and so on waiting for your kind help

            R Offline
            R Offline
            riced
            wrote on last edited by
            #7

            Something like this? :)

            Private Sub Timer1\_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
               Private Shared nextImage As Integer = 0
               PictureBox1.Image = MyImage(nextImage)
               nextImage = (nextImage + 1) Mod 16
            End Sub
            

            Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

            H 1 Reply Last reply
            0
            • R riced

              Something like this? :)

              Private Sub Timer1\_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
                 Private Shared nextImage As Integer = 0
                 PictureBox1.Image = MyImage(nextImage)
                 nextImage = (nextImage + 1) Mod 16
              End Sub
              

              Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

              H Offline
              H Offline
              Henry Minute
              wrote on last edited by
              #8

              Unless I have misread your code, it would not work! Every time the tick event fires you are setting nextImage to 0, before doing anything else, therefore the last line of your snippet is useless. The OP should use something like this:

              Private Sub Timer1\_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
                 PictureBox1.Image = MyImage(Me.I)
                 Me.I = (Me.I + 1) Mod 16
              End Sub
              

              Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

              R 1 Reply Last reply
              0
              • H Henry Minute

                Unless I have misread your code, it would not work! Every time the tick event fires you are setting nextImage to 0, before doing anything else, therefore the last line of your snippet is useless. The OP should use something like this:

                Private Sub Timer1\_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
                   PictureBox1.Image = MyImage(Me.I)
                   Me.I = (Me.I + 1) Mod 16
                End Sub
                

                Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

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

                nextImage is static (i.e. Shared in VB) so it is set to 0 only on first call to Timer1_Tick. It retains its value between successive calls which is what I think the OP requires. The problem with Me.I is it could be changed outside of the handler by some unrelated code. When the handler is called you have no idea what the value of Me.I is so it's wide open to index out of bounds exception.

                Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

                H 1 Reply Last reply
                0
                • R riced

                  nextImage is static (i.e. Shared in VB) so it is set to 0 only on first call to Timer1_Tick. It retains its value between successive calls which is what I think the OP requires. The problem with Me.I is it could be changed outside of the handler by some unrelated code. When the handler is called you have no idea what the value of Me.I is so it's wide open to index out of bounds exception.

                  Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

                  H Offline
                  H Offline
                  Henry Minute
                  wrote on last edited by
                  #10

                  OK. Sorry I missed that. :-O

                  Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                  R 1 Reply Last reply
                  0
                  • H Henry Minute

                    OK. Sorry I missed that. :-O

                    Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                    R Offline
                    R Offline
                    riced
                    wrote on last edited by
                    #11

                    Easily done - often guilty of it myself. :) When I thought about the bounds it struck me that this is better.

                    Private Sub Timer1\_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
                       Private Shared nextImage As Integer = 0
                       PictureBox1.Image = MyImage(nextImage)
                       nextImage = (nextImage + 1) Mod MyImage.Length
                    End Sub
                    

                    Then you don't have to do anything if more images are added or some removed.

                    Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

                    B H 2 Replies Last reply
                    0
                    • R riced

                      Easily done - often guilty of it myself. :) When I thought about the bounds it struck me that this is better.

                      Private Sub Timer1\_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
                         Private Shared nextImage As Integer = 0
                         PictureBox1.Image = MyImage(nextImage)
                         nextImage = (nextImage + 1) Mod MyImage.Length
                      End Sub
                      

                      Then you don't have to do anything if more images are added or some removed.

                      Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

                      B Offline
                      B Offline
                      bapu2889
                      wrote on last edited by
                      #12

                      hello thanks for your rep. yes it's works fine this is what i changed

                      Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

                          'PictureBox1.Image = (MyImage(I))
                          Static nextImage As Integer = 0
                          PictureBox1.Image = MyImage(nextImage)
                          nextImage = (nextImage + 1) Mod MyImage.Length
                      End Sub
                      

                      it's working as i was trying to thanks a lot sir have a nice day :-D

                      1 Reply Last reply
                      0
                      • R riced

                        Easily done - often guilty of it myself. :) When I thought about the bounds it struck me that this is better.

                        Private Sub Timer1\_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
                           Private Shared nextImage As Integer = 0
                           PictureBox1.Image = MyImage(nextImage)
                           nextImage = (nextImage + 1) Mod MyImage.Length
                        End Sub
                        

                        Then you don't have to do anything if more images are added or some removed.

                        Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

                        H Offline
                        H Offline
                        Henry Minute
                        wrote on last edited by
                        #13

                        riced wrote:

                        Then you don't have to do anything if more images are added or some removed.

                        Good point. I really should practice VB.Net more, if I want to play over here. :)

                        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                        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