Solved

Ending a process

Posted on 2000-04-17
4
139 Views
Last Modified: 2010-05-02
I have a function in a separate class that updates the treeview control nodes on a form. The class has a reference to the tree control, but not the form.  The problem is that if try to close the form while the function is updating, the form closes, but then reopens because the function is still  referencing the treeview. Anyone know how I can keep this from happening?  I've tried setting the object= nothing when the form closes, as well as the reference to the treeview, but it didn't work.  
0
Comment
Question by:gferrell
  • 2
4 Comments
 
LVL 32

Expert Comment

by:bhess1
ID: 2723697
If you reference a form, or a control on the form, after the form has been unloaded (or closed), the form will reload.

You need to ensure that you abort the update when you want to close the form.  Try something like this:

In your Class, include a Private variable, and a public function like this:

Private clsAbortFlag as Boolean

Public Function clsAbort() as Integer

If CanNotAbort() Then   ' Test - can I stop now?  (Optional)
   clsAbort = False
Else
   clsAbortFlag = True
   Do While clsAbortFlag
      DoEvents ' Or however you prefer to wait for processing to complete
   Loop
   clsAbort = True
End If
End Function

In each of the procedures in your class that might be affected, insert a test:

  If clsAbortFlag Then Exit Sub

In your Form_QueryUnload, add something like this:

If Not clsAbort Then
   MsgBox "Can not close at this time."
   Cancel = True
   Exit Sub
End If

Then continue as normal.
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2723702
There are multiple typos (Sorry), but you should get the idea.
0
 

Accepted Solution

by:
Scrappy earned 200 total points
ID: 2723934
-------------------------------------
FORM1
-------------------------------------
Option Explicit

Private WithEvents clsTreeViewAlteringClass As class1
Private bWaitingToClose As Boolean

Private Sub clsTreeViewAlteringClass_LongStoppedProcessing()
    If bWaitingToClose Then Unload Me
End Sub

Private Sub Command1_Click()
    Call clsTreeViewAlteringClass.addnodes
End Sub

Private Sub Form_Load()
    Set clsTreeViewAlteringClass = New class1
    bWaitingToClose = False
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If clsTreeViewAlteringClass.bActive = True Then
        bWaitingToClose = True
        clsTreeViewAlteringClass.bStopProcess = True
        Cancel = True
    End If
End Sub

-------------------------------------
CLASS1
-------------------------------------
Option Explicit

Public m_bStopLongProcess As Boolean
Public m_LongProcessActive As Boolean
Public Event LongStoppedProcessing()

Public Function addnodes() As Boolean

Dim i As Integer
Dim ns As Nodes

    m_LongProcessActive = True
   
    Set ns = Form1.TreeView1.Nodes
   
    m_bStopLongProcess = False
   
    ns.Add , "r", "r", "this is text"
   
    Do While i < 5000 And Not m_bStopLongProcess
        ns.Add "r", tvwChild, "c" & CStr(i), "child 1" & CStr(i)
        DoEvents
        i = i + 1
    Loop
   
    Set ns = Nothing
   
    m_LongProcessActive = False
   
    RaiseEvent LongStoppedProcessing

End Function


0
 

Author Comment

by:gferrell
ID: 2724029
Good thinking using an event!  
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to debug this code 7 61
How to set the sa password in a vb6 code for sql connection 9 54
Recommendation vb6 to vb.net or others 14 150
Excel Automation VBA 19 71
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question