~~ CLASS (SINIF) MODULLER ~~
Class moduller hakkında herşeyi bu sayfada bulabilirsiniz...
Private m_Name As String
Public Property Get Name() As String
Name = m_Name
End Property
Public Property Let Name(ByVal deg As String)
m_Name = deg
End Property
Private m_ObjProp As Object
Public Property Get ObjProp() As Object
Set ObjProp = m_ObjProp
End Property
Public Property Set Name(ByVal deg As Object)
Set m_ObjProp = deg
End Property
Private m_Name As String
Public Property Get ObjProp() As String
Name = m_Name
End Property
Friend Property Let SetToVariable(ByVal deg As String)
m_Name = deg
End Property
Private m_ObjProp As Object
Public Property Get ObjProp() As Object
Set ObjProp = m_ObjProp
End Property
Friend Property Set SetToVariable(ByVal deg As Object)
Set m_ObjProp = deg
End Property
Private m_Name As Object
Public Property Let Name(ByVal deg As String) As String
m_Name = deg
End Property
Friend Property Get ReadFromVariable() As String
ReadFromVariable = m_Name
End Property
Private m_ObjProp As Object
Public Property Set Name(ByVal deg As Object) As Object
Set m_ObjProp = deg
End Property
Friend Property Get ReadFromVariable() As Object
Set ReadFromVariable = m_ObjProp
End Property
Private m_Font As clsFont
Public Property Get Font() As clsFont
Set Font = m_Font
End Property
Public Property Set Font(deg As clsFont)
Set m_Font = deg
End Property
Private Sub Class_Initialize()
Set m_Font = New clsFont
End Sub
Private m_Name As String
Public Property Get Name() As String
Name = m_Name
End Property
Public Property Let Name(deg As String)
m_Name = deg
End Property
Sub Test()
Dim txt As New clsTextBox1
txt.Font.Name = "Arial"
MsgBox txt.Font.Name
End Sub
Public Event deneme1()
Public Event deneme2(ByVal arg As String)
Public Event deneme3(ByVal arg1 As Long, ByVal arg2 As String, … )
' Olaylar...
Public Event ListFiles(ByVal FileName As String)
Public Event ErrorMessage(ByVal ErrNumber As Long, ByVal ErrMsg As String)
Public Event BeforeAction(ByVal Msg As String)
Public Event AfterAction(ByVal Msg As String)
Public Sub GetFiles(FolderPath As String, Optional FilePattern As String = "*.*")
Dim d As String, s As String
s = IIf(Right(FolderPath, 1) = "\", FolderPath, FolderPath & "\")
d = Dir(s & FilePattern, vbArchive + vbHidden + vbNormal + vbReadOnly + vbSystem)
RaiseEvent BeforeAction(FolderPath & " dizininde dosya araması başladı.")
Do While d <> ""
If d = "explorer.exe" Then ' Herhangi bir denetimle hata döndür :
GoTo ErrHandler
Else
RaiseEvent ListFiles(d) ' Dosya ismini "olay" ımıza gönder
End If
d = Dir
Loop
RaiseEvent AfterAction(FolderPath & " dizininde dosya araması tamamlandı.")
Exit Sub
ErrHandler:
' Form modulundeki olaya gönderilecekse :
' 1-)
RaiseEvent ErrorMessage(123456, d & " dosyası içeriyor !") ' veya
' 2-)
' Gerçek bir hata durumunda
'RaiseEvent ErrorMessage(Err.Number, Err.Description)
'***************************************************************
' Form modulundeki "olay" ımıza göndermeden normal bir error penceresi çıkması için :
' 1-)
'Err.Raise 123456, , "Özel Açıklama"
' 2-)
'Err.Raise Err.Number, , Err.Description
End Sub
Private WithEvents fls As clsFiles
Private Sub CommandButton1_Click()
Set fls = New clsFiles
fls.GetFiles "c:\windows"
End Sub
Private Sub fls_AfterAction(ByVal Msg As String)
' Sınıf içinde Dir işlemi bittikten sonra buraya mesaj göndermiştik.
Debug.Print Msg
End Sub
Private Sub fls_BeforeAction(ByVal Msg As String)
' Sınıf içinde Dir başlamadan önce buraya mesaj göndermiştik.
Debug.Print Msg
End Sub
Private Sub fls_ErrorMessage(ByVal ErrNumber As Long, ByVal ErrMsg As String)
' Sınıf içindeki üyenin çalışması sırasında hata olursa veya
' başka bir denetimle burada yakalanacak.
Debug.Print "Hata No="; ErrNumber; "; Hata İletisi="; ErrMsg
End Sub
Private Sub fls_ListFiles(ByVal FileName As String)
' Sınıf içindeki üye düzgün çalışırken verileri burada yakalanacak.
ListBox1.AddItem FileName
End Sub
' Interface Sınıfı
Public Sub DenemeSub()
' Boş kalacak.
End Sub
Public Function DenemeFunction()
' Boş kalacak.
End Function
Public Property Get DenemeProperty() As Variant
' Boş kalacak.
End Property
Public Property Let DenemeProperty(ByVal vNewValue As Variant)
' Boş kalacak.
End Property
' Esas sınıfımız.
Implements IDeneme
Private Function IDeneme_DenemeFunction() As Variant
' Buraya kod yazılacak.
End Function
Private Property Let IDeneme_DenemeProperty(ByVal RHS As Variant)
' Buraya kod yazılacak.
End Property
Private Property Get IDeneme_DenemeProperty() As Variant
' Buraya kod yazılacak.
End Property
Private Sub IDeneme_DenemeSub()
' Buraya kod yazılacak.
End Sub
' Buradan da esas sınıfımızı çağıracağız.
Dim cls As IDeneme
Set cls = New Class1 ' Yanlışlık yok; kullanım bu şekilde.
' Aşağıdaki gibi çağıracağız.
cls.DenemeFunction
cls.DenemeProperty = 10
cls.DenemeSub
End Sub
Implements Scripting.Dictionary
Private m_objDic As Scripting.Dictionary
Private Sub Class_Initialize()
Set m_objDic = New Scripting.Dictionary
End Sub
Private Sub Class_Terminate()
Set m_objDic = Nothing
End Sub
Private Sub Dictionary_Add(Key As Variant, Item As Variant)
m_objDic.Add Key, Item
End Sub
Private Property Let Dictionary_CompareMode(ByVal RHS As Scripting.CompareMethod)
m_objDic.CompareMode = RHS
End Property
Private Property Get Dictionary_CompareMode() As Scripting.CompareMethod
Dictionary_CompareMode = m_objDic.CompareMode
End Property
Private Property Get Dictionary_Count() As Long
Dictionary_Count = m_objDic.Count
End Property
Private Function Dictionary_Exists(Key As Variant) As Boolean
Dictionary_Exists = m_objDic.Exists(Key)
End Function
Private Property Get Dictionary_HashVal(Key As Variant) As Variant
' ???
End Property
Private Property Let Dictionary_Item(Key As Variant, RHS As Variant)
m_objDic.Item(Key) = RHS
End Property
Private Property Get Dictionary_Item(Key As Variant) As Variant
Dictionary_Item = m_objDic.Item(Key)
End Property
Private Property Set Dictionary_Item(Key As Variant, RHS As Variant)
Set Dictionary_Item(Key) = RHS
End Property
Private Function Dictionary_Items() As Variant
Set Dictionary_Items = m_objDic.Items
End Function
Private Property Let Dictionary_Key(Key As Variant, RHS As Variant)
Dictionary_Key(Key) = RHS
End Property
Private Function Dictionary_Keys() As Variant
Set Dictionary_Keys = m_objDic.Keys
End Function
Private Sub Dictionary_Remove(Key As Variant)
m_objDic.Remove Key
End Sub
Private Sub Dictionary_RemoveAll()
m_objDic.RemoveAll
End Sub
Sub Test()
' Kısaca buradaki Implements :
' cls isimli Scripting.Dictionary nin,
' New Instance yapılmış hali CustomDictionary dir.
' Diğer bir deyişle, CustomDictionary ile
' New Scripting.Dictionary yapıyoruz.
Dim cls As Scripting.Dictionary
Set cls = New CustomDictionary ' "cls", bir "New Scripting.Dictionary" dir.
cls.Add "ad", "Zeki"
cls.Add "soyad", "Gürsoy"
Debug.Print "Eleman Sayısı="; cls.Count; "; Ad="; cls("ad"); "; SoyAd="; cls("soyad")
End Sub
Public Function GetRange(rng As Range) As clsCells
Dim vCells As New clsCells, r As Range
For Each r In rng
vCells.AddToCol r.Value, r.Address(0, 0)
Next
Set GetRange = vCells
End Function
Private col As Collection
Public Property Get Count() As Long
Count = col.Count
End Property
Public Property Get Item(Key As Variant) As clsCell
Set Item = col.Item(Key)
End Property
Public Property Get Items() As Collection
' For-Each döngüsü için kullanılır.
Set Items = col
End Property
Friend Sub AddToCol(vValue As Variant, vAddress As String)
Dim c As New clsCell
c.SetToAddress = vAddress
c.Value = vValue
col.Add c, CStr(vAddress)
End Sub
Private Sub Class_Initialize()
Set col = New Collection
End Sub
Private Sub Class_Terminate()
Set col = Nothing
End Sub
Private m_Value As Variant
Private m_Adress As String
Public Property Get Value() As Variant
Value = m_Value
End Property
Public Property Let Value(ByVal vNewValue As Variant)
m_Value = vNewValue
End Property
Public Property Get Address() As String
' Adres özelliği Read-Only dir.
Address = m_Adress
End Property
Friend Property Let SetToAddress(ByVal vNewValue As String)
' Read-Only olan Address özelliğinde dış dünyanın veri alabilmesi
' için Friend olan SetToAddress ile sınıflar arasında haberleşme sağlıyoruz.
m_Adress = vNewValue
End Property
Sub Test()
Dim csh As New clsSheet, cs As New clsCells
Set cs = csh.GetRange(Range("a1:a10"))
For i = 1 To cs.Count
Debug.Print "Adres="; cs.Item(i).Address; "; Value="; cs.Item(i).Value
Next
' veya
Dim r As clsCell
For Each r In cs.Items
Debug.Print "Adres="; r.Address; "; Value="; r.Value
Next
' veya
Debug.Print cs.Item("a5").Value
End Sub
Private WithEvents chkBox As MSForms.CheckBox
Public Event Click(obj As MSForms.CheckBox)
Private col As Collection
Private Sub chkBox_Click()
RaiseEvent Click(chkBox)
End Sub
Friend Sub Add(frm As Object, objChkBox As MSForms.CheckBox)
Set chkBox = objChkBox
col.Add frm ' UserForm1
End Sub
Private Sub Class_Initialize()
Set col = New Collection
End Sub
Private Sub Class_Terminate()
Set col = Nothing
End Sub
Public WithEvents cls As clsCheckBoxes
Private Sub cls_Click(obj As MSForms.CheckBox)
MsgBox "Benim Adım : " & obj.Name
End Sub
Private Sub UserForm_Activate()
Dim c As MSForms.Control, NewForm As UserForm1
For Each c In Me.Controls
If TypeOf c Is MSForms.CheckBox Then
' cls değişkenine atamak üzere yeni UF ata. Bu nedenle form ekrana yüklendiği
' andaki olaya (Activate) kod yazıyoruz.
' New UserForm1 ile atama yaparken Initialize olayı altındaki kod çalışır; DİKKAT!!!
Set NewForm = New UserForm1
' Yeni UF nin cls değişkenine yeni Class instance ata.
Set NewForm.cls = New clsCheckBoxes
NewForm.cls.Add NewForm, c ' Yeni formu ve kotrolü koleksiyona ata.
End If
Next
End Sub
Public WithEvents chkBox As MSForms.CheckBox
Private col As Collection
Public Sub Add(CheckBoxObject As MSForms.CheckBox)
Dim chkClass As New clsCheckBoxes
Set chkClass.chkBox = CheckBoxObject
col.Add chkClass
End Sub
Private Sub chkBox_Click()
MsgBox "Benim Adım : " & chkBox.Name
End Sub
Private Sub Class_Initialize()
Set col = New Collection
End Sub
Private Sub Class_Terminate()
Set col = Nothing
End Sub
Private cls As clsCheckBoxes
Private Sub UserForm_Initialize()
Dim c As MSForms.Control
Set cls = New clsCheckBoxes
For Each c In Me.Controls
If TypeOf c Is MSForms.CheckBox Then
cls.Add c
End If
Next
End Sub
Private Sub UserForm_Terminate()
Set cls = Nothing
End Sub
Public WithEvents chkBox As MSForms.CheckBox
Private Sub chkBox_Click()
MsgBox "Benim Adım : " & chkBox.Name
End Sub
Private col As Collection
Private Sub UserForm_Initialize()
Dim ctrl As MSForms.Control
Dim cls As clsCheckBoxes
Set col = New Collection
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.CheckBox Then
Set cls = New clsCheckBoxes
Set cls.chkBox = ctrl
col.Add cls
End If
Next
End Sub
Private Sub UserForm_Terminate()
Set col = Nothing
End Sub
Public WithEvents chkBox As MSForms.CheckBox
Private Sub chkBox_Click()
MsgBox "Benim Adım : " & chkBox.Name
End Sub
Private m() As clsCheckBoxes
Private Sub UserForm_Initialize()
Dim ctrl As MSForms.Control
Dim cls As clsCheckBoxes, i As Long
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.CheckBox Then
Set cls = New clsCheckBoxes
Set cls.chkBox = ctrl
i = i + 1
ReDim Preserve m(i)
Set m(i) = cls
End If
Next
End Sub
Public Property Get Item(Key As Variant) As clsCell
Attribute Item.VB_UserMemId = 0
Attribute Item.VB_Description = "Bir clsCell nesnesi döndürür"
Set Item = col.Item(Key)
End Property
Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_Description = "Bu özellik For-Each döngüsü imkanı verir."
Attribute NewEnum.VB_UserMemId = -4
Set NewEnum = col.[_NewEnum]
End Function
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "FileSystemObject"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Description = "Scripting Kütüphanesi\nFileSystemObject Sınıfı"
Dim cls As VBAProject.Class1
Set cls = New VBAProject.Class1 ' Kabul edilmez
' veya
Dim cls As New VBAProject.Class1 ' Kabul edilmez
' veya
Set cls = CreateObject("VBAProject.Class1") ' Kabul edilmez
Public Function New_Class1() As Class1
Set New_Class1 = New Class1
End Function
Public Function New_Class2() As Class2
Set New_Class2 = New Class2
End Function
Dim cls As VBAProject.Class1
Set cls = New_Class1
cls.ProsedurAdi
Sub Test1()
Dim fso As FileSystemObject
Dim fold As Folder, folds As Folders, fil As File, fils As Files
Set fso = New_FileSystemObject
Set fold = fso.GetFolder("c:\windows")
Debug.Print "[GetFolder Özellikleri]"
Debug.Print _
"IsRootFolder="; fold.IsRootFolder; "; Name="; fold.Name; _
"; ParentFolder="; fold.ParentFolder; "; Path="; fold.Path
Set folds = fold.SubFolders
Set fils = fold.Files
Debug.Print ""
Debug.Print "[SubFolders Koleksiyonu]"
For Each fold In folds
Debug.Print _
"IsRootFolder="; fold.IsRootFolder; "; Name="; fold.Name; _
"; ParentFolder="; fold.ParentFolder; "; Path="; fold.Path
Next
Debug.Print ""
Debug.Print "[Files Koleksiyonu]"
For Each fil In fils
Debug.Print "Name="; fil.Name; "; Path="; fil.Path; "; Size="; fil.Size; "Bayt"
Next
End Sub
Sub Test2()
Dim fso As FileSystemObject, fold As Folder
Set fso = New_FileSystemObject
Set fold = fso.GetFolder("c:\").SubFolders.Add("Test")
Debug.Print fold.Path & " klasörü oluşturuldu. "
RmDir fold.Path
Debug.Print fold.Path & " klasörü silindi."
End Sub
Sub Test3()
Dim fs As ZGRSY.FileSearch
Set fs = ZGRSY.New_FileSearch
With fs ' veya With ZGRSY.New_FileSearch
.Filename = "*.xlsm"
.LookIn = "c:\"
.SearchSubFolders = False
.Execute
For i = 1 To .FoundFiles.Count
Debug.Print .FoundFiles(i)
Next
End With
End Sub
#If Win64 Then
' Win64=true, Win32=true, Win16= false dir.
#ElseIf Win32 Then
' Win32=true, Win16=false dir.
#Else
' Win16=true dur.
#End If
#If VBA7 Then ' Office 2010 derleyicisi ise
#If Win64 Then ' 64 bit Office ise
#Else
#End If
#Else
#End If
#If VBA7 Then ' Office 2010 derleyicisi ise
#If Win64 Then ' 64 bit Office ise
#End If
#Else
#End If
#If VBA7 And Win64 Then ' Office 2010 derleyicisi ve 64 bit Office ise
#Else
#End If