Results 1 to 13 of 13

Thread: [RESOLVED] Novice question

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    7

    Resolved [RESOLVED] Novice question

    I am changing the caption property of a label inside a Do Loop but it does not work. The program runs well but get almost 100% from CPU and in task manager appears "Not reponding". Of course when the Do Loop finish the label get updated. The code is more or less like this:

    i=1
    do
    label.caption="Tested:" & Cstr(i)
    i=i+1
    loop until 1=10000

  2. #2
    New Member
    Join Date
    Dec 2005
    Posts
    8

    Re: Novice question

    your mistake is 1=1000 it must be i=1000

  3. #3
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Novice question

    Also, put Doevents in your loop to get things to update and stop the computer from freezing.

    zaza

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Novice question

    Welcome to the forums.

    Try this
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim i As Long
    3. i = 1
    4. Do
    5. Label1.Caption = "Tested: " & CStr(i)
    6. DoEvents
    7. i = i + 1
    8. Loop Until i = 10000
    9. End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    7

    Re: Novice question

    Quote Originally Posted by jethrobg
    your mistake is 1=1000 it must be i=1000
    Sorry, I type a mistake.

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    7

    Re: Novice question

    Quote Originally Posted by zaza
    Also, put Doevents in your loop to get things to update and stop the computer from freezing.

    zaza

    Sort and simple ... It is working right now, thanks.

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    7

    Re: Novice question

    Quote Originally Posted by Hack
    Welcome to the forums.

    Try this
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim i As Long
    3. i = 1
    4. Do
    5. Label1.Caption = "Tested: " & CStr(i)
    6. DoEvents
    7. i = i + 1
    8. Loop Until i = 10000
    9. End Sub
    Hello from Spain

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Novice question

    Quote Originally Posted by unora
    Hello from Spain
    Welcome.

    If this is resolved, please pull down the Thread Tools menu and click the Mark Thread Resolved button. That will let everyone know that you have your answer.

    Thank you.

  9. #9

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    7

    Re: Novice question

    I tried also "label.refresh" and works only if I do nothing, I mean, the label`s caption updates but if I move the window, or set the focus to other windows the label`s caption do not update any more. Doevents works fine and better. Again thanks.

  10. #10

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    7

    Re: Novice question

    Quote Originally Posted by Hack
    Welcome.

    If this is resolved, please pull down the Thread Tools menu and click the Mark Thread Resolved button. That will let everyone know that you have your answer.

    Thank you.

    Done

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Novice question

    Quote Originally Posted by unora
    but if I move the window, or set the focus to other windows the label`s caption do not update any more.
    That is because in order for code to execute, the window has to have focus.

  12. #12

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    7

    Re: Novice question

    Quote Originally Posted by Hack
    That is because in order for code to execute, the window has to have focus.

    Mmmm I do not agree that. For example my program runs on window A, now the label´s caption is being updated. Then I set focus to IE (for example) and then I return to my program´s window. The label´s caption shows nothing. But If I pause the execution and then run , the label´s caption begin to be updated again. Anyway, the statement "Doevents" works

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Novice question

    Quote Originally Posted by unora
    For example my program runs on window A, now the label´s caption is being updated. Then I set focus to IE (for example) and then I return to my program´s window. The label´s caption shows nothing.
    Right, because it doesn't have focus
    Quote Originally Posted by unora
    But If I pause the execution and then run , the label´s caption begin to be updated again.
    But, now it does have focus again.

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