domino创建动态数组

Dynamic arrays
简述
Dim myDynamicArray() As String
ReDim [ Preserve ] arrayName  (  bounds  ) [ As  dataType ]



Option Base 1
' Declare a dynamic String array. Later, this is
' defined as a one-dimensional array whose elements
' are assigned values that the user enters. 
Dim myNames() As String
Dim ans1 As Integer
Dim ans2 As Integer
Dim counter As Integer
Dim userInput As String
' Ask the user to enter a number and assign it to ans1%.
ans1% = CInt(InputBox$ _
   ("How many names would you like to enter?"))
' Use ans1% as the upper bound of the array's only dimension.
ReDim myNames(ans1%)
' Elicit ans1% strings from the user, and assign them
' to successive elements in the array.
For counter% = 1 to ans1%
  myNames(counter%) = InputBox$("Enter a name: ")
Next
' Print the contents of the array on a single line
' with a space between the value of each element.
For counter% = 1 to ans1%
   Print myNames(counter%) " " ;
Next
' Output: a newline
Print ""
' Ask the user for another number and assign it to ans2%.
ans2% = CInt(InputBox$("How many more names?"))
' If the number is greater than 0, resize the
' array, preserving its original values, so that the
' user can enter additional values.
If ans2% > 0 Then
  ReDim Preserve myNames(ans1% + ans2%)
  ' Elicit the new values and assign them to the
  ' elements that have been allocated after the old ones.
  For counter% = 1 to ans2%
    myNames(counter% + ans1%) = InputBox$("Enter a name: ")
  Next 
  ' Print the contents of the array on a single line
  ' with a space between the value of each element.
   For counter% = 1 to ans1% + ans2%
    Print myNames(counter%) " " ; 
  Next   
  Print ""
End If
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值