Calculator Program In Html Using Vbscript

 admin  

Using VBScript in Internet ExplorerThe following sections describe how to use client-side VBScript in your Webpages. VBScript can also be used on the server, as discussed in Chapter 27.Although server-side VBScript can be browser-independent, client-side VBScriptrequires that the user have Microsoft Internet Explorer. Currently, Netscapeusers cannot run VBScript code.

  1. Call Vbscript From Html
  2. Calculator Program In Html Using Vbscript Java

Remember to keep your audience in mind whenusing VBScript. Events and ProceduresIn standard Visual Basic, you respond to events by placing code in event procedures.You can also use event procedures in VBScript, although writing them is notas easy because the event procedure declarations are not provided for you.As an example, consider the following HTML code, which creates two form elements,an input box and a button: Because the preceding two form elements are named, all you have to do to createan event procedure is write a VBScript subroutine with the appropriate nameand parameters.

Call Vbscript From Html

For example, by creating a VBScript subroutine called cmdCalculateOnClick,you can get IE to execute code in response to the button's Click event.The code in Listing 30.2 uses VBScript events in a simple interest calculator. Listing 30.2:Using VBScript to Access Web Page Elements Simple example of VBScript

R. TEnd FunctionSub cmdCalculateOnClickDim lPrincipalDim dblRateDim nYearsDim cInterestlPrincipal = CLng(txtPrincipal.value)dblRate = CDbl(txtRate.value)nYears = CInt(txtTime.value)cInterest = CalcInterest(lPrincipal, dblRate, nYears)MsgBox 'Your Interest is ' & FormatCurrency(cInterest)End SubSub txtRateOnChangeIf CDbl(txtRate.Value) 1 Then txtRate.Value = txtRate.Value / 100End Sub-Enter Principal: Enter Int. Rate: Time in Years. NOTEListing 30.2 uses HTML form elements, which have a different set of eventsand properties.

Calculator Program In Html Using Vbscript Java

Note, for example, the use of the Value propertyinstead of the Text property. However, as you will see in an upcomingexample, you can also insert controls onto Web pages, which have a morefamiliar set of properties and events.In the sample Web page in Listing 30.2, Internet Explorer knows which eventprocedure to run because the event procedure is named appropriately. However,you could just as easily specify a different Click event procedure bynaming it in the button's HTML: This syntax is useful with images in Web pages. Consider the standard methodof creating an image hyperlink: This approach works, but your only option is to jump to a new page. A moreversatile method is to specify a Click event in the IMG tag. TheClick event procedure could use VBScript code to move to the new siteor perform whatever action you wanted:

Simply insert the element you want in FrontPage and bringup the Script Wizard, which is shown in.The Script Wizard provides a hierarchical view of events.In the previous example, you examined the Navigate method of InternetExplorer's Window object. This method causes Internet Explorer to openthe specified URL. Another useful function is document.write, which writesHTML to the browser window:

However, before you submit the form tothe server, you might want to use VBScript to validate or change the information.Listing 30.3 shows an example of validating form data with VBScript. Listing 30.3:Modifying and Submitting a Form with VBScript Simple example of Forms

CAUTIONRemember that VBScript does not run in Netscape Navigator, so you may wantto perform validation tasks on the server.In Listing 30.3, many of the form tasks are handled in VBScript instead ofHTML. For example, the ACTION and METHOD parameters are left outof the form declaration. No submit button was provided because the form wassubmitted from VBScript code. Also, notice the hidden form field, which storesa value that the user did not enter.

A sample run of the page in Listing 30.3is shown in.VBScript validates form data before submitting it to the Web server. Using ActiveX ControlsIn addition to creating objects with the CreateObject method, you canembed objects in your Web page by using the tag. The tag allows you to place ActiveX controls in a Web page. Your VBScript code canthen access these objects, as in the list box example shown here: Calculator Program In Html Using VbscriptUsing

Acts as a unique identifier from the Windows Registrythat identifies the object.CODEBASE. Provides the URL for the OCX or CAB file usedto download the object. In the example, the ListBox control is builtinto Internet Explorer, so the CODEBASE parameter is not needed.height and width.

Javascript

Indicate the size of theobject.PARAM tags. Control behavior of an object, such as the Propertieswindow in Visual Basic.The best way to insert ActiveX controls into a Web page is to do so in FrontPageand then copy the resulting HTML into your Web page.

Shows the list of ActiveX controls in FrontPage.Class IDs can be determined by using FrontPage. The controls that beginwith 'Microsoft Forms' are built in, or intrinsic to, Internet Explorerand do not require downloading.In Chapter 14, 'Creating ActiveX Controls,' you learned how to createyour own ActiveX controls, which can be placed on a Web page. Using your owncontrols offers several advantages over plain VBScript and HTML, including thefollowing:.Full VB functionality is available.Your code cannot be easily viewed by the user, as with script code.

   Coments are closed