UAE Changing Text1.Text or Label1.Caption in Form_LinkClose

ID Number: Q74293

1.00

WINDOWS

Summary:

Running a Visual Basic application under the following conditions will

result in a Windows Unrecoverable Application Error (UAE) message:

1. A DDE (dynamic data exchange) conversation has been established

with another application where Visual Basic is the server (for

example, another application such as Microsoft Excel for Windows

initiates the DDE conversation.)

2. The Text, Picture, or Caption property of a Textbox, Picture, or

Label is set within the LinkClose event procedure of a form.

The problem occurs for a program run in the Visual Basic development

environment or run as an .EXE program. The problem does not occur if

the Visual Basic application acts as the client (that is, initiates

the conversation) in a DDE conversation.

Microsoft has confirmed this to be a problem in Microsoft Visual Basic

programming system version 1.0 for Windows. We are researching this

problem and will post new information here as it becomes available.

More Information:

The problem occurs any time a control capable of DDE is changed within

the LinkClose event procedure of a form. Changing a control capable of

DDE causes Visual Basic to check all valid links. Because the

LinkClose event is incorrectly called before the DDE channel has been

fully deleted, Visual Basic treats the "partially" closed channel as a

valid link. A Windows UAE is generated as a result of Visual Basic

checking this invalid link.

To work around this problem, do the following:

1. Add a Timer control to the form.

2. Remove the code from the LinkClose event of Form1 and replace it

with:

Sub Form_LinkClose ()

Timer1.Enabled = -1

Timer1.Interval = 10

End Sub

3. Add the following code to the Timer event of Timer1:

Sub Timer1_Timer ()

Label1.Caption = "new caption"

'or Text1.Text = "new text" if using text box

Timer1.Enabled = 0

End Sub

When this is run and a LinkClose event occurs, the LinkClose event

will be allowed 10 milliseconds to finish, after which the desired

code will be executed (in the timer event) with no UAE.

Steps to Reproduce Problem

--------------------------

1. Start Microsoft Word for Windows (WINWORD.EXE).

2. From the Macro menu, choose Edit.

3. Type "autoexec" (without the quotation marks) as the name of the

macro you want to create, and press ENTER.

4. Add the following lines of code:

Sub MAIN 'sets up DDE link with VB

ChanNum = DDEInitiate("uaetest","form1")

Print ChanNum 'To confirm that link has been established

End Sub

5. Exit Word for Windows and save all changes as you are prompted.

6. Start Microsoft Visual Basic (Form1 will automatically be created

by default).

7. Put a label box on Form1 (or a text box on Form1).

8. Add the following code to the LinkClose event of Form1:

Sub Form_LinkClose ()

Label1.Caption = "new caption"

' or Text1.Text = "new text" if using TextBox

End Sub

9. From the File menu of Visual Basic, Save the file as Uaetest.Frm.

10. From the File menu of Visual Basic, Save the project as Uaetest.Mak.

11. Run Uaetest.

12. Start Windows. It will automatically run the macro to establish

the DDE link. This can be confirmed by the number 1 showing up on

the status line in Word for Windows.

13. Exit Word for Windows.

14. A UAE message will be displayed.

Additional reference words: 1.00