VB.NET Image Control Array

Hi,

I have been sitting in front of my PC for about 12 hours trying to figure out this problem so I think it is time for some help.

I am trying to design a simple game that moves a series of images across the screen using a control array.  The direction of the moving images is dependant on whether the user clicks the right or left command button.

The program starts with a static image on the left hand side of the screen and when the user clicks the 'Right' button it should start moving in that direction, cycling through 6 images until it reaches the other side of the screen.

I have got it so it displays the starting image on the left side of the screen, but when I click the 'Right' button it comes up with an error:

Object variable With block variable not set

I haven't got a clue what this means and once it has given me the error message it starts to move the static image across the screen, but it does not cycle through them.

I am very confused and frustrated with this whole thing and don't think I have explained it very well but please help.

Thanks in advance,

John
LVL 14
john-formbyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeff CertainCommented:
The error means that you are trying to reference some variable with setting it... i.e. dim var as vartype = new vartype
0
john-formbyAuthor Commented:
Thanks for the reply but I am still confused.  I have only been using VB for about three weeks so I don't know a lot :-)

Here is the code for what I have done so far.  If you could have a look at it I would be very grateful.

Option Strict Off
Option Explicit On
Public Class Form1
    Inherits System.Windows.Forms.Form
    Public imgLeft()
    Public imgRight()
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents cmdStop As System.Windows.Forms.Button
    Friend WithEvents cmdRight As System.Windows.Forms.Button
    Friend WithEvents cmdJump As System.Windows.Forms.Button
    Friend WithEvents cmdReset As System.Windows.Forms.Button
    Friend WithEvents cmdExit As System.Windows.Forms.Button
    Friend WithEvents cmdLeft As System.Windows.Forms.Button
    Friend WithEvents hsbSpeed As System.Windows.Forms.HScrollBar
    Friend WithEvents lblSpeed As System.Windows.Forms.Label
    Friend WithEvents lblFast As System.Windows.Forms.Label
    Friend WithEvents lblSlow As System.Windows.Forms.Label
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents imgPath As System.Windows.Forms.PictureBox
    Friend WithEvents imgWall As System.Windows.Forms.PictureBox
    Friend WithEvents imgStandLeft As System.Windows.Forms.PictureBox
    Friend WithEvents imgFlatLeft As System.Windows.Forms.PictureBox
    Friend WithEvents imgFlatRight As System.Windows.Forms.PictureBox
    Friend WithEvents imgStandRight As System.Windows.Forms.PictureBox
    Friend WithEvents imgPerson As System.Windows.Forms.PictureBox
    Friend WithEvents imgOuch As System.Windows.Forms.PictureBox
    Friend WithEvents _imgRight_0 As System.Windows.Forms.PictureBox
    Friend WithEvents _imgRight_1 As System.Windows.Forms.PictureBox
    Friend WithEvents _imgRight_3 As System.Windows.Forms.PictureBox
    Friend WithEvents _imgLeft_0 As System.Windows.Forms.PictureBox
    Friend WithEvents _imgLeft_3 As System.Windows.Forms.PictureBox
    Friend WithEvents _imgLeft_1 As System.Windows.Forms.PictureBox
    Friend WithEvents _imgLeft_2 As System.Windows.Forms.PictureBox
    Friend WithEvents _imgRight_5 As System.Windows.Forms.PictureBox
    Friend WithEvents _imgRight_4 As System.Windows.Forms.PictureBox
    Friend WithEvents _imgRight_2 As System.Windows.Forms.PictureBox
    Friend WithEvents _imgLeft_5 As System.Windows.Forms.PictureBox
    Friend WithEvents _imgLeft_4 As System.Windows.Forms.PictureBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.cmdStop = New System.Windows.Forms.Button
        Me.cmdRight = New System.Windows.Forms.Button
        Me.cmdJump = New System.Windows.Forms.Button
        Me.cmdReset = New System.Windows.Forms.Button
        Me.cmdExit = New System.Windows.Forms.Button
        Me.cmdLeft = New System.Windows.Forms.Button
        Me.hsbSpeed = New System.Windows.Forms.HScrollBar
        Me.imgPath = New System.Windows.Forms.PictureBox
        Me.imgWall = New System.Windows.Forms.PictureBox
        Me.lblSpeed = New System.Windows.Forms.Label
        Me.lblFast = New System.Windows.Forms.Label
        Me.lblSlow = New System.Windows.Forms.Label
        Me._imgRight_0 = New System.Windows.Forms.PictureBox
        Me._imgRight_1 = New System.Windows.Forms.PictureBox
        Me._imgRight_3 = New System.Windows.Forms.PictureBox
        Me._imgLeft_0 = New System.Windows.Forms.PictureBox
        Me.imgStandLeft = New System.Windows.Forms.PictureBox
        Me._imgLeft_3 = New System.Windows.Forms.PictureBox
        Me._imgLeft_5 = New System.Windows.Forms.PictureBox
        Me.imgFlatLeft = New System.Windows.Forms.PictureBox
        Me._imgLeft_1 = New System.Windows.Forms.PictureBox
        Me._imgLeft_4 = New System.Windows.Forms.PictureBox
        Me._imgLeft_2 = New System.Windows.Forms.PictureBox
        Me.imgFlatRight = New System.Windows.Forms.PictureBox
        Me._imgRight_5 = New System.Windows.Forms.PictureBox
        Me.imgStandRight = New System.Windows.Forms.PictureBox
        Me._imgRight_4 = New System.Windows.Forms.PictureBox
        Me._imgRight_2 = New System.Windows.Forms.PictureBox
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.imgPerson = New System.Windows.Forms.PictureBox
        Me.imgOuch = New System.Windows.Forms.PictureBox
        Me.SuspendLayout()
        '
        'cmdStop
        '
        Me.cmdStop.BackColor = System.Drawing.Color.CornflowerBlue
        Me.cmdStop.Cursor = System.Windows.Forms.Cursors.Hand
        Me.cmdStop.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdStop.Location = New System.Drawing.Point(96, 400)
        Me.cmdStop.Name = "cmdStop"
        Me.cmdStop.Size = New System.Drawing.Size(64, 32)
        Me.cmdStop.TabIndex = 1
        Me.cmdStop.Text = "Stop"
        '
        'cmdRight
        '
        Me.cmdRight.BackColor = System.Drawing.Color.CornflowerBlue
        Me.cmdRight.Cursor = System.Windows.Forms.Cursors.Hand
        Me.cmdRight.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdRight.Location = New System.Drawing.Point(160, 400)
        Me.cmdRight.Name = "cmdRight"
        Me.cmdRight.Size = New System.Drawing.Size(64, 32)
        Me.cmdRight.TabIndex = 2
        Me.cmdRight.Text = "Right"
        '
        'cmdJump
        '
        Me.cmdJump.BackColor = System.Drawing.Color.CornflowerBlue
        Me.cmdJump.Cursor = System.Windows.Forms.Cursors.Hand
        Me.cmdJump.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdJump.Location = New System.Drawing.Point(96, 368)
        Me.cmdJump.Name = "cmdJump"
        Me.cmdJump.Size = New System.Drawing.Size(64, 32)
        Me.cmdJump.TabIndex = 3
        Me.cmdJump.Text = "Jump"
        '
        'cmdReset
        '
        Me.cmdReset.BackColor = System.Drawing.Color.CornflowerBlue
        Me.cmdReset.Cursor = System.Windows.Forms.Cursors.Hand
        Me.cmdReset.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdReset.Location = New System.Drawing.Point(96, 432)
        Me.cmdReset.Name = "cmdReset"
        Me.cmdReset.Size = New System.Drawing.Size(64, 32)
        Me.cmdReset.TabIndex = 4
        Me.cmdReset.Text = "Reset"
        '
        'cmdExit
        '
        Me.cmdExit.BackColor = System.Drawing.Color.CornflowerBlue
        Me.cmdExit.Cursor = System.Windows.Forms.Cursors.Hand
        Me.cmdExit.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExit.Location = New System.Drawing.Point(720, 448)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(64, 32)
        Me.cmdExit.TabIndex = 5
        Me.cmdExit.Text = "Exit"
        '
        'cmdLeft
        '
        Me.cmdLeft.BackColor = System.Drawing.Color.CornflowerBlue
        Me.cmdLeft.Cursor = System.Windows.Forms.Cursors.Hand
        Me.cmdLeft.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdLeft.Location = New System.Drawing.Point(32, 400)
        Me.cmdLeft.Name = "cmdLeft"
        Me.cmdLeft.Size = New System.Drawing.Size(64, 32)
        Me.cmdLeft.TabIndex = 6
        Me.cmdLeft.Text = "Left"
        '
        'hsbSpeed
        '
        Me.hsbSpeed.Cursor = System.Windows.Forms.Cursors.Hand
        Me.hsbSpeed.Location = New System.Drawing.Point(368, 416)
        Me.hsbSpeed.Maximum = 500
        Me.hsbSpeed.Minimum = 4
        Me.hsbSpeed.Name = "hsbSpeed"
        Me.hsbSpeed.Size = New System.Drawing.Size(192, 32)
        Me.hsbSpeed.TabIndex = 7
        Me.hsbSpeed.Value = 250
        '
        'imgPath
        '
        Me.imgPath.Image = CType(resources.GetObject("imgPath.Image"), System.Drawing.Image)
        Me.imgPath.Location = New System.Drawing.Point(0, 288)
        Me.imgPath.Name = "imgPath"
        Me.imgPath.Size = New System.Drawing.Size(800, 40)
        Me.imgPath.TabIndex = 8
        Me.imgPath.TabStop = False
        '
        'imgWall
        '
        Me.imgWall.Image = CType(resources.GetObject("imgWall.Image"), System.Drawing.Image)
        Me.imgWall.Location = New System.Drawing.Point(332, 200)
        Me.imgWall.Name = "imgWall"
        Me.imgWall.Size = New System.Drawing.Size(121, 92)
        Me.imgWall.TabIndex = 9
        Me.imgWall.TabStop = False
        '
        'lblSpeed
        '
        Me.lblSpeed.BackColor = System.Drawing.Color.CornflowerBlue
        Me.lblSpeed.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblSpeed.Location = New System.Drawing.Point(432, 376)
        Me.lblSpeed.Name = "lblSpeed"
        Me.lblSpeed.Size = New System.Drawing.Size(64, 32)
        Me.lblSpeed.TabIndex = 10
        Me.lblSpeed.Text = "Speed"
        Me.lblSpeed.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'lblFast
        '
        Me.lblFast.BackColor = System.Drawing.Color.CornflowerBlue
        Me.lblFast.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblFast.Location = New System.Drawing.Point(304, 416)
        Me.lblFast.Name = "lblFast"
        Me.lblFast.Size = New System.Drawing.Size(56, 32)
        Me.lblFast.TabIndex = 11
        Me.lblFast.Text = "Fast"
        Me.lblFast.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'lblSlow
        '
        Me.lblSlow.BackColor = System.Drawing.Color.CornflowerBlue
        Me.lblSlow.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblSlow.Location = New System.Drawing.Point(568, 416)
        Me.lblSlow.Name = "lblSlow"
        Me.lblSlow.Size = New System.Drawing.Size(56, 32)
        Me.lblSlow.TabIndex = 12
        Me.lblSlow.Text = "Slow"
        Me.lblSlow.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        '_imgRight_0
        '
        Me._imgRight_0.BackColor = System.Drawing.Color.Transparent
        Me._imgRight_0.Image = CType(resources.GetObject("_imgRight_0.Image"), System.Drawing.Image)
        Me._imgRight_0.Location = New System.Drawing.Point(8, 80)
        Me._imgRight_0.Name = "_imgRight_0"
        Me._imgRight_0.Size = New System.Drawing.Size(46, 63)
        Me._imgRight_0.TabIndex = 13
        Me._imgRight_0.TabStop = False
        Me._imgRight_0.Visible = False
        '
        '_imgRight_1
        '
        Me._imgRight_1.BackColor = System.Drawing.Color.Transparent
        Me._imgRight_1.Image = CType(resources.GetObject("_imgRight_1.Image"), System.Drawing.Image)
        Me._imgRight_1.Location = New System.Drawing.Point(48, 80)
        Me._imgRight_1.Name = "_imgRight_1"
        Me._imgRight_1.Size = New System.Drawing.Size(56, 63)
        Me._imgRight_1.TabIndex = 14
        Me._imgRight_1.TabStop = False
        Me._imgRight_1.Visible = False
        '
        '_imgRight_3
        '
        Me._imgRight_3.BackColor = System.Drawing.Color.Transparent
        Me._imgRight_3.Image = CType(resources.GetObject("_imgRight_3.Image"), System.Drawing.Image)
        Me._imgRight_3.Location = New System.Drawing.Point(160, 80)
        Me._imgRight_3.Name = "_imgRight_3"
        Me._imgRight_3.Size = New System.Drawing.Size(44, 63)
        Me._imgRight_3.TabIndex = 15
        Me._imgRight_3.TabStop = False
        Me._imgRight_3.Visible = False
        '
        '_imgLeft_0
        '
        Me._imgLeft_0.BackColor = System.Drawing.Color.Transparent
        Me._imgLeft_0.Image = CType(resources.GetObject("_imgLeft_0.Image"), System.Drawing.Image)
        Me._imgLeft_0.Location = New System.Drawing.Point(744, 80)
        Me._imgLeft_0.Name = "_imgLeft_0"
        Me._imgLeft_0.Size = New System.Drawing.Size(46, 63)
        Me._imgLeft_0.TabIndex = 16
        Me._imgLeft_0.TabStop = False
        Me._imgLeft_0.Visible = False
        '
        'imgStandLeft
        '
        Me.imgStandLeft.BackColor = System.Drawing.Color.Transparent
        Me.imgStandLeft.Image = CType(resources.GetObject("imgStandLeft.Image"), System.Drawing.Image)
        Me.imgStandLeft.Location = New System.Drawing.Point(734, 8)
        Me.imgStandLeft.Name = "imgStandLeft"
        Me.imgStandLeft.Size = New System.Drawing.Size(56, 64)
        Me.imgStandLeft.TabIndex = 17
        Me.imgStandLeft.TabStop = False
        Me.imgStandLeft.Visible = False
        '
        '_imgLeft_3
        '
        Me._imgLeft_3.BackColor = System.Drawing.Color.Transparent
        Me._imgLeft_3.Image = CType(resources.GetObject("_imgLeft_3.Image"), System.Drawing.Image)
        Me._imgLeft_3.Location = New System.Drawing.Point(584, 80)
        Me._imgLeft_3.Name = "_imgLeft_3"
        Me._imgLeft_3.Size = New System.Drawing.Size(48, 63)
        Me._imgLeft_3.TabIndex = 18
        Me._imgLeft_3.TabStop = False
        Me._imgLeft_3.Visible = False
        '
        '_imgLeft_5
        '
        Me._imgLeft_5.BackColor = System.Drawing.Color.Transparent
        Me._imgLeft_5.Image = CType(resources.GetObject("_imgLeft_5.Image"), System.Drawing.Image)
        Me._imgLeft_5.Location = New System.Drawing.Point(472, 80)
        Me._imgLeft_5.Name = "_imgLeft_5"
        Me._imgLeft_5.Size = New System.Drawing.Size(56, 63)
        Me._imgLeft_5.TabIndex = 19
        Me._imgLeft_5.TabStop = False
        Me._imgLeft_5.Visible = False
        '
        'imgFlatLeft
        '
        Me.imgFlatLeft.BackColor = System.Drawing.Color.Transparent
        Me.imgFlatLeft.Image = CType(resources.GetObject("imgFlatLeft.Image"), System.Drawing.Image)
        Me.imgFlatLeft.Location = New System.Drawing.Point(448, 224)
        Me.imgFlatLeft.Name = "imgFlatLeft"
        Me.imgFlatLeft.Size = New System.Drawing.Size(81, 65)
        Me.imgFlatLeft.TabIndex = 20
        Me.imgFlatLeft.TabStop = False
        Me.imgFlatLeft.Visible = False
        '
        '_imgLeft_1
        '
        Me._imgLeft_1.BackColor = System.Drawing.Color.Transparent
        Me._imgLeft_1.Image = CType(resources.GetObject("_imgLeft_1.Image"), System.Drawing.Image)
        Me._imgLeft_1.Location = New System.Drawing.Point(684, 80)
        Me._imgLeft_1.Name = "_imgLeft_1"
        Me._imgLeft_1.Size = New System.Drawing.Size(59, 63)
        Me._imgLeft_1.TabIndex = 21
        Me._imgLeft_1.TabStop = False
        Me._imgLeft_1.Visible = False
        '
        '_imgLeft_4
        '
        Me._imgLeft_4.BackColor = System.Drawing.Color.Transparent
        Me._imgLeft_4.Image = CType(resources.GetObject("_imgLeft_4.Image"), System.Drawing.Image)
        Me._imgLeft_4.Location = New System.Drawing.Point(528, 80)
        Me._imgLeft_4.Name = "_imgLeft_4"
        Me._imgLeft_4.Size = New System.Drawing.Size(63, 63)
        Me._imgLeft_4.TabIndex = 22
        Me._imgLeft_4.TabStop = False
        Me._imgLeft_4.Visible = False
        '
        '_imgLeft_2
        '
        Me._imgLeft_2.BackColor = System.Drawing.Color.Transparent
        Me._imgLeft_2.Image = CType(resources.GetObject("_imgLeft_2.Image"), System.Drawing.Image)
        Me._imgLeft_2.Location = New System.Drawing.Point(632, 80)
        Me._imgLeft_2.Name = "_imgLeft_2"
        Me._imgLeft_2.Size = New System.Drawing.Size(55, 63)
        Me._imgLeft_2.TabIndex = 23
        Me._imgLeft_2.TabStop = False
        Me._imgLeft_2.Visible = False
        '
        'imgFlatRight
        '
        Me.imgFlatRight.BackColor = System.Drawing.Color.Transparent
        Me.imgFlatRight.Image = CType(resources.GetObject("imgFlatRight.Image"), System.Drawing.Image)
        Me.imgFlatRight.Location = New System.Drawing.Point(256, 224)
        Me.imgFlatRight.Name = "imgFlatRight"
        Me.imgFlatRight.Size = New System.Drawing.Size(81, 65)
        Me.imgFlatRight.TabIndex = 24
        Me.imgFlatRight.TabStop = False
        Me.imgFlatRight.Visible = False
        '
        '_imgRight_5
        '
        Me._imgRight_5.BackColor = System.Drawing.Color.Transparent
        Me._imgRight_5.Image = CType(resources.GetObject("_imgRight_5.Image"), System.Drawing.Image)
        Me._imgRight_5.Location = New System.Drawing.Point(264, 80)
        Me._imgRight_5.Name = "_imgRight_5"
        Me._imgRight_5.Size = New System.Drawing.Size(56, 63)
        Me._imgRight_5.TabIndex = 25
        Me._imgRight_5.TabStop = False
        Me._imgRight_5.Visible = False
        '
        'imgStandRight
        '
        Me.imgStandRight.BackColor = System.Drawing.Color.Transparent
        Me.imgStandRight.Image = CType(resources.GetObject("imgStandRight.Image"), System.Drawing.Image)
        Me.imgStandRight.Location = New System.Drawing.Point(8, 8)
        Me.imgStandRight.Name = "imgStandRight"
        Me.imgStandRight.Size = New System.Drawing.Size(56, 64)
        Me.imgStandRight.TabIndex = 26
        Me.imgStandRight.TabStop = False
        Me.imgStandRight.Visible = False
        '
        '_imgRight_4
        '
        Me._imgRight_4.BackColor = System.Drawing.Color.Transparent
        Me._imgRight_4.Image = CType(resources.GetObject("_imgRight_4.Image"), System.Drawing.Image)
        Me._imgRight_4.Location = New System.Drawing.Point(200, 80)
        Me._imgRight_4.Name = "_imgRight_4"
        Me._imgRight_4.Size = New System.Drawing.Size(63, 63)
        Me._imgRight_4.TabIndex = 27
        Me._imgRight_4.TabStop = False
        Me._imgRight_4.Visible = False
        '
        '_imgRight_2
        '
        Me._imgRight_2.BackColor = System.Drawing.Color.Transparent
        Me._imgRight_2.Image = CType(resources.GetObject("_imgRight_2.Image"), System.Drawing.Image)
        Me._imgRight_2.Location = New System.Drawing.Point(104, 80)
        Me._imgRight_2.Name = "_imgRight_2"
        Me._imgRight_2.Size = New System.Drawing.Size(55, 63)
        Me._imgRight_2.TabIndex = 28
        Me._imgRight_2.TabStop = False
        Me._imgRight_2.Visible = False
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        Me.Timer1.Interval = 10
        '
        'imgPerson
        '
        Me.imgPerson.BackColor = System.Drawing.Color.Transparent
        Me.imgPerson.Location = New System.Drawing.Point(0, 232)
        Me.imgPerson.Name = "imgPerson"
        Me.imgPerson.Size = New System.Drawing.Size(81, 72)
        Me.imgPerson.TabIndex = 29
        Me.imgPerson.TabStop = False
        '
        'imgOuch
        '
        Me.imgOuch.BackColor = System.Drawing.Color.Transparent
        Me.imgOuch.Image = CType(resources.GetObject("imgOuch.Image"), System.Drawing.Image)
        Me.imgOuch.Location = New System.Drawing.Point(336, 56)
        Me.imgOuch.Name = "imgOuch"
        Me.imgOuch.Size = New System.Drawing.Size(100, 100)
        Me.imgOuch.TabIndex = 30
        Me.imgOuch.TabStop = False
        Me.imgOuch.Visible = False
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = New System.Drawing.Size(800, 494)
        Me.ControlBox = False
        Me.Controls.Add(Me.imgOuch)
        Me.Controls.Add(Me.imgPerson)
        Me.Controls.Add(Me._imgRight_2)
        Me.Controls.Add(Me._imgRight_4)
        Me.Controls.Add(Me.imgStandRight)
        Me.Controls.Add(Me._imgRight_5)
        Me.Controls.Add(Me.imgFlatRight)
        Me.Controls.Add(Me._imgLeft_2)
        Me.Controls.Add(Me._imgLeft_4)
        Me.Controls.Add(Me._imgLeft_1)
        Me.Controls.Add(Me.imgFlatLeft)
        Me.Controls.Add(Me._imgLeft_5)
        Me.Controls.Add(Me._imgLeft_3)
        Me.Controls.Add(Me.imgStandLeft)
        Me.Controls.Add(Me._imgLeft_0)
        Me.Controls.Add(Me._imgRight_3)
        Me.Controls.Add(Me._imgRight_1)
        Me.Controls.Add(Me._imgRight_0)
        Me.Controls.Add(Me.lblSlow)
        Me.Controls.Add(Me.lblFast)
        Me.Controls.Add(Me.lblSpeed)
        Me.Controls.Add(Me.imgWall)
        Me.Controls.Add(Me.imgPath)
        Me.Controls.Add(Me.hsbSpeed)
        Me.Controls.Add(Me.cmdLeft)
        Me.Controls.Add(Me.cmdExit)
        Me.Controls.Add(Me.cmdReset)
        Me.Controls.Add(Me.cmdJump)
        Me.Controls.Add(Me.cmdRight)
        Me.Controls.Add(Me.cmdStop)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Name = "Form1"
        Me.Text = "Sonic Jump - Designed & Written by John Crick"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Public direction As String
    Public steps As Integer
    Public Jumping As Boolean
    Public JumpCounts As Integer
    Public JumpAmount As Integer
    Dim quit As Object

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        quit = MsgBox("Do you really want to exit?", vbQuestion + vbYesNo, "Sonic Jump") 'Message box and message
        If quit = vbYes Then 'If quit equals yes Then
            Me.Close() ' Close the form window
        Else
            If quit = vbNo Then 'If quit equals no Then
                cmdStop.Focus() 'Set focus to Price Excluding VAT textbox
            End If
        End If
    End Sub

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If msg.WParam.ToInt32() = CInt(Keys.Escape) Then ' If escape key pressed Then
            quit = MsgBox("Do you really want to exit?", vbQuestion + vbYesNo, "Sonic Jump") 'Message box and message
            If quit = vbYes Then 'If quit equals yes Then
                Me.Close() ' Close the form window
            Else
                If quit = vbNo Then 'If quit equals no Then
                    cmdStop.Focus() 'Set focus to Price Excluding VAT textbox
                End If
            End If
        End If
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        steps = 0
        direction = "none"
        Timer1.Enabled = False
        imgPerson.Image = imgStandRight.Image
    End Sub

    Private Sub cmdLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLeft.Click
        direction = "left"
        Timer1.Enabled = True
    End Sub

    Private Sub cmdRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRight.Click
        direction = "right"
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If steps = 0 Then
            steps = 1
        ElseIf steps = 1 Then
            steps = 2
        ElseIf steps = 2 Then
            steps = 3
        ElseIf steps = 3 Then
            steps = 4
        ElseIf steps = 4 Then
            steps = 5
        ElseIf steps = 5 Then
            steps = 0
        End If

        If direction = "left" Then
            imgPerson.Left = imgPerson.Left - 1
            imgPerson.Image = imgLeft(steps).Image
        ElseIf direction = "right" Then
            imgPerson.Left = imgPerson.Left + 1
            imgPerson.Image = imgRight(steps).Image
        End If
    End Sub
End Class
0
Jeff CertainCommented:
Your code needs to be:
Public imgRight as vartype
Public imgLeft as vartype

It looks like these are meant to be arrays of images, but I don't see where they're ever initialized.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

john-formbyAuthor Commented:
Changed them to vartype but it is not recognised. Tried varianttype but it comes up with build errors.

0
planoczCommented:
Just to get around the error for now....

    Try
            If direction = "left" Then
                imgPerson.Left = imgPerson.Left - 1
                imgPerson.Image = imgLeft(steps)
            ElseIf direction = "right" Then
                imgPerson.Left = imgPerson.Left + 1
                imgPerson.Image = imgRight(steps)
        End If
        Catch ex As Exception
            'Skip error
        End Try
0
Jeff CertainCommented:
Sorry. "vartype" is pseudocode. You need to declare them as an object type.
Private imgRight(5) as Bitmap
Private imgLeft(5) as Bitmap

Then, in your page load, you need to have code that initializes the images.
imgRight(0) = new Bitmap(<insert filename here>)
imgRight(1) = new Bitmap(<insert filename here>)
imgRight(2) = new Bitmap(<insert filename here>)
etc

in TimerTick, you need to change your code to
            If direction = "left" Then
                  imgPerson.Left = imgPerson.Left - 1
                  imgPerson.Image = imgLeft(steps)
            ElseIf direction = "right" Then
                  imgPerson.Left = imgPerson.Left + 1
                  imgPerson.Image = imgRight(steps)
            End If

Also, you can simplify your code by using
steps+=1
steps = steps mod 5
in Timer_Tick

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
john-formbyAuthor Commented:
The images I am using are not bitmaps, but transparent Gifs.  Does that make a difference?  I have uploaded a .zip file so you can download and see what I have done.  I am not very good at explaining whats wrong cause I don't fully understand myself.  Also what you have just written for me has gone way over my head :-(  This is only the second program I have ever written, sorry.

You can download the file at:  http://www.3doubleu.co.uk/game.zip

It is quite a large file, 1,211KB
0
planoczCommented:
Chaosian  has the right idea, but for a smoother image flow try the try and catch code with
    Private imgRight() As Bitmap
    Private imgLeft() As Bitmap
0
planoczCommented:
Thats it for me today check back with you tomorrow.
0
Jeff CertainCommented:
Do you have an e-mail I can send the working project to?
0
john-formbyAuthor Commented:
Yes, its: admin@3doubleu.co.uk  Thanks
0
Bob LearnedCommented:
There is a neat concept in VB.NET where you can easily create run-time controls, and add event handlers, that would be more dynamic than the static method that you have chosen.

Bob
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.