找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 6193|回复: 2

Using dynamic arrays

[复制链接]

96

主题

158

回帖

4

精华

核心会员

积分
6513
发表于 2012-6-6 07:44:57 | 显示全部楼层 |阅读模式
<HTML>
<HEAD>
<TITLE>Dynamic Array Application</TITLE>
<SCRIPT LANGUAGE="vbscript">

Option Explicit     'require all variables to be declared

ReDim myArray(0)    'create a dynamic array with 1 element
Dim intIndex        'variable to track the array index

intIndex = 0        'assign the first index number to counter
     
Sub cmdButton1_OnClick
       
   ' Store the user input in the array
   myArray(intIndex) = Document.frmForm1.txtText1.Value   
   intIndex = intIndex + 1          'increment the array counter by one
   ReDim Preserve myArray(intIndex) 'increase the size of the array
   Document.frmForm1.txtText1.Value = ""     'Empty the text box again
End Sub

Sub cmdButton2_OnClick
   Dim x, y, strArrayContents      'declare some variables we'll need
         
   'repeat this process as many times as there are array elements
   'note: the last element will always be empty because we've
   'incremented the counter *after* the assignment.
   'try changing the above sub so that we always fill every element
   For x = 0 to intIndex - 1
      'assign a short description and the element no to the variable
      strArrayContents = strArrayContents & "Element No." & _
                         CStr(x) & " = "
      'add to this the contents of the element
      strArrayContents =  strArrayContents & 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")
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>

7

主题

414

回帖

1

精华

铂金会员

积分
2173
发表于 2013-4-12 22:59:55 | 显示全部楼层
M。。原來是這樣做

0

主题

68

回帖

0

精华

铜牌会员

积分
94
发表于 2015-1-11 14:17:49 | 显示全部楼层
谢谢分享
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表