Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DESPERATE FOR HELP on a LOADPICTURE issue!!! 1

Status
Not open for further replies.

tmktech

MIS
Oct 3, 2002
78
US
Hey folks!

I've got an problem that I've been pounding on for hours and I could really use some help!!!!

I've got an IMAGE Control that sits on a Worksheet - not in a form (it's necessary).

I've found out - after a big code / time investment in this approach - that the picture will not update while the macro is running (but will after it's complete). IT'S CRITICAL THAT I FIND A WAY TO UPDATE THE IMAGE DURING THE MACROS' PROCESSING.


FYI: I have a similar LoadPicture within a FRAME on a FORM and it updates during the macro code fine. I've also verified that it's NOT a App. calculate, screenupdating, or interactive issue.

H E L P !!!

THANKS IN ADVANCE!!!

TMKTECH
 
I played with this a bit until I got the same results as you did. See code below:

Code:
Sub Macro1()
   Dim t    As Long
   Dim x    As Integer
   
   Sheet1.Image1.Picture = LoadPicture("c:\test.jpg")
   DoEvents
   
   'use up some clock cycles 
   '(adjust iterations as needed)
   For t = 1 To 1800000
      x = x + 1       
      If x > 50 Then
         x = 0
      End If
   Next
   MsgBox ("done")
   Sheet1.Image1.Picture = LoadPicture("")
End Sub

On my machine, I got the message, but no picture. So, I played a bit more more and found that...

Code:
Sub Macro1()
   Dim t    As Long
   Dim x    As Integer
   
   Sheet1.Image1.Picture = LoadPicture("c:\test.jpg")
   DoEvents
Code:
   DoEvents
Code:
   'use up some clock cycles
   '(adjust iterations as needed)
   For t = 1 To 1800000
      x = x + 1       
      If x > 50 Then
         x = 0
      End If
   Next
   MsgBox ("done")
   Sheet1.Image1.Picture = LoadPicture("")
End Sub

...worked on my machine (Excel 2000/Win 2000). My guess is that 2 consecutive DoEvents wouldn't work across a network, or on a slower machine. But putting the DoEvents in a For/Next loop, with a small number of iterations may get the results you want. I'm not suggesting this as a solution, but merely a work-around until a better solution comes along.
 
Interesting, sfvb.


As you experienced, 1 DoEvent doesn't help but 2 does. It's getting the job done, but I can't help but think this is a messy (and INefficent, speedwise) solution.

By the way, I too am on a Office / Windows 2K platform.

I welcome additional feedback as well as a better understanding of W H Y the DoEvents works.

Thanks!
TMKTECH
 
... messy (and INefficent, speedwise) solution

I most definitely agree. As I said, this wasn't meant to be a solution, merely a temporary work-around, until a better answer came along.

I'll try it tommorow at the office, across the network. But, I can't image it will work. If it does, I think I'd need to understand why it works, before I was confident enough to use it in any production code.
 
Thanks, sfvb.

Please keep me posted on the network test. By the way, user a timer or wait function in place of the FIRST DoEvent works as well.

And, it IS getting it done at this point, so here's a star.

TMKTECH
 
Thanks for the star. I'll post my results after I get to the office, tomorrow. I've got the same OS and Office version at home and at work, and all the service packs are up to date on both machines. So, it should come down whether it works across a network or not.

My guess is not, but we'll see. Anybody else have any ideas?
 
tmtech,
It worked across the network. I don't understand why, but it worked.
 
Thanks for the feedback!

My last concern is CPU resources & I/O access times. Do you think that the TWO (2) DoEvents is a time-related thing (given my feedback on a timer / wait working too)? If so, I'm concerned that on a slow LAN, that it might take 3 or 4 DoEvents (or a longer timer). Thing is, I only want to wait, pause, etc. ONLY AS LONG AS IT TAKES and no longer since this occurs in an iterative process.

sfvb? Anyone else?

THANKS AGAIN, sfvb for following thru today!

TMKTECH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top