VBA Project - Pet Shelter (CLASSES and OBJECTS)

  Рет қаралды 5,636

Data Ben

Data Ben

Күн бұрын

Пікірлер: 32
@George-lp3qb
@George-lp3qb Жыл бұрын
it's the first time is see some1 in vba use classes with interfaces, Great Video
@noambrand
@noambrand 2 жыл бұрын
Finally got it. Great job! I have seen numerous class videos but I have to admit that only yours made sense to me.
@databen7194
@databen7194 2 жыл бұрын
Thanks Noam! I'm glad my video helped you
@danielbarton1694
@danielbarton1694 3 жыл бұрын
This is the best example and explanation of VBA classes I have found yet on what is a challenging concept to grasp for a beginner. Thanks for taking the time and effort to make this excellent video. I hope your channel grows to gain more subscriber which you deserve.
@databen7194
@databen7194 3 жыл бұрын
Thanks Daniel !
@AlbertKitamirike
@AlbertKitamirike 3 жыл бұрын
Great tutorial, I love it. I'm subscribing now.
Ай бұрын
Just found your channel. What an awsome video. Thanks, thanks, thanks!!
@reevesjim
@reevesjim 2 жыл бұрын
Liked and subscribed! Well done!
@TheSardOz
@TheSardOz 9 ай бұрын
Great video!
@jerrymilesmiles9313
@jerrymilesmiles9313 2 жыл бұрын
Outstanding! (please improve the audio). Best regards from Limón, Costa Rica!
@databen7194
@databen7194 2 жыл бұрын
Thanks, will do!
@sebastian1200
@sebastian1200 3 жыл бұрын
Very good explanation of how to use classes in vba. You wouldn’t share either the file, would you by any chance?
@databen7194
@databen7194 3 жыл бұрын
Link added to description :)
@sebastian1200
@sebastian1200 3 жыл бұрын
Thanks ever so much! Much obliged 😀
@conan7422
@conan7422 2 жыл бұрын
The collection "animals" only needs to be filled with the elements of the class specified in "choice" this simplifies the code and reduces the time and memory requirements.
@noviceprogrammer2011
@noviceprogrammer2011 3 жыл бұрын
Great video, just one question though: What happens if new data arrived that included a new type of animal (say owl) which not is listed already? Would you need to create a new class for it? If so, that doesn't seem to make sense.
@databen7194
@databen7194 3 жыл бұрын
Hi NP, yes you would need to create an Owl class. This tutorial assumes there are limited pet types and therefore only these classes. An alternative for dynamic data would be to create one Animal class and have the type as an attribute and assign all pets to that class. So all pets are Animals with Animal.type = cat/dog/owl etc.
@noviceprogrammer2011
@noviceprogrammer2011 3 жыл бұрын
@@databen7194 Thanks for clarifying.
@MoroseMoe
@MoroseMoe 3 жыл бұрын
I'm a relatively experienced programmer, and I've been googling around past couple of days to try and find a practical application for classes (custom objects), but couldn't find any. My own line of thinking is creating objects is ever only useful if you are coding a lot of similar stuff and you want to put it all in a neat little box with a ribbon on top... but even then justifying objects over just functions seems difficult to me. Is there something I'm missing? (I work as an internal dev for all things accounting at a medium large corp.)
@databen7194
@databen7194 3 жыл бұрын
Heya Moe, my background is similar and I too used mostly functions. I did occasionally use classes for when I wanted to convert some identifiable objects from spreadsheets into VBA objects and then do what I wanted with them in more detail (e.g. 'Employee'). I think I just touched on what is possible though and I'm open to the idea some people are doing or have done some very neat things with Classes and objects in VBA. I can understand getting to a point where you hit the wall of lack of features for classes in VBA and get frustrated. I do wonder if Python for Excel then comes into it's own at this point, but then that's not so practical in a corporate environment where you cannot just install python on all the machines.
@MoroseMoe
@MoroseMoe 3 жыл бұрын
@@databen7194 Thanks for reply. I've been mentioning Python as a thing that exists to my boss, but considering the mainstream direction of using "robots" *sigh* which are outsourced projects, I fear an end is nigh for in-house developers. We will all be degraded to code janitors.
@George-lp3qb
@George-lp3qb Жыл бұрын
Could you please cover working with customXMl part
@noviceprogrammer2011
@noviceprogrammer2011 3 жыл бұрын
I have been stepping through your code and can't figure out the following: Sub PrintCollection(coll As Collection, name As String) Debug.Print vbNewLine & "Printing " & name & ":" On Error Resume Next Dim item As Variant For Each item In coll Debug.Print item.PrintOut() Next item On Error GoTo 0 End Sub in particular, when you reach this line: Debug.Print item.PrintOut() it immediately jumps to the specific class, be it Cat, Dog, Fish or Hamster. How does the program know which class to go to?
@databen7194
@databen7194 2 жыл бұрын
Sure, so the key line here is that 'item' is declared as a Variant (basically 'anything') so when each item variant is looped over in the Collection it morphis into it's type with it, and luckily for us this includes class types! Cat, Dog or Fish. It could be any data type even a basic one for example String, Integer or Long would work in a Variant loop too, give it a try. :)
@bg31337
@bg31337 2 жыл бұрын
I guess he missed the use of the AnimalClassFactory: within the AnimalClassFactory Function the classType is extracted from the range. Then an object of this class is created and returned to the Sub CreateReport, where this object is added to the collection. This collection of objects will be then handed over to your Sub PrintCollection. And now that happens what Ben already said. Item is now one object in the collection. So when calling item.PrintOut this Sub is performed on the object. So if you look in Sub PrintOut there it is defined to Debug.Print TypeName(Me), where Me is the object, so TypeName(Me) gives you the class name
@1fredq1
@1fredq1 Жыл бұрын
I've always spelt Fishes with an 'es' not Fishs, so your formula for me would return Fishe ?
@efernandes67
@efernandes67 3 жыл бұрын
Ben, good class example and explanation! Can you share the file?
@databen7194
@databen7194 3 жыл бұрын
Link added to description :)
@robin810104
@robin810104 3 жыл бұрын
It doesn't seem as if you are using the implemented animal class. None of those methods are triggered and if you comment out the implement line then everything still works... No disrespect, just trying to understand
@thearchibaldtuttle
@thearchibaldtuttle 3 жыл бұрын
Important: VBA does not implement interfaces, it exposes the methods that need to be implemented. An interface is like a contract. When you implement an interface class you agree to include all the interface's public properties and methods in that class module.
@bg31337
@bg31337 2 жыл бұрын
There's a small bug: if (...) then aMaxStayTime = aStayTime -> if (...) then aMaxStayTime = animal.daysHoused
@bg31337
@bg31337 2 жыл бұрын
14:28 What would be the difference if I would've implemented daysHoused not as a Public Property but as a Public Function DaysHoused() As Integer DaysHoused = Now() - arrivalDate_ End Function And wouldn't the call be the same? aMaxStayTime = animal.DaysHoused() So, why does Property saves us many lines of code?
VBA Classes - The Definitive Guide
31:03
Data Ben
Рет қаралды 36 М.
Creating Classes in VBA
10:19
Jennifer Garth
Рет қаралды 19 М.
Hoodie gets wicked makeover! 😲
00:47
Justin Flom
Рет қаралды 68 МЛН
КОГДА К БАТЕ ПРИШЕЛ ДРУГ😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 7 МЛН
小路飞还不知道他把路飞给擦没有了 #路飞#海贼王
00:32
路飞与唐舞桐
Рет қаралды 73 МЛН
HELP!!!
00:46
Natan por Aí
Рет қаралды 50 МЛН
Excel VBA Dictionary Object, It's Great :)
13:54
Data Ben
Рет қаралды 6 М.
Working with Multiple Classes in VBA
1:11:47
Jennifer Garth
Рет қаралды 6 М.
Excel vba class module tutorial 2024
46:45
Sean Johnson
Рет қаралды 1 М.
Excel VBA: Using Class Modules with Collections (5/5)
13:37
Excel Macro Mastery
Рет қаралды 71 М.
Convert Existing VBA Code into a Class
25:55
Jennifer Garth
Рет қаралды 9 М.
VBA Classes
40:43
Siddharth Rout
Рет қаралды 9 М.
Better VBA 4 - Using Enums (Enumerations) in VBA
9:26
codekabinett.com/en
Рет қаралды 9 М.
Class Modules in VBA: Made Super Simple
17:43
Excel Macro Mastery
Рет қаралды 34 М.
Machine Learning for Everybody - Full Course
3:53:53
freeCodeCamp.org
Рет қаралды 7 МЛН
Hoodie gets wicked makeover! 😲
00:47
Justin Flom
Рет қаралды 68 МЛН