animated gif

Heike

Well-known member
Joined
Jun 5, 2002
Messages
56
I want to show an animated gif if some execution is done instead of setting the cursor to "WaitCursor". At the time I would set my cursor I openl a form which contains an animated gif. But the gif is only animated after my execution finished. Whats wrong?
 
You would need to play the gif just before the execution begins...

Using the mouse events would be most helpful...

in VB, the mouse events are executed in sequence:
Mouse_Down()
Mouse_Up()
Click()
DoubleClick()

This will work best if you put it in the _MouseUp event...

Take a button for instance...
NOTE: In this example, I would put my code that I want to execute in the button1_click() event...
Code:
Private Sub button1_MouseUp(blah)
  Play Gif Code Here...
End Sub

Private Sub button1_Click(blah)
  Put Work Code Here...
End Sub

Now when the user presses down AND THEN releases the mouse on button1, the gif will start playing while the code executes...
 
Unfortunately it makes no difference....

This is how I do it, maybe you can see an error.

Code:
If Not objWordInstance Is Nothing Then
    frmGif = New frmIBS_Beschaeftigt() 
    frmGif.AnimateImage()
   [...]
   .FillDocVariables(...)
    frmGif.Close()
    frmGif = Nothing
End If

where frmGif is my form with the animated gif and .FillDocVariables is the sub whose execution should be shown by that gif.
 
ok, your code snippit is the code used to open the gif...

What is the general idea of what your application does when it goes into a long process where you would need the waiting gif?

What event is this code in?

It looks like you are going to fill a table with data...

The gif doesnt play until after the data is filed? or is it something else?
 
Last edited by a moderator:
The code snippit is only one example. I want to use my animated gif at several places.

I am developing an AddIn for Word(2000).

The snippit I copied here is used to parse to one document to search for DocVariables in it. To each of this DocVariable I have an entry in my CustomDocumentProperties containing a SQL-statement. I must execute that SQL-statement and the value I get becomes the value of the DocVariable.

Yes, when all my DocVariables are filled (which means the execution of that function is finished), my gif starts to play. But I want it to be parallel. I think the only way may be to do that by using several threads???
 
You are probably right. If the function is executing lots of things in a loop, you might be able to get away with sticking an Application.DoEvents() in the loop. Otherwise, youll probably have to execute that function in a new thread.
 
Even if using threads it seems to be more difficult than I thought.

It seems to work... My function fills my DocVariables and during that I see my animated gif and it is(!) animated. But: how can I tell that form when to close?

Maybe you can have one look at my code and give me a hint?!

I created a new class:
Code:
Public Class IBSThread
    Public objQueryParameters As ArrayList
    Public Doc As Word.Document
    Public mobjProperties As DocProperties
    Public blnPushed As Boolean
    Public IBSWord As New comIBS_Word()
    Public Event Done()

    Public Sub Sub1()
        IBSWord.FillDocVariables(Doc, mobjProperties, objQueryParameters, Not blnPushed)
        RaiseEvent Done()
    End Sub
End Class

And this is the "main" program (frmGif is declared modally)
Code:
With objConnect.objIBS_Word
    .ResetDocVariables(...)
    .ParameterZufuegen = False 
    .DokumentVariablen = mobjProperties
    If Not objWordInstance Is Nothing Then
        Dim myThread As Threading.Thread
        .IstVorschau = True
        objQueryParameters = New ArrayList()
        objQueryParameters.Clear()
        objQueryParameters.Add(objIBS_INIT.ibsKrankenhausNr)
        objQueryParameters.Add(objIBS_INIT.ibsAbteilung)
        objQueryParameters.Add(objIBS_INIT.ibsVorlage)

        clsThread = New IBSThread()
        clsThread.blnPushed = Me.tlbButtonVorNach.Pushed
        clsThread.Doc = CType(objWordInstance.ActiveDocument, Word.Document)
        clsThread.mobjProperties = mobjProperties
        clsThread.objQueryParameters = objQueryParameters
        clsThread.IBSWord = objConnect.objIBS_Word

        myThread = New Threading.Thread(AddressOf clsThread.Sub1)
        myThread.Name = "IBS Thread"
        myThread.Start()

        frmGif = New frmIBS_Beschaeftigt() 
        frmGif.ShowDialog()
    End if
End with

Heres the handling of the event
Code:
Private Sub clsThread_Done() Handles clsThread.Done
    frmGif.Close()
       
    ChangeSize(False)
End Sub

But my form is not being closed! Why?
 
Back
Top