none
PictureBox image troubles RRS feed

  • Question

  • I am trying to troubleshoot a program for a class, and I cannot understand why the pictures will not update.

     

    Public Class Form1                                                                                                                                                          Dim intCounter As Integer
        Private Sub tmrSpeed_Tick(sender As Object, e As EventArgs) Handles tmrSpeed.Tick

            Static intCounter As Integer = 0

            Select Case intCounter
                Case 0   'These image files are added to the program, I can change the picBox manually (they are frames of animation)
                    Me.picSpaceRunner.Image = My.Resources.r0
                Case 1
                    Me.picSpaceRunner.Image = My.Resources.r1
                Case 2
                    Me.picSpaceRunner.Image = My.Resources.r2
                Case 3
                    Me.picSpaceRunner.Image = My.Resources.r3
                Case 4
                    Me.picSpaceRunner.Image = My.Resources.r4
                Case 5
                    Me.picSpaceRunner.Image = My.Resources.r5
                Case 6
                    Me.picSpaceRunner.Image = My.Resources.r6
                Case 7
                    Me.picSpaceRunner.Image = My.Resources.r7
                Case 8
                    Me.picSpaceRunner.Image = My.Resources.r8
                Case 9
                    Me.picSpaceRunner.Image = My.Resources.r9
            End Select

            intCounter += 1

            If intCounter = 10 Then
                intCounter = 0
            End If

        End Sub

    Saturday, December 15, 2018 5:15 PM

All replies

  • Have you tried setting a breakpoint on Select Case intCounter, when hit step thru the code to ensure it's executing properly?

    Also note two variables, one form level, one static procedure level is not wise.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Saturday, December 15, 2018 5:19 PM
    Moderator
  • The select case doesn't appear to be executing at all (no clue as to why).

    As for the variable, my teacher said we needed it to be global but it needed to be static for the select case. This was the only way I could come up with, as I was unable to declare the variable as static outside of the sub procedure.

    Saturday, December 15, 2018 5:35 PM
  • The select case doesn't appear to be executing at all (no clue as to why).

    As for the variable, my teacher said we needed it to be global but it needed to be static for the select case. This was the only way I could come up with, as I was unable to declare the variable as static outside of the sub procedure.

    Do you have this somewhere? Otherwise your code seems to work.

      tmrSpeed.Start()
    Plus what interval do you have set for the timer?



    Saturday, December 15, 2018 5:53 PM
  • The select case doesn't appear to be executing at all (no clue as to why).

    As for the variable, my teacher said we needed it to be global but it needed to be static for the select case. This was the only way I could come up with, as I was unable to declare the variable as static outside of the sub procedure.

     You would not declare it as Static outside the sub,  you would use the Dim statement or even one of the other Access Level Specifiers when declaring a Globally scoped variable.  For your needs,  you should probably just use the Dim statement to declare it globally.

    Dim intCounter As Integer = 0

     

     Also,  I believe that Tom has given you the places to look for why the Select Case is never executed,  the Timer has either never been started/enabled,  or the Timer's Interval property is set way to small/quick or way to large/slow.  By default the Interval is set to 100 milliseconds which is 1/10th of a second which is way to fast.  You would probably want to set it to 1000 milliseconds (1 second),  or larger.


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Sunday, December 16, 2018 2:00 AM
    Sunday, December 16, 2018 1:56 AM
  • Hi,

    It may be no tmrSpeed set:

    add code:

       Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            tmrSpeed.Enabled = True
            tmrSpeed.Interval = 1000
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 17, 2018 6:21 AM