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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Watching for events in Form2 while Form1 does something.

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
I think this might involve Threads, but I'm not sure.
I have a form, it's going to do some work, and update a dialog box with a progress bar. This dialog box is going to have a cancel button that would end the procedure in the form. How can I go about doing this?
 
I don't think that this will work because the moment you open a Dialog window from a form, current form's execution will stop till you close the Dialog window. So I guess you might have to use a non-Dialog window to do this. So to achieve this first you have to declare a public property for the main window, something like 'cancelProcess' and the first line of code in your process intensive function should be 'If (cancelProcess) then Exit' and then you might have to use a Thread 'Sleep' function for every 30 secs so that the user gets a chance to click the 'Cancel' button on the progress bar window(otherwise user may always get an hourglass cursor), and once the user clicks the cancel button you might have to set 'cancelProcess' property of main window to TRUE, so that the caller can exit out of the loop. I guess this should work.

-Kris11
 
try this: (pseudo-code)

code on form1, this is the form that makes you show the dialog

//form1
private withevents myfrmDialog as frmDialog

sub DoSomething
myformdialog=new frmdialog
myformdialog.showmodal
end sub

sub myfrmDialog_Cancelled()
myformdialog=nothing / or close or whatever
end sub

// end form1


//frmDialog

sub DoSomething
public event Canceled

sub btnCancel_Click
raiseevent Canceled
end sub

// end frmDialog


The gap between theory and practice is not as wide in theory as it is in practice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top