« December 2003 | Main

コントロール配列かどうかを判別

Private Sub Form_Load()
Dim ctl As Control
For Each ctl In Me.Controls
    If TypeName(Controls(ctl.Name)) = "Object" Then
        Debug.Print ctl.Name & "(" & CStr(ctl.Index) & ")"
    Else
        Debug.Print ctl.Name
    End If
Next ctl
End Sub

'別解
Function iscontrolarray(ctl As Control) As Boolean
On Error GoTo iscontrolarray_err
    Dim i As Long
    i = ctl.Index
    iscontrolarray = True
Exit Function
iscontrolarray_err:
If Err.Number = 343 Then
    iscontrolarray = False
End If
End Function

| | Comments (0) | TrackBack (0)

FileSystemObjectフォルダ再帰検索

Option Explicit

Private Sub Command1_Click()
Dim fs As Object, fld As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Set fld = fs.GetFolder("C:\TEMP")
DispFolders fld
Set fld = Nothing
Set fs = Nothing
End Sub

Private Sub DispFolders(oFolder As Object)
Dim oSubFolder As Object
Debug.Print oFolder.Path
For Each oSubFolder In oFolder.SubFolders
DispFolders oSubFolder
Next
End Sub

| | Comments (0) | TrackBack (0)

« December 2003 | Main