For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > February 2005 > Message in listbox not updated immediatly









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Message in listbox not updated immediatly
Andr? Legault

2005-02-27, 3:55 am

Hi Group,

I have a small program that copies files from the hard disk to a diskette on
the A:\ drive.

In the program I have 2 forms, one with a command button to start the program
and another which consists only of a listbox for messages.

In my program, I have these lines:

frmMessagesList.lstMessages.AddItem "Files copy started."
CopyFiles

Even if AddItem is before the subprogram, the message doesn't get added to the
listbox until the copy is done. (CopyFiles is a sub program doing the copy.)

Can someone explain why this happens, and how to avoid it?

TIA
Andre
BT3

2005-02-27, 8:55 am

This kind of thing comes up a LOT. I read that you are actually queuing the
..AddItem stuff. It won't actually show up until the stack pointer leaves
the sub-routine. When the code exits the sub, it updates.

If you are absolutely sure that that routine won't get called again until it
is finished, then put a DoEvents after the .AddItem line. That allows the
components to update, at least until somebody has a better answer.

BT3

"Andr? Legault" <legault.andre@videotron.ca> wrote in message
news:7d24010e.0502262312.3ac52e4b@posting.google.com...
> Hi Group,
>
> I have a small program that copies files from the hard disk to a diskette

on
> the A:\ drive.
>
> In the program I have 2 forms, one with a command button to start the

program
> and another which consists only of a listbox for messages.
>
> In my program, I have these lines:
>
> frmMessagesList.lstMessages.AddItem "Files copy started."
> CopyFiles
>
> Even if AddItem is before the subprogram, the message doesn't get added to

the
> listbox until the copy is done. (CopyFiles is a sub program doing the

copy.)
>
> Can someone explain why this happens, and how to avoid it?
>
> TIA
> Andre



J French

2005-02-27, 8:55 am

On 26 Feb 2005 23:12:53 -0800, legault.andre@videotron.ca (Andr?
Legault) wrote:

>Hi Group,
>
>I have a small program that copies files from the hard disk to a diskette on
>the A:\ drive.
>
>In the program I have 2 forms, one with a command button to start the program
>and another which consists only of a listbox for messages.
>
>In my program, I have these lines:
>
> frmMessagesList.lstMessages.AddItem "Files copy started."
> CopyFiles
>
>Even if AddItem is before the subprogram, the message doesn't get added to the
>listbox until the copy is done. (CopyFiles is a sub program doing the copy.)
>
>Can someone explain why this happens, and how to avoid it?


Try List1.Refresh it will force an immediate update rather than a
delayed one.

BT3

2005-02-27, 3:55 pm

I didn't post that because it doesn't work on mine. I just figured that was
the way it was, sorry. In fact I don't use the refresh at all because I
can't ever get it to actually refresh like the book says it will.

BT3

"J French" <erewhon@nowhere.uk> wrote in message
news:422199c2.248052389@news.btclick.com...
> On 26 Feb 2005 23:12:53 -0800, legault.andre@videotron.ca (Andr?
> Legault) wrote:
>
on[color=darkred]
program[color=darkred]
to the[color=darkred]
copy.)[color=darkred]
>
> Try List1.Refresh it will force an immediate update rather than a
> delayed one.
>



Stefan Berglund

2005-02-27, 8:55 pm

On Sun, 27 Feb 2005 09:52:11 -0600, "BT3" <honeypot@epmctc.com>
wrote:
in <i0mUd.99992$GT.78610@okepread01>

>I didn't post that because it doesn't work on mine. I just figured that was
>the way it was, sorry. In fact I don't use the refresh at all because I
>can't ever get it to actually refresh like the book says it will.
>
>BT3


Did you try the refresh followed by a DoEvents?


---
Stefan Berglund
J French

2005-02-28, 8:55 am

On Sun, 27 Feb 2005 09:52:11 -0600, "BT3" <honeypot@epmctc.com> wrote:

>I didn't post that because it doesn't work on mine. I just figured that was
>the way it was, sorry. In fact I don't use the refresh at all because I
>can't ever get it to actually refresh like the book says it will.


<snip>

It is worth running up a little test app to check that again.

What you said about the stack pointer leaving the subroutine is not
really true
- it has nothing to do with the stack pointer
- although it kind of looks as if it does

What is happening is that Windows is building up a load of Paint
Windows Messages and those are not processed until an explicit or
/implicit/ (note implicit) DoEvents is performed.

The .Refresh method of a control should force VB to get Windows to
process paint messages immediately.

Sometimes one runs into a problem that has two causes and derives a
general rule from the 'wrong' cause.
That may have happened to you (it certainly has to me in the past)

However, it might be that your version of VB or Windows behaves
differently - still it is worth double checking.


BT3

2005-02-28, 3:55 pm

yes, .Refresh followed by a DoEvetns works everytime, so as a test I dropped
the .Refresh and it still worked, so I just abandoned .Refresh.

BT3

"Stefan Berglund" <keepit@in.thegroups> wrote in message
news:6eg421hdmo2ku1ae1df7bgc20rnhcpa6vq@
4ax.com...
> On Sun, 27 Feb 2005 09:52:11 -0600, "BT3" <honeypot@epmctc.com>
> wrote:
> in <i0mUd.99992$GT.78610@okepread01>
>
was[color=darkred]
>
> Did you try the refresh followed by a DoEvents?
>
>
> ---
> Stefan Berglund



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com