2012年2月4日土曜日

vbaのarrayのshiftメッソドを作ってみた

vbaのarrayのshiftメッソドを作ってみた
Function shift(ByVal arr As Variant) As Variant
    Dim u As Long
    u = UBound(arr)
    Dim l As Long
    If u < 1 Then
        shift = Array()
        Exit Function
    End If
    Dim v() As Variant
    For l = LBound(arr) To u - 1
        ReDim Preserve v(l)
        v(l) = arr(l + 1)
    Next
    shift = v
End Function

'検証
Sub test()
    Dim n As Variant
    n = Array("a", "b", "c")
    n = shift(n) 'n = array("b", "c")
End Sub

0 件のコメント:

コメントを投稿