Created
March 16, 2012 05:29
-
-
Save nobrinskii/2048662 to your computer and use it in GitHub Desktop.
[vba/excel] 配列の新しいインデックス番号を返す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'------------------------------------------------------------------------------ | |
'配列の新しいインデックス番号を返す | |
'------------------------------------------------------------------------------ | |
'【引数】配列(あるいはEmpty値のVariant型) | |
'【戻り値】long型 | |
'【備考】引数が配列ではないく、かつ初期化済みの場合は-1を返す。 | |
Private Function SetNewIndex(varArray As Variant) As Long | |
Dim lngNewIndex As Long | |
Dim index As Long | |
If IsEmpty(varArray) Then | |
ReDim varArray(0) | |
lngNewIndex = 0 | |
ElseIf Not IsArray(varArray) Then | |
lngNewIndex = -1 | |
Else | |
index = UBound(varArray) | |
lngNewIndex = index + 1 | |
If lngNewIndex = 0 Then | |
ReDim varArray(0) | |
Else | |
ReDim Preserve varArray(lngNewIndex) | |
End If | |
End If | |
SetNewIndex = lngNewIndex | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment