ぼくのかんがえたさいきょうのくらすもじゅうる~VBAでOOP~

そこそこできたので販売します
そのうちサンプル書くかもしれないです
拡張もするかもしれません


サンプル

'' 下記のツイート(ポスト)にいくつか載せていくことにします

<標準モジュール>TJ

Option Explicit

'''
''' 拡張クラスを使うためのモジュール
'''

Private p_ArrayEx As ArrayEx

'' // As ArrayEx ----------------------------------------

Private Sub ToElem(arr As Variant)
    Dim e As Variant
    For Each e In arr
        Select Case True
            Case IsArray(e): ToElem e
            Case Else:       p_ArrayEx.Add e
        End Select
    Next
End Sub

Property Get NewArrayEx(ParamArray a_args() As Variant) As ArrayEx
    Dim args As Variant: args = a_args
    Set p_ArrayEx = New ArrayEx
    Call ToElem(args)
    Set NewArrayEx = p_ArrayEx
End Property

Property Get SequenceEx(StartNum As Long, _
                       EndNum As Long, _
              Optional StepNum As Long = 1, _
              Optional DefaultVal As Variant = Empty) As ArrayEx
    
    Set SequenceEx = New ArrayEx
    Dim i As Long
    For i = StartNum To EndNum Step StepNum
        SequenceEx.Add IIf(IsEmpty(DefaultVal), i, DefaultVal)
    Next
End Property

'' // As DateTimeEx ----------------------------------------

Property Get NewDateTimeEx(Optional arg As Date = 0) As DateTimeEx
    Set NewDateTimeEx = New DateTimeEx
    Let NewDateTimeEx.Value = IIf(arg = 0, Now(), arg)
End Property

Property Get DateSerialEx(Year As Integer, Month As Integer, Day As Integer) As DateTimeEx
    Set DateSerialEx = New DateTimeEx
    Let DateSerialEx.Value = VBA.DateSerial(Year, Month, Day)
End Property

Property Get TimeSerialEx(Hour As Integer, Minute As Integer, Second As Integer) As DateTimeEx
    Set TimeSerialEx = New DateTimeEx
    Let TimeSerialEx.Value = VBA.TimeSerial(Hour, Minute, Second)
End Property

Property Get DateTimeSerialEx(Year As Integer, Month As Integer, Day As Integer, _
                             Hour As Integer, Minute As Integer, Second As Integer) As DateTimeEx
    
    Set DateTimeSerialEx = New DateTimeEx
    Let DateTimeSerialEx.Value = VBA.DateSerial(Year, Month, Day) _
                                  + VBA.TimeSerial(Hour, Minute, Second)
End Property

'' // As DictEx ----------------------------------------

Property Get NewDictEx(Optional dict As Object = Nothing) As DictEx
    Set NewDictEx = New DictEx
    Set NewDictEx.Value = dict
End Property

'' // As NumberEx ----------------------------------------

Property Get NewNumberEx(Optional arg As Double = 0) As NumberEx
    Set NewNumberEx = New NumberEx
    Let NewNumberEx.Value = arg
End Property

Property Get RandomEx(Optional MinValue As Long = 0, _
                     Optional MaxValue As Long = 0) As NumberEx
    Randomize
    Dim n As Double: n = VBA.Rnd
    If MinValue <> 0 Or MaxValue <> 0 Then
        n = Int((MaxValue - MinValue + 1) * n + MinValue)
    End If
    Set RandomEx = New NumberEx
    Let RandomEx.Value = n
End Property

Property Get PiEx(Optional arg As Double = 1) As NumberEx
    Set PiEx = New NumberEx
    Let PiEx.Value = arg * Atn(1) * 4
End Property

Property Get ExpEx(Optional arg As Double = 1) As NumberEx
    Set ExpEx = New NumberEx
    Let ExpEx.Value = VBA.Exp(arg)
End Property

'' // As RecordsetEx ----------------------------------------

Property Get NewRecordsetEx(Optional rs As Object = Nothing) As RecordsetEx
    Set NewRecordsetEx = New RecordsetEx
    Set NewRecordsetEx.Value = rs
End Property

'' // As StringEx ----------------------------------------

Property Get NewStringEx(Optional arg As String = "") As StringEx
    Set NewStringEx = New StringEx
    Let NewStringEx.Value = arg
End Property

<クラスモジュール>ArrayEx

ここから先は

24,009字

¥ 1,000

この記事が気に入ったらサポートをしてみませんか?