Cannot Make DDE Link to Object as Child of Another Object

ID Number: Q75091

1.00

WINDOWS

buglist1.00

Summary:

When performing dynamic data exchange (DDE) from a Visual Basic client

application to any Windows server application (including Visual Basic

server applications), you cannot make a DDE link to an object that is

not a direct child of a form in the Visual Basic application.

For example, with Excel you cannot establish a DDE link from a text

box in a Visual Basic application if that text box is contained within

a picture box on Form1.

The text box must be on Form1 and not a child of any other object on

that form.

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

programming system version 1.0 for Windows. Microsoft is researching

this problem and will post new information here as it becomes

available.

More Information:

To work around this problem, create an additional object on the form

and set that object's Visible property to False. You can then

establish a DDE link with this hidden object.

Establishing a DDE link with a hidden object will issue the Change

event for this object. You can attach code to this event that will

update the information sent via the DDE link to the appropriate

control, which may or may not be a direct child of the form.

The following example demonstrates this workaround:

First, create the server application in Visual Basic:

1. Start Visual Basic. Form1 will be created by default.

2. Put a text box (Text1) on Form1.

3. Save the Form and Project with the name SERVER.

4. From the File menu, choose Make EXE File, make an .EXE, and call it

SERVER.EXE.

Next, create the client application in Visual Basic:

1. From the File menu, choose New Project. Form1 will be created by

default.

2. Put a picture box (Picture1) on Form1.

3. Put a text box (Text1) in the picture box (Picture1) as follows:

a. Click ONCE on the text box icon in the toolbox.

b. Move the mouse pointer on top of Picture1 (note the mouse

pointer is a cross).

c. Press the left mouse button and drag the mouse pointer to

size the text box.

d. Release the left mouse button.

e. Text1 is now a child of Picture1.

4. Put a text box (Text2) on Form1.

5. Set the Visible property of Text2 to False.

6. Add the following code to the General Declaration section of Form1:

Const NONE = 0

Const HOT = 1

7. Add the following code to the Form_Load event procedure of Form1:

Sub Form_Load ()

'This procedure will start the Visual Basic server application

'that was created earlier.

Form1.Show 'Show Form1

z% = Shell("C:\VB\SERVER,1)

z% = DoEvents() 'Causes Windows to process the Shell.

Text2.LinkMode = NONE 'Clears DDE Link if already there.

Text2.LinkTopic = "Server|Form1" 'Sets up link with VB server.

Text2.LinkItem = "Text1" 'Sets link to Text Box on server.

Text2.LinkMode = HOT 'Establish a hot DDE link.

End Sub

8. Add the following code to the Change event procedure of Text1:

Sub Text2_Change ()

'This procedure will cause the information in the text field of

'Text1 to be updated whenever the text property of Text2 changes.

Text1.Text = Text2.Text

End Sub

You can now run the VB client application:

1. From the Run menu, choose Start.

2. Form1 of the client application will be loaded and the Visual Basic

server application will automatically be started.

3. Any information you now type in the text box of the server

application will be automatically updated to the invisible text box

(on Form1) in the client application and then automatically

transferred to the Visible text box (on Picture1 on Form1) in the

client application.

Additional reference words: 1.00