Issues with modal UserForms and Inventor

Issues with modal UserForms and Inventor

bshbsh
Collaborator Collaborator
691 Views
5 Replies
Message 1 of 6

Issues with modal UserForms and Inventor

bshbsh
Collaborator
Collaborator

Hey,

I'm having this problem since forever, so I'm asking for advice.

I'm using a modal userform to display output of my macros. The form is just a simple form with a large textbox and vertical scrollbar, a close button and a progress bar (self made).

The problem is, I need to show this form modal for certain macros, to prevent users doing anythign with the currently open document while the macro is doing it's things. The macros output sort of logging information into the textbox, and it should automatically scroll. But sometimes these macros take a looooong time to run. Sometimes even Windows7 thinks the inventor application is hung and not responding because the macros working. In these cases the modal userform disappears and goes behind the inventor window. Also, after this happens for the first time, the textbox stops scrolling completely and even though any text input to teh userform should bring it to foreground and give it focus (which is apparently required for the text scrolling to work), it does not work either.

The only thing I could do is, to put some DoEvents calls into the macros. This makes inventor "repsonsive" again and makes the textbox scrolling too. But the problem is, doing taht also defies the modality of the form and the user interaction events is taken by inventor and they do can manipulate teh open documents despite an open modal form.

 

So long story short: is there a better or recommended way to fix this?

Thanks.

IV2018.3.6, W7 x64.

0 Likes
692 Views
5 Replies
Replies (5)
Message 2 of 6

HideoYamada
Advisor
Advisor

Hello bshbsh,

 

I have not understood exactly what is you problem.

I made a dialog.

dialog.PNG

 

The code of this dialog is here :

Private StopRequired As Boolean

Private Sub StartButton_Click()
    StopRequired = False
    Dim lastTime As String
    
CloseButton.Enabled = False
While Not StopRequired DoEvents ' Do someting If lastTime <> Time Then lastTime = Time Label1.Caption = lastTime End If Wend

CloseButton.Enabled = True End Sub Private Sub StopButton_Click() StopRequired = True End Sub Private Sub CloseButton_Click() Me.Hide End Sub

And show the dialog as follows :

Sub test()
    UserForm1.Show
End Sub

The dialog is always in front of Inventor application window, and user cannot access Inventor application window.

 

Something conditions are different?

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 3 of 6

bshbsh
Collaborator
Collaborator

my form looks like this:

still workingstill working

big textbox with a scrollbar. on the first pic it is still scrolling...

stopped scrollingstopped scrolling

but after a while (when the process takes too long) it stops scrolling and windows shuffles it into the background, inventor window whites out, etc. i guess it's some windows thing, if a process is "not responding" for like 10 seconds or so, it thinks it is stuck, funnily the text is still gets added to the textbox and you see the scrollbar getting smaller and smaller as the box contents get longer, but windows still thinks womehow it is a stuck process, even if it is clearly doing something.

and it just stops scrolling if i switch to an other window. textbox is set to have focus every time a line of text is added to it and it is also repainted and everything, but no scrolly...

stopped scrollingstopped scrolling

this mostly happens if the process is taking longer than that supposed "threshold" for "stuck process" timeout.

0 Likes
Message 4 of 6

HideoYamada
Advisor
Advisor

Hello bshbsh,

 

I had focused on following in your first post.

 

> The only thing I could do is, to put some DoEvents calls into the macros.

> This makes inventor "repsonsive" again and makes the textbox scrolling too.

> But the problem is, doing that also defies the modality of the form and

> the user interaction events is taken by inventor and

> they do can manipulate the open documents despite an open modal form.

 

As far as I tried, the user could not access to Inventor even when DoEvents was called in the long loop.

I think this is the excepted behavior because the dialog is modal.

 

Best Regards,

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 5 of 6

bshbsh
Collaborator
Collaborator

I have done some more extensive testing, and it seems like the problem i'm having (userform and inventor seemingly not responding) is NOT just with modal forms, but any forms that are running long code.

example: non modal userform, with a button that does the long running code, and teh long running code puts and updates a progressbar on the statusbar in the inventor main window. this starts by updating nicely until like 5-10 seconds or so, then it "whites out" and "hourglasses" and shows "not responding" in the tilebar, neither the userform nor inventor can be accessed at all. then after like a minute or so when the code actually finishes, it just booom, comes back to life, progressbar at 100%, and the code is done fine and inventor works again. and that's with putting doevents into the code loop for every iteration.

0 Likes
Message 6 of 6

HideoYamada
Advisor
Advisor

Hello,

 

Does putting DoEvents into the loop resolve the problem that Inventor and dialog become "white out"?

 

Dialogs that need to prevent user access to the parent window must be modal.

Don't try to change mode-less dialog  to modal by ignoring window messages.

DoEvents invokes window message loop and an application can response to OS.

If an application ignores window messages from OS for a long time, the window become "white out".

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes