Microsoft KB Archive/94264

-

{| The information in this article applies to:
 * width="100%"|
 * Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, and 2.0c
 * Microsoft Windows operating system versions 3.0 and 3.1

SUMMARY
Although Word for Windows supports multiple-line edits in input boxes, such as the one produced by the WordBasic InputBox$ command, multiple-line edits are not available in WordBasic custom or user-defined dialog boxes.

The WordBasic TextBox statement creates a text or edit box inside a user-defined dialog box. You can use the TextBox statement to type text in a dialog box; however, the TextBox statement is limited to a single line of text.

Note: This restriction does not apply to later versions of Word for Windows.

Note: This article assumes you have a working knowledge of Microsoft Visual Basic and the WordBasic macro programming language supplied with Word for Windows.

MORE INFORMATION
You can use one of the following two methods to prompt for multiple lines of text.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code &quot;as is&quot; without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Method 1
In a custom dialog box you can simulate a multiple-line textbox by creating multiple textboxes positioned immediately above or below one another. The following custom dialog box definition uses three separate TextBox statements to prompt for three lines of information:

Sub MAIN Begin Dialog UserDialog 400, 168, &quot;Microsoft Word&quot; TextBox 126, 28, 252, 18, .TextBox1 TextBox 126, 53, 252, 18, .TextBox2 TextBox 126, 78, 252, 18, .TextBox3 OKButton 270, 106, 88, 21 CancelButton 270, 133, 88, 21 Text 43, 30, 48, 13, &quot;Line 1&quot; Text 43, 55, 48, 13, &quot;Line 2&quot; Text 43, 79, 48, 13, &quot;Line 3&quot; End Dialog Dim dlg As UserDialog n = Dialog(dlg) End Sub Note: The WordBasic InputBox$ command and the Word for Windows FILLIN field accept more than a single line of text.

Method 2
Microsoft Visual Basic supports the use of multiple-line textboxes, including scrollbars and other features. The following method describes how to create a simple Visual Basic program that contains a multi-line textbox, an OK button, and a Cancel button. In addition, a WordBasic macro is provided that shows how to use this application.

  Create a new project in Visual Basic with a form that has a textbox, a label, and two buttons on it with the following properties: Form: Name = multline LinkMode = 1 - Source LinkTopic = system Textbox: Name = multline Multiline = True Scrollbars = 3 - Both Text = (nothing.. or any default text you want in the textbox) Button 1: Name = btnOK Caption = &OK Button 2: Name = btnCancel Caption = &Cancel Label: Name = status Caption = waiting Note: Position the label beyond the form borders so that it is not visible when you run the application. Word uses this label to determine if the OK button was pressed or not. To position the label: enlarge the size of the form, move the label into the open space, and decrease the size of the form to cover the label.   Create the following subroutines to handle the events for the form items: Sub btnOK_Click status.Caption = &quot;ok&quot; End Sub

Sub btnCancel_Click status.Caption = &quot;cancel&quot; End Sub

Sub Form_LinkExecute (CmdStr As String, Cancel As Integer) If InStr(1, CmdStr, &quot;end&quot;) Then Cancel = 0 End End If  End Sub  Create the executable file by choosing Make EXE File from the File menu. Type a name for the program in the File Name box and choose the OK button.

Below is a WordBasic macro that does the following:  Runs the Visual Basic application using the Shell command. The Shell command below assumes the the Visual Basic application is found on your MS-DOS path. You can add a full drive and path specification if needed. Uses dynamic data exchange (DDE) to obtain the contents of the label. The first argument of the DDEInitiate command must be the name of the Visual Basic program file. In the sample macro below, the filename is &quot;multline&quot;. Loops until the contents of the label is not in a &quot;waiting&quot; state. If the label is set to &quot;OK&quot;, uses DDE to request the contents of the multiline textbox and then displays the result in a message box.</li>  Uses a DDEExecute command to exit the Visual Basic application. Sub MAIN </li></ul>

Wend Select Case status$ Case &quot;ok&quot;                       ' OK button pushed a$ = DDERequest$(chan, &quot;multline&quot;) DDEExecute chan, &quot;end&quot;       'shutdown multiline form MsgBox a$, &quot;Multiline Textbox Contents&quot; Case &quot;cancel&quot;                   ' Cancel button pushed DDEExecute chan, &quot;end&quot;       'shutdown multiline form End Select End Sub