|
<HTML>
<HEAD>
<TITLE>Dynamic Array Application No.2</TITLE>
<SCRIPT LANGUAGE="vbscript">
Option Explicit 'require all variables to be declared
ReDim myArray(0) 'create a dynamic array with 1 element
Sub cmdButton1_OnClick
'Store the value enter by the user in the array
myArray(UBound(myArray)) = Document.frmForm1.txtText1.Value
'grow the array to be one element greater than its current size
'Preserve its contents
ReDim Preserve myArray(UBound(myArray) + 1)
'Empty the text box for the user
Document.frmForm1.txtText1.Value = ""
End Sub
Sub cmdButton2_OnClick
'declare some variables we're going to need
Dim x, y, strArrayContents
'repeat this process as many times as there are array elements
For x = 0 to UBound(myArray) - 1
'add a short description and the element number to the variable,
'along with the contents of the element and a carriage return
strArrayContents = strArrayContents & "Element No." & CStr(x) & _
" = " & myArray(x) & vbCrLf
'go back and do it again for the next value of x
Next
'when we're done, show the result in a message box
y = MsgBox(strArrayContents,0,"Dynamic Array Application #2")
End Sub
</SCRIPT>
</HEAD>
<BODY BGCOLOR="white">
<FORM NAME="frmForm1">
<INPUT TYPE="text" NAME="txtText1"><BR>
<INPUT TYPE="button" NAME="cmdButton1" VALUE="Add to array"><P>
<INPUT TYPE="button" NAME="cmdButton2" VALUE="Show Array Contents">
</FORM>
</BODY>
</HTML>
|
|