Sorry for being a duplicate question with My Wisdom Bag (I'm looking for a quick answer)
I'm rewriting the skeleton source to ask questions to improve the existing scheduler
The development language is EXCEL vba
The item class is defined and a function to list items from the worksheet is
Trying to define
(Cls item) Public id as int Public todo as string
Sub Main Dim Items as collection Set items = new cls items Dim tbl as object Set Tbl = sheet1.usedrange Items.WsRead tbl Omitted
I want to read the whole sheet and generate an items collection
Currently, functions outside the class are defined, and the loop is turned item by item.
I want to put it in a class method, but the output is not a single object,
I'd like to include multiple lists, but I'm not sure about this.
Public function WsRead (ByVal tbl as object) as collection Omitted
Answer # 1
The question code example is simple, but you want to use this as a template to implement more complex processing using classes?
Cls itemis 1 data, so it is not possible to list it.
If you want to implement a method that loads a list into a class,
You need a separate class that lists
Cls items(such as collection or array).
I have an image of the code.
'Class module Clss item Public id as int Public todo as string
'Class module Clls item list Option Explicit Dim Items As Collection Private Sub Class_Initialize () Set Items = New Collection End Sub Private Sub Class_Terminate () 'Drop the Clss items in the Collection in a loop End Sub Public Sub WsRead (ByVal tbl As Object) Dim item As Clss item Dim i As Long For i = 1 To tbl.rows.count Set item = New Clss item Item.id = ***** Item.todo = ***** Items.Add item Next End Sub
That means you need an item class and an item list class.
Speaking of Excel objects,
You can imagine the relationship between the Worksheet object and the WorkSheets object.
Answer # 2
Perhaps you have an image of an array?
If the class properties are only id and todo, there is almost no merit in defining the class, and it is better to define it in an array.
There are many merits to define in a class, but the biggest merit is that VBA is effective when items to be handled are complicated, such as data and functions can be grouped together, property can be set, value can be set to other properties, etc. I think.
However, variables declared in a class can also be handled like arrays.
Dim a (100) As Class_A For i = 0 To 100 Set a (i) = New Class_A Next i
VBA classes are not all-round, but the way to deal with them is often in power.
However, forcibly created files will only be difficult to maintain later.
How about using worksheets well and using each function well?
Answer # 3
Dictionary item defined in class module
Isn't it possible to store it?
Set items = New Cls items.id = 1 items.todo = "Tomorrow" Dim myDic As Object Set myDic = CreateObject ("Scripting.Dictionary") myDic.Add "Project1", items
- vba - i want to pass class data to the user form
- Class definition and usage tutorial in python
- PHP redis counter class definition and usage examples
- PHP abstract abstract class definition and usage examples
- PHP log LOG class definition and usage example
- JS dictionary Dictionary class definition and usage examples
- PHP DB database connection class definition and usage example
- PHP whois query class definition and usage example
- Inheritance definition and usage analysis of js class
- js definition class method example [ES5 and ES6]
- Java local inner class and anonymous inner class definition and usage example analysis
- Java abstract class and abstract method definition and usage examples
- vba - i want to use a class module to link checkboxes of any number of automatically generated ole objects
- vba - filesystemobject definition
- Python definition class self usage instance analysis
- python - about operation definition of class variables and non-class variables
- php - in the definition of the class, notice: undefined variable: ingredients is displayed
- Django admin management tool TabularInline class usage detailed explanation
- vba - i want to create a member to use as an argument in my own class
- python 3x - typeerror: 'method' object is not subscriptable
- python - you may need to restart the kernel to use updated packages error
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - emulator: dsound: could not initialize about the error message directsoundcapture
- android studio - unresolved reference comes out in kotlin
- mysql startup failed [error] innodb: the innodb_system data file 'ibdata1' must be writable
- django - oserror: [winerror 123] the file name, directory name, or volume label syntax is incorrect : '<frozen importlib_boot
- python - importerror: cannot import name md5 error cannot be resolved