|
-
Dec 29th, 2005, 09:36 AM
#1
Thread Starter
New Member
[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
-
Dec 29th, 2005, 09:43 AM
#2
New Member
Re: Novice question
your mistake is 1=1000 it must be i=1000
-
Dec 29th, 2005, 09:50 AM
#3
Re: Novice question
Also, put Doevents in your loop to get things to update and stop the computer from freezing.
zaza
-
Dec 29th, 2005, 09:52 AM
#4
Re: Novice question
Welcome to the forums. 
Try this
VB Code:
Private Sub Command1_Click()
Dim i As Long
i = 1
Do
Label1.Caption = "Tested: " & CStr(i)
DoEvents
i = i + 1
Loop Until i = 10000
End Sub
-
Dec 29th, 2005, 10:16 AM
#5
Thread Starter
New Member
Re: Novice question
 Originally Posted by jethrobg
your mistake is 1=1000 it must be i=1000
Sorry, I type a mistake.
-
Dec 29th, 2005, 10:17 AM
#6
Thread Starter
New Member
Re: Novice question
 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.
-
Dec 29th, 2005, 10:18 AM
#7
Thread Starter
New Member
Re: Novice question
 Originally Posted by Hack
Welcome to the forums.
Try this
VB Code:
Private Sub Command1_Click()
Dim i As Long
i = 1
Do
Label1.Caption = "Tested: " & CStr(i)
DoEvents
i = i + 1
Loop Until i = 10000
End Sub
Hello from Spain
-
Dec 29th, 2005, 10:21 AM
#8
Re: Novice question
 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.
-
Dec 29th, 2005, 10:23 AM
#9
Thread Starter
New Member
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.
-
Dec 29th, 2005, 10:24 AM
#10
Thread Starter
New Member
Re: Novice question
 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
-
Dec 29th, 2005, 10:24 AM
#11
Re: Novice question
 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.
-
Dec 29th, 2005, 10:30 AM
#12
Thread Starter
New Member
Re: Novice question
 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
-
Dec 29th, 2005, 10:58 AM
#13
Re: Novice question
 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
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|