LoginSignup
0
3

More than 5 years have passed since last update.

VBA_配列からNothingを除外

Posted at

1.概要

オブジェクトの配列においてNothingであるものを除外する関数
※自己クラスの配列において、不要なものを予めNothingにし、
 後にまとめて除外したいことがあったため作成

2.ソースコード

'引数の配列からNothingを除外する
Public Function DeleteNothingObj(arg_array As Variant)

    Dim i As Long 'カウンタ
    Dim buf_ As New Collection '消さないオブジェクトのバッファ

    '引数の配列からNothingでないオブジェクトをバッファへ格納
    For i = 0 To UBound(arg_array)
        If Not arg_array(i) Is Nothing Then
            Call buf_.Add(arg_array(i))
        End If
    Next

    '引数の配列をバッファのオブジェクト数にRedim
    ReDim arg_array(buf_.Count - 1)

    '引数に再格納
    For i = 0 To UBound(arg_array)
        Set arg_array(i) = buf_(i + 1)
    Next

End Function


3.出力結果

~略~

0
3
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3