전체 배열을 지우는 방법은 무엇입니까?
다음과 같은 어레이가 있습니다.
Dim aFirstArray() As Variant
전체 배열을 지우려면 어떻게 해야 합니까?수집품은 어떻습니까?
다음 중 하나를 사용할 수 있습니다.Erase
또는ReDim
배열을 지우기 위한 문.각 예는 MSDN 설명서에 나와 있습니다.예:
Dim threeDimArray(9, 9, 9), twoDimArray(9, 9) As Integer
Erase threeDimArray, twoDimArray
ReDim threeDimArray(4, 4, 9)
컬렉션을 제거하려면 해당 항목을 반복한 후Remove
방법:
For i = 1 to MyCollection.Count
MyCollection.Remove 1 ' Remove first item
Next i
VBA에서 동적 배열을 삭제하려면 다음 지침을 사용합니다.Erase
.
예:
Dim ArrayDin() As Integer
ReDim ArrayDin(10) 'Dynamic allocation
Erase ArrayDin 'Erasing the Array
이것이 도움이 되길 바랍니다!
이는 다음과 같이 간단합니다.
Erase aFirstArray
나에게 더 나은 사용법 찾기:저는 보통 변형이 비어 있는지 테스트하는데, 위의 방법들은 모두 테스트에서 실패합니다.변형을 실제로 빈 상태로 설정할 수 있습니다.
Dim aTable As Variant
If IsEmpty(aTable) Then
'This is true
End If
ReDim aTable(2)
If IsEmpty(aTable) Then
'This is False
End If
ReDim aTable(2)
aTable = Empty
If IsEmpty(aTable) Then
'This is true
End If
ReDim aTable(2)
Erase aTable
If IsEmpty(aTable) Then
'This is False
End If
이런 식으로 나는 내가 원하는 행동을 얻습니다.
[your Array name] = Empty
그러면 배열에 내용이 없고 다시 채울 수 있습니다.
ReDim aFirstArray(0)
이렇게 하면 배열 크기가 0으로 조정되고 모든 데이터가 지워집니다.
저는 전체 배열을 지우는 데 딤/레딤이 실패한 경우에 빠졌습니다.
2개의 모듈 전체 배열, 사용자 양식 내부의 개인 배열,
한 어레이는 동적이며 클래스 모듈을 사용하고 다른 어레이는 고정되어 있으며 특수 유형을 사용합니다.
Option Explicit
Private Type Perso_Type
Nom As String
PV As Single 'Long 'max 1
Mana As Single 'Long
Classe1 As String
XP1 As Single
Classe2 As String
XP2 As Single
Classe3 As String
XP3 As Single
Classe4 As String
XP4 As Single
Buff(1 To 10) As IPicture 'Disp
BuffType(1 To 10) As String
Dances(1 To 10) As IPicture 'Disp
DancesType(1 To 10) As String
End Type
Private Data_Perso(1 To 9, 1 To 8) As Perso_Type
Dim ImgArray() As New ClsImage 'ClsImage is a Class module
사용자 양식 내부와 외부에서 이러한 어레이(및 관련 런타임 생성 컨트롤)를 삭제하기 위해 공용으로 선언된 하위 항목이 있습니다.
Public Sub EraseControlsCreatedAtRunTime()
Dim i As Long
On Error Resume Next
With Me.Controls 'removing all on run-time created controls of the Userform :
For i = .Count - 1 To 0 Step -1
.Remove i
Next i
End With
Err.Clear: On Error GoTo 0
Erase ImgArray, Data_Perso
'ReDim ImgArray() As ClsImage ' i tried this, no error but wouldn't work correctly
'ReDim Data_Perso(1 To 9, 1 To 8) As Perso_Type 'without the erase not working, with erase this line is not needed.
End Sub
참고: 이 마지막 서브는 외부(다른 폼 및 클래스 모듈)에서 처음 호출되었습니다.Call FormName.SubName
하지만 그것을 대체해야 했습니다.Application.Run FormName.SubName
더 적은 오류, 왜 그런지 묻지 마...
사용만Redim
진술
Dim aFirstArray() As Variant
Redim aFirstArray(nRows,nColumns)
언급URL : https://stackoverflow.com/questions/3018510/how-to-clear-the-entire-array
'programing' 카테고리의 다른 글
장식품은 언제 사용해야 합니까? (0) | 2023.04.29 |
---|---|
특정 단어에 대한 Git 커밋 디프 또는 내용을 grep하는 방법 (0) | 2023.04.29 |
셸 스크립팅에서 문자열의 처음 두 문자를 추출하려면 어떻게 해야 합니까? (0) | 2023.04.29 |
한 디브를 다른 디브 위에 덧씌우는 방법 (0) | 2023.04.29 |
셸 스크립트에서 백틱 대신 $()를 사용하면 어떤 이점이 있습니까? (0) | 2023.04.29 |