Important alert: (current site time 7/15/2013 11:06:17 PM EDT)
 

VB icon

Control Arrays

Email
Submitted on: 1/11/2002 5:39:58 PM
By: John Bridle  
Level: Intermediate
User Rating: By 1 Users
Compatibility: VbScript (browser/client side)
Views: 12677
author picture
(About the author)
 
     This code demonstrates how control arrays can be used to carry out repetative math calculations in forms easily.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Control Arrays
' Description:This code demonstrates how control arrays can be used to carry out repetative math calculations in forms easily.
' By: John Bridle
'
' Returns:A total value based on the repetative formula!
'
' Assumes:This code is in its simplist format for the demonstration of how Control Arrays can be used in web programing!
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7121&lngWId=4'for details.'**************************************

<html>
<head>
<meta http-equiv="Content-Language" content="en-gb">
<title>Sample of Control Arrays</title>
<SCRIPT Language="vbscript">
<!--
sub Calc()
'Declare the variables required for the process, notice I have declared an array 
'for the txtBox control and have specified how many elements it has.
Dim i,Total,a,txtBox(4)
i=0
a=0
Total=0
'Now I perform a Do statement to cycle through my array performing in this case an addition
'to add each text box to one another!
Do until i=4
	a=frmTest.txtBox(i).value
	Total=Total+a
	i=i+1
Loop
'Finally I assign the Total Variable to the Total TextBox
frmTest.txtTotal.Value=Total
End sub
-->
</SCRIPT>
</head>
<body onload="Calc()">
<form method="POST" name="frmTest" action="Testing.asp">
	<p><input type="text" name="txtBox" size="20" value="1" onchange="Calc()">+<br>
<input type="text" name="txtBox" size="20" value="2" onchange="Calc()">+<br>
<input type="text" name="txtBox" size="20" value="3" onchange="Calc()">+<br>
<input type="text" name="txtBox" size="20" value="4" onchange="Calc()"></p>
	<p>Totals:</p>
 <p><input type="text" name="txtTotal" size="20"></p>
</form>
</body>
</html>


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

1/5/2003 12:21:48 PMRobert L Long

The only problem with this, is with any VBScript function; only compatiable with IE. This would be much more benificial in JScript.
(If this comment was disrespectful, please report it.)

 
12/7/2005 7:57:23 AMNikky

only compatiable with IE
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.