VBA Project - Pet Shelter (CLASSES and OBJECTS)

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

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
Ай бұрын
Just found your channel. What an awsome video. Thanks, thanks, thanks!!
@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
@reevesjim
@reevesjim 2 жыл бұрын
Liked and subscribed! Well done!
@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.
@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.
@TheSardOz
@TheSardOz 10 ай бұрын
Great video!
@George-lp3qb
@George-lp3qb Жыл бұрын
Could you please cover working with customXMl part
@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 😀
@jerrymilesmiles9313
@jerrymilesmiles9313 2 жыл бұрын
Outstanding! (please improve the audio). Best regards from Limón, Costa Rica!
@databen7194
@databen7194 2 жыл бұрын
Thanks, will do!
@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.
@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
Рет қаралды 37 М.
Excel VBA Dictionary Object, It's Great :)
13:54
Data Ben
Рет қаралды 6 М.
One day.. 🙌
00:33
Celine Dept
Рет қаралды 64 МЛН
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 135 МЛН
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 40 МЛН
小路飞和小丑也太帅了#家庭#搞笑 #funny #小丑 #cosplay
00:13
家庭搞笑日记
Рет қаралды 10 МЛН
Object Orientation in Access / VBA - Should we use it?
19:39
codekabinett.com/en
Рет қаралды 4,1 М.
Creating Classes in VBA
10:19
Jennifer Garth
Рет қаралды 19 М.
Convert Existing VBA Code into a Class
25:55
Jennifer Garth
Рет қаралды 10 М.
Exel VBA module de classe découverte
24:37
Tuto De Rien
Рет қаралды 16 М.
How to Use Class Interfaces in Excel VBA
20:16
Excel Macro Mastery
Рет қаралды 82 М.
Excel vba class module tutorial 2024
46:45
Sean Johnson
Рет қаралды 1,2 М.
Working with Multiple Classes in VBA
1:11:47
Jennifer Garth
Рет қаралды 7 М.
Animations in Excel using VBA
10:45
Data Ben
Рет қаралды 12 М.
Watch these 28 minutes if you want to become an Advanced VBA user...
29:01
Excel Macro Mastery
Рет қаралды 56 М.
Reduce VBA Errors by 90% (with this little-known Method)
16:59
Excel Macro Mastery
Рет қаралды 59 М.
One day.. 🙌
00:33
Celine Dept
Рет қаралды 64 МЛН