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

Thread: Repetition structure

  1. #1
    Join Date
    Mar 2013
    Posts
    18

    Repetition structure

    Hello, Would you please help me???

    I'm building a app., and I want to repeat 6 pictures inside a Image control (Image1), through a ImageList when I click on a command button "NEXT"

    all the images are stored in the ImageList.


    I've done this code but it's not working.


    Code:
    For i = 1 To 6
    
                 Set Image1.Picture = ImageList1.ListImages((i) + 1).Picture
            
                 i = i + 1
    
    Next i

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,825

    Re: Repetition structure

    Of course not, you have 2 issues there
    1 you are using a loop so you would be setting the image several times but only the last one will appear
    2 you are incrementing the counter var inside the for loop which you should never do

    that code will load image 2 then image 4 then image 6 but you will only see image 6

    The correct method if you want to load them one at a time upon clicking a button would be to
    1: get rid of the loop
    2: Put the code in a command button click event
    3: use a static counter var which increments on each click

    Code:
    Private Sub Command1_Click()
        Static i as integer
        Set Image1.Picture = ImageList1.ListImages((i) + 1).Picture        
        i = i + 1
    end sub
    Of course that would continue to try to load an image even after you get past 6 so you may need to add code to set i=0 when i reaches 6 or whatever numbers you need

    I have deleted your duplicate thread in the VB.Net forum, In future do not start more than one thread for the same question.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Mar 2013
    Posts
    18

    Re: Repetition structure

    Thank you very much for helping me.

    I don't really want to load them one at a time. !!!

    I want to load in the Imgae control one after one upon clicking a button, and if it's the last image, it repeats the first one... (Loop)

  4. #4
    Join Date
    Mar 2013
    Posts
    18

    Re: Repetition structure

    Would you please make me the code.

  5. #5
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,825

    Re: Repetition structure

    No I will not write the code for you again.

    If you want them to load with a delay between like a slide show then you need to use a timer, It is very simple

    1: Add a timer control to your form.
    2: Set the interval to 1000 in the timer properties This will give you a 1 second delay between pictures
    3: Set enabled=false in the timer properties
    4: Double click on the timer to bring up the code window
    5: Place code such as the 3 lines I showed you before into the timer event
    6: In your command button click code add a line to enable the timer i.e. Timer1.Enabled=true
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Mar 2013
    Posts
    18

    Re: Repetition structure

    Thanks with the automatic loading (Timer), but I'm not interested to this, I want manually rather.

    I set i=0 with [ IF - END IF ] like you said but it's not bringing up the first Image after the Loop. just the second one that appears the first. (MISSING OF THE FIRST AFTER LOOP)

    ----

    I tried this code and it works fine now.

    I have 7 images into the ImageList, I set "i=6" and not "i=7", because when I set "i=7" it's not working very fine !!!

    Code:
    If i = 6 then
    
    i = -1
    
    End if
    PERFECT !!!


    Thank you very much, user "DataMiser"

  7. #7
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,825

    Re: Repetition structure

    Glad you got it working but honestly I have no idea what you were trying to ask
    When I showed you code to load one at a time you said that was not what you wanted
    When I showed you how to load them all with a delay so as to make them visible for a short while you say you want to do it manually

    The bottom line is that an image box can only show 1 image at a time so either you show them one at a time as I showed with the button click or you do it with a timer so they all load with a short delay between them

    You can't just click a button and load them all at once as that results in only the last one actually being shown and all the other code is just wasting CPU cycles
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    Mar 2013
    Posts
    18

    Re: Repetition structure

    Sorry about that.

    The problem is when you replied to me, I was drowsing in front of the keyboard as it was so late to us, so I hadn't really read very well your response, I just skimmed it and replied... even the code you wrote I thought it was mine that you repeated to me.

    next day that I found I should have not do it!!!

    Very Sorry again !!!

    --

    in brief, I wanted to make something like an introducing window that appear when you launch the software and gives the users a small introduction of the software and HOW TO DO WHAT. Like what you see in Dev-C++ when you launch it the first time.

    and I make it with your precious HELP.

    I made it with " IF - END IF", and it was working fine but the problem was when you add an image you need to add another portion of a long code of IF - END IF to handle it. So with twenty images you also need to add twenty portion of very long code to handle. Boring !!!

    ----

    I will publish the link here to download this app. after completion. Just to handle the languages module (as I need to build it with several languages) and deployment that remain.

    Meanwhile you can enjoy the first version of that : --- No links to EXE files please ---

    http://francisnd.fr.gd/telechargement.htm

    and please give me a rating on 10.

    ---

    Are you still a Vb6 programmer or you were ??? ; and you mastered it, so that you found good to help people
    Last edited by GremlinSA; December 2nd, 2013 at 12:49 AM. Reason: removed link to EXE file...

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center