CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Select ... Case

  1. #1
    Join Date
    Jan 2000
    Posts
    2

    Select ... Case

    I am new at VB, this list also.
    Thought I'd start out with an easy question,,, here goes.

    Below is my code, I want to have a timer, control array of 3 images and a blank image box

    When the timer reaches a certain time one images appears, after a few clicks another,, and so on.

    Heres the code I am trying, Its sticks on the first image.

    Any ideas were I'm messing up?

    Private Sub Form_Load()

    Select Case Image

    Case Is > 0
    If time > 0 Then
    Image1.Picture = st(0)
    End If

    Case Is >= 10
    If time >= 10 Then
    Image1.Picture = st(1)
    End If

    Case Is >= 20
    If time >= 20 Then
    Image1.Picture = st(2)
    End If

    End Select
    End Sub


    Private Sub Timer1_Timer()

    time = time + 1
    If time = 30 Then
    time = 0
    End If
    End Sub

    Thanks for your time
    curtis03


  2. #2
    Join Date
    Nov 1999
    Location
    US NJ
    Posts
    113

    Re: Select ... Case

    Try This...

    Private Sub Form_Load()

    If Time > 0 Then
    Image1.Picture = st(0)
    ElseIf Time >= 10 Then
    Image1.Picture = st(1)
    ElseIf Time >= 20 Then
    Image1.Picture = st(2)
    End If

    End Sub


    Private Sub Timer1_Timer()

    Time = Time + 1
    If Time = 30 Then
    Time = 0
    End If
    End Sub



  3. #3
    Join Date
    Jan 2000
    Posts
    2

    Re: Select ... Case

    I tried this from a reply post,,,,

    Private Sub Form_Load()

    If Time > 0 Then
    Image1.Picture = st(0)
    ElseIf Time >= 10 Then
    Image1.Picture = st(1)
    ElseIf Time >= 20 Then
    Image1.Picture = st(2)
    End If

    End Sub


    Private Sub Timer1_Timer()

    Time = Time + 1
    If Time = 30 Then
    Time = 0
    End If
    End Sub

    Still didn't work,
    I may be wrong, but isn't the first line always going to be true
    "Time > 0"

    I'll try "Time <10"
    Then "Time >20"
    Then "Time >30"

    and reset the counter at 40

    Thanks
    curtis03


  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Select ... Case

    There's a few things wrong with your code :

    1. You've placed the code to switch pictures in Form_Load - that only gets called once (when the form loads!)

    2. You've done a 'Select Case' on 'Image' - that doesn't make any sense in the checking 'Case' part to VB

    3. Your 'Is > 0' will always be called for any value in the select statement


    Try the following code in your form instead :


    option Explicit
    '
    private Sub Form_Load()
    '
    ' Setup first image
    '
    set Image1.Picture = st(0).Picture
    End Sub
    '
    private Sub Timer1_Timer()
    '
    ' Use a static variable rather than a module wide one
    ' to ensure that this is the only routine that modifies
    ' it
    '

    static lTime as Long
    '
    lTime = lTime + 1
    If lTime = 30 then
    lTime = 0
    End If
    '
    If lTime >= 0 And lTime < 10 then
    set Image1.Picture = st(0).Picture
    ElseIf lTime >= 10 And lTime < 20 then
    set Image1.Picture = st(1).Picture
    ElseIf lTime >= 20 then
    set Image1.Picture = st(2).Picture
    End If
    '
    End Sub







    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured