Hi Mark,
I can confirm what you're seeing - it's been that way since
at lease 14.01, so it's not something specific to A2K.
rdh.
Public Sub btnGetPoint_Click()
Dim pt As Variant
Me.Hide
MsgBox "test1"
Me.Show
MsgBox "text2"
'make sure no other code is written after the Me.Show call
End Sub
What happens? Well, like you expect, the code hides the form, does a
message box containing "test1" then the Form is redisplayed. If you close
this form, you get the display "test2". Now here's the interesting part.
If instead of closing the form, I hit the button a few times, something
changes. I get "test1" in each instance, but upon closing the form, for
ever time that I click the button, I now have that many message boxes
containing "test2" in them that I must dismiss. So, like I said, it's
almost like it's starting a new instance of the form, without triggering the
initialize events. It doesn't pick up where it left off.
John
Richard D. Howard [Autodesk GIS] wrote in message
<7kbr0g$cq...@adesknews2.autodesk.com>...
>
>Mark Webb (Autodesk - ADT Software Engineer) wrote in message
><7kavrd$9p...@adesknews2.autodesk.com>...
>>
>>I've noticed some peculiarity which I cannot seem to work around..
>>
>
Aren't you complicating something intended to be simple?
When you show a Modal Dialog / UserForm, "no subsequent code is executed
until the Dialog / UserForm is hidden or unloaded". This is by design.
And it also happens when you show the SAME INSTANCE of your hidden UserForm
which is still a Modal Form.
" MsgBox "text2" " is subsequent code. It is not executed unless you unload
the form or ... you use my modeless control.
Cheers
Denis
Personally I cannot see how this was *As Design*, as it is pretty
unintuitive behaviour. I've never known Win32 preventing subsequent calls to
be delayed after a ShowWindow(SW_SHOW)
Once you know the problem and how to get around it, this doesn't really
become an issue, so putting Me.Show as the last call in the routine is
fine...
--
Mark Webb
Software Engineer, AutoCAD Architectural Desktop
Autodesk, UK
mark...@eur.autodesk.com
http://www.autodesk.com/archdesktop
Denis Gagné <de...@videotron.ca> wrote in message
news:7kpfio$7t...@adesknews2.autodesk.com...
>This is going further than I expected :-)
This is an interesting subject for discussion that could go further.
I just may not have found the right words to express a different point of
view and I'm very sorry
>
>Personally I cannot see how this was *As Design*, as it is pretty
>unintuitive behaviour. I've never known Win32 preventing subsequent calls
to
>be delayed after a ShowWindow(SW_SHOW)
>
This may be limitative but isn't modality an intended limitation?
>Once you know the problem and how to get around it, this doesn't really
>become an issue, so putting Me.Show as the last call in the routine is
>fine...
Yes, except for an event procedure.
The only workaround I know is to use the Activate Event to maintain the
activity after a UserForm becomes active. Unfortunately this event is
triggered only once and you will have to Unload the Userform instead of
hiding it.
Code for UserForm1:
Private Sub CommandButton1_Click()
testContinue
End Sub
Private Sub UserForm_Activate()
Select Case Caption
Case "Continue"
testContinue
'Case...
End Select
End Sub
Code for Module1.bas:
Public Sub testContinue()
Static Continue As Boolean
If Not Continue Then
Unload UserForm1
'Here you can interact with AutoCAD
' using ThisDrawing.Utility.GetPoint()
MsgBox "Before"
Continue = True
'Set the Caption for an appropriate action
UserForm1.Caption = "Continue"
'Show a new instance of the UserForm
UserForm1.Show
Else
'Action that will take place after
'the new instance of UserForm1
'is activated
Continue = False
UserForm1.Caption = "UserForm1"
MsgBox "After"
End If
End Sub
Salutations
Denis
Unintuitive yes, but this is expected and makes sense. VBA forms must be
MODAL. This means that Me.Show starts a modal state while Me.Hide ends the
modal state.
Eg.
Sub Confusion()
UserForm1.Show ' Begins modal state
MsgBox "Hi" ' does not display until modal state ends;
' since a new modal state was created
' this does not execute until the
modal
' state created in
CommandButton1_Click()
' ends
End Sub
Private Sub CommandButton1_Click()
Me.Hide ' Ends modal state from Sub Confusion
MsgBox "Test" ' Displays immediately
Me.Show ' Begins new modal state
MsgBox "Test2" ' does not display until modal state ends
End Sub
In C++, Me.Show is equivalent to calling DoModal() and not ShowWindow().
Cheers,
Jorge
Denis Gagné wrote in message <7kqp9s$9s...@adesknews2.autodesk.com>...