FP97: Sample VBScript to Calculate Contents of Drop-Down Lists

Last reviewed: March 18, 1998
Article ID: Q170495
The information in this article applies to:
  • Microsoft FrontPage 97 for Windows with Bonus Pack

SUMMARY

This article provides a sample Visual Basic Script that calculates the contents of a drop-down list and displays the results in a text box.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

To create a sample Visual Basic scripting program to add the contents of multiple drop-down menus, use the following steps:

  1. In FrontPage Explorer, open or create a Web.

  2. Open a Web page in FrontPage Editor.

  3. Insert the following form fields, by pointing to Form Field on the Insert menu, and then clicking the appropriate command:

    Two drop-down menus One one-line text box One push button

  4. Right-click the first drop-down menu form field and then click Form Field Properties.

  5. In the Name box, type the following name, and then click OK:

    Drop1

  6. Repeat steps 4 and 5 for the remaining form fields. Use the following names:

           Object                        Name
           ======                        ====
    
           Second Drop-Down Menu         Drop2
           One One Line Text Box         Text1
           One Push Button               Button1
    
    

  7. Right-click the first drop-down menu form field and then click Form Field Properties.

  8. In the Drop-down Menu Properties dialog box, click Add.

  9. In the Add Choice dialog box, enter a number in the Choice box, and then click OK.

  10. Repeat steps 8 and 9 for each additional number you want to enter.

  11. Repeat steps 7 through 10 for the second drop-down form field.

  12. Right-click the push button form field and then click Form Field Properties.

  13. Click Normal, and then click OK.

  14. On the Insert menu, click Script.

  15. Click to select the VBScript check box.

  16. In the Script box, type the following code:

    sub button1_onclick

    ' Create the form object. dim theform set theform = document.form1

    ' Return the value from the first drop-down menu. Drop-down text ' boxes return values as text. The Cint function converts text

    ' into an integer. firstvalue = Cint(theform.drop1.options _ (theform.drop1.selectedindex).text)

    ' Return the value from the second drop-down menu. secondvalue = Cint(theform.drop2.options _ (theform.drop2.selectedindex).text)

    ' Display the results in a text box. theform.Text1.value = firstvalue + secondvalue

    end sub

  17. Click OK.

  18. Save the file and preview it in your Web browser.

For additional information about Microsoft Visual Basic Scripting, please see the following Microsoft Web site:

   http://www.microsoft.com/vbscript/


Additional query words: 97

Keywords : fpedit kbusage kbdta
Version : windows:97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto
Solution Type : kbcode


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: March 18, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.