如何使用另一个填充数组?
how to populate an array using anither?
我正在练习用另一个数组填充一个数组。令人不安的是,我试图从第一个 array.I 中的某个点开始使用 Vb6
进行填充
尝试以下示例项目:
Option Explicit
Private Sub Form_Click()
Dim intIndex As Integer
Dim intSrc(10) As Integer
Dim intResult() As Integer
'fill source array with some etxt values
For intIndex = 0 To UBound(intSrc)
intSrc(intIndex) = intIndex * intIndex
Next intIndex
'fill resulting array with subset 3 to 7
intResult = FromArray(intSrc, 3, 7)
'show resulting array
For intIndex = 0 To UBound(intResult)
Print CStr(intIndex) & " : " & CStr(intResult(intIndex))
Next intIndex
End Sub
Private Function FromArray(intSrc() As Integer, intFrom As Integer, intTo As Integer) As Integer()
Dim intIndex As Integer
Dim intResult() As Integer
'resize resulting array to appropriate size
ReDim intResult(intTo - intFrom) As Integer
'fill resulting array with values from source array
For intIndex = 0 To UBound(intResult)
intResult(intIndex) = intSrc(intFrom + intIndex)
Next intIndex
'return resulting array
FromArray = intResult
End Function
当您 运行 它并单击表单时,您将看到生成的数组。
该项目包含一些基本的数组处理函数。尝试一些不同的值,看看它是如何工作的。
也尝试一些奇怪的值,如 intResult = FromArray(intSrc, 7, 3)
,并尝试理解错误。
我正在练习用另一个数组填充一个数组。令人不安的是,我试图从第一个 array.I 中的某个点开始使用 Vb6
进行填充尝试以下示例项目:
Option Explicit
Private Sub Form_Click()
Dim intIndex As Integer
Dim intSrc(10) As Integer
Dim intResult() As Integer
'fill source array with some etxt values
For intIndex = 0 To UBound(intSrc)
intSrc(intIndex) = intIndex * intIndex
Next intIndex
'fill resulting array with subset 3 to 7
intResult = FromArray(intSrc, 3, 7)
'show resulting array
For intIndex = 0 To UBound(intResult)
Print CStr(intIndex) & " : " & CStr(intResult(intIndex))
Next intIndex
End Sub
Private Function FromArray(intSrc() As Integer, intFrom As Integer, intTo As Integer) As Integer()
Dim intIndex As Integer
Dim intResult() As Integer
'resize resulting array to appropriate size
ReDim intResult(intTo - intFrom) As Integer
'fill resulting array with values from source array
For intIndex = 0 To UBound(intResult)
intResult(intIndex) = intSrc(intFrom + intIndex)
Next intIndex
'return resulting array
FromArray = intResult
End Function
当您 运行 它并单击表单时,您将看到生成的数组。
该项目包含一些基本的数组处理函数。尝试一些不同的值,看看它是如何工作的。
也尝试一些奇怪的值,如 intResult = FromArray(intSrc, 7, 3)
,并尝试理解错误。