Tutorials
VBScript.
.
| < 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.
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

|
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 |
| Good basic tutorial. Thanks. |
|
hi I have a problem i want to convert a value into a variable how can i do that? here is my sample code. 'dim onjName11 'dim onjName12 'dim onjName21 'dim onjName22 onjName11=22222222 onjName12=33333333 onjName21=44444444 onjName22=55555555 for i = 1 to 2 vale="onjName" & i &"1" WScript.Echo vale next |
|
Dear Ghaazi, Its never possible to use for loop for values within a text Regards, Mukesh |
| VBScript does support contants, as of version 5: http://msdn.microsoft.com/en-us/library/16twy8ed(VS.80).aspx |