Free Training


C Language  |  CSS  |  MainFrame  |  VBScript  |  PHP  |  XML  |  C++ Tutorials  |  Ajax  |  JavaScript  |  CSS3  |  UML  |  jQuery  |  Microsoft AJAX

VBScript Tutorials

 
Home Tutorials VBScript
 

VB Script - Working with Variables

 

VB Script - Working with Variables - Page 2

Page 2 of 2


.


.


 




Example :


< HTML >
< HEAD >
< TITLE >vbscript example< / TITLE >
< SCRIPT LANGUAGE="VBScript" >
< ! -- Add this to instruct non-IE browsers to skip over VBScript modules.
Option Explicit

Sub cmdCalculate_OnClick
Dim AmountofTax
Dim CRLF
Dim Message
Dim Subtotal
Dim TABSPACE
Dim TAX_RATE
Dim TotalCost

' Define our constant values.
TAX_RATE = 0.06
CRLF = Chr(13) & Chr(10)
TABSPACE = Chr(9)

' Perform order calculations.
Subtotal = Document.myform.txtQuantity.Value * Document.myform.txtUnitPrice.Value
AmountofTax = Subtotal * TAX_RATE
TotalCost = Subtotal + AmountofTax

' Display the results.
Message = "The total for your order is:"
Message = Message & CRLF & CRLF
Message = Message & "Subtotal:" & TABSPACE & "$" & Subtotal & CRLF
Message = Message & "Tax:" & TABSPACE & "$" & AmountofTax & CRLF
Message = Message & "Total:" & TABSPACE & "$" & TotalCost
MsgBox Message,,"Your Total"
End Sub
-->
< /SCRIPT >
< /HEAD >
< BODY >
< FORM NAME="myform" >
< TABLE >
< TR >
< TD >< B >Quantity:< /B >< /TD >
< TD >< INPUT TYPE="Text" NAME="txtQuantity" SIZE=5 >< /TD >
< /TR >
< TR >
< TD >< B >Unit price:< /B >< /TD >
< TD >< INPUT TYPE="Text" NAME="txtUnitPrice" SIZE=5 >< /TD >
< /TR >
< /TABLE >
< BR >
< INPUT TYPE="Button" NAME="cmdCalculate" VALUE="Calculate Cost" >
< /FORM >
< /BODY >
< /HTML >


The output on the browser would be as under :




The commonly used operands are addition,subtraction, multiplication and subtraction. The result of calculations are stored in a variable called subtotal.All the calculations are than displayed by using the MsgBox function. The ampersand character is used to concatenate two strings.


Conclusion :

Till now you must have learn the types of variables the vbscript uses. How to declare variables and use it within the script and what a comment line in a script.




First Page: VB Script - Working with Variables


Read Next: Working with Objects in VB Script



 

 

Comments


sudhap said:

  hi
in the above program what is document variable and from where it comes
i tried this program
but it is not working
waiting for reply
veena
March 8, 2007, 8:15 am

Rick Shultz said:

  Good basic tutorial. Thanks.
June 24, 2008, 5:05 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Weekly Offers

Sponsored Links