Multiple Line Textboxes In Custom Dialog Boxes

Last reviewed: July 30, 1997
Article ID: Q94264
The information in this article applies to:
  • 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 "as is" 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, "Microsoft Word"
   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, "Line 1"
   Text 43, 55, 48, 13, "Line 2"
   Text 43, 79, 48, 13, "Line 3"
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.

  1. 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.
    
    

  2. Create the following subroutines to handle the events for the form items:

       Sub btnOK_Click ()
       status.Caption = "ok"
       End Sub
    
       Sub btnCancel_Click ()
       status.Caption = "cancel"
       End Sub
    
       Sub Form_LinkExecute (CmdStr As String, Cancel As Integer)
       If InStr(1, CmdStr, "end") Then
          Cancel = 0
          End
       End If
       End Sub
    
    

  3. 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 "multline".
  • Loops until the contents of the label is not in a "waiting" state.
  • If the label is set to "OK", uses DDE to request the contents of the multiline textbox and then displays the result in a message box.
  • Uses a DDEExecute command to exit the Visual Basic application.

    Sub MAIN
    
    Shell "multline" chan = DDEInitiate("multline", "system") status$ = DDERequest$(chan, "status")
    While status$ = "waiting"           ' wait for a button to be pushed
       status$ = DDERequest$(chan, "status")
    
Wend Select Case status$
   Case "ok"                        ' OK button pushed
      a$ = DDERequest$(chan, "multline")
      DDEExecute chan, "end"        'shutdown multiline form
      MsgBox a$, "Multiline Textbox Contents"
   Case "cancel"                    ' Cancel button pushed
      DDEExecute chan, "end"        'shutdown multiline form
End Select
End Sub

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, pages 236 and 303


KBCategory: kbmacro
KBSubcategory:
Additional query words: 1.0 1.10 1.10a 2.0 2.0a winword winword2
2.0a-CD 2.0b 2.0c TextBox multi line multiple-line user-defined vb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.