English 中文(简体)
• 如何将2个阵列中的一个层面分配给设在BA的新1个阵列
原标题:How to assign one dimension of a 2d array to a new 1d array in VBA

I need to be able to create a newarray and assign it to another2darray(atsomeelement)

array1(0) = 1
array1(1) = 2

现在

array2(0) = array1

因此,

array2(0)(0) = 1
array2(0)(1) = 2

现在,我想拿出一个新的阵列,把1个阵列分配给它。

newarray = array2(0)

因此,

newarray(0) = 1
newarray(1) = 1

I cannot do this in VBA code.
Code snippet below, works if you comment out the last section where I try and assign array2(1) to arraynew.

Function test()
    Dim array1(0 To 20) As String
    Dim array2(0 To 5) As Variant
    Dim count As Integer

    For count = 0 To UBound(array1)
     array1(count) = count
    Next count

     now that array1 is filled i want to insert it into array2(1)
    array2(1) = array1

      test
    MsgBox (array2(1)(3))

     now i want to create a new string array and assign it to array2(1)
    Dim arraynew(0 To 20) As String
    arraynew = array2(1)
     this is what fails. 

End Function
问题回答

我们不能指定固定的阵列。 声明它是一种动态。

Dim arraynew() As String
arraynew = array2(1) 




相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签