Class Modules in VBA: Made Super Simple

Class Modules in VBA: Made Super Simple

Excel Macro Mastery

1 год назад

28,839 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@Excelmacromastery
@Excelmacromastery - 05.05.2023 18:16

Let me know of your struggles(or successes) with Class Modules in the comments below

Ответить
@rmdfra
@rmdfra - 07.09.2023 23:13

Hello. You said that by writing 'Set p = New clsPoint' it is possible to define in runtime how many objects are to be created in a for loop. What that loop would look like? Would an array of type clsPoint be needed? Your content is great, thanks.

Ответить
@crawdad4823
@crawdad4823 - 23.08.2023 23:15

Super-clear, thanks. I wish all internet tutorials were this well-organized!

Ответить
@josealvesferreira1683
@josealvesferreira1683 - 09.06.2023 14:43

Very good, thanks

Ответить
@iliesmeziani
@iliesmeziani - 15.05.2023 17:15

please mr can I contact you by email

Ответить
@BenjaminHouot
@BenjaminHouot - 11.05.2023 11:17

Very good presentation of class module

Ответить
@derekpowles7960
@derekpowles7960 - 09.05.2023 18:19

when you add the empty code below
Private Sub Class_Initialize()

End Sub

Private Sub Class_Terminate()

End Sub
On compile/run, the compiler removes this code. A simple blind comment in each procedure will keep the code.

Ответить
@faanmuller4569
@faanmuller4569 - 09.05.2023 12:19

Words fail to adequately describe Mr. Kelly's mastery. Simply unique.

Ответить
@derekpowles7960
@derekpowles7960 - 09.05.2023 10:56

In several places you say 'copy the code' when it should be 'move' or 'cut and paste' ,it confused me for a moment.

Ответить
@joeguirg
@joeguirg - 09.05.2023 04:40

Hey Paul, Thanks for the video. Very basic question around minute 3: the balance variable is being passed to two subs CreditAccount and DebitAccount. I don't understand how the value of the balance variable is maintained outside of the subs? In other words when the line Call CreditAccount(balance, 100) is executed, the variable balance is updated inside the sub and once the sub is exited then I thought the balance variable disappears. In order for the balance variable to be passed outside the sub, wouldn't this need to be a function instead of a sub? Can you help me clear up this confusion?

Ответить
@houstonvanhoy7767
@houstonvanhoy7767 - 08.05.2023 23:32

This video definitely is on a higher level. I'll have to view it several times. 🤔 But I will get there.☑

Ответить
@YvesAustin
@YvesAustin - 08.05.2023 06:12

Thank you for a very complete video. As an intermediate vba programmer, and having watched several tutorials over class modules (and you have a few!), I am even more confused now than before. I am still at the very beginning, meaning I really do not understand the value of class modules and what problems they are trying to solve. I would create a public function to calculate balance after debit and credit (which is what you also offer as an option). I am not sure I fully understand the concept. Is it simply to get a naming convention that pleases the eye? You mention three issues with a standard procedure. The first (messy input) is solved by initializing the class module sub which appears to be the same as passing the variable through a public function (or?), in the second you mention there are no connection between the variables and the subs, I am really confused about this statement. Last, if you allow a user to add code to your code, then the code is not protected and that is not good practice. I really really want to learn about these class modules. I am a still at a loss as to their true value. Pls accept my apologies. This is by no means a criticism to your work, which is fantastic, rather a statement from an average coder trying to get better. Thank you again.

Ответить
@jrcryo
@jrcryo - 07.05.2023 18:18

So if i understand well, it could be "easy" to create a class module that replicate the behaviour of the dictionary and the collection.

Ответить
@LilaBdrKarki-kb1mn
@LilaBdrKarki-kb1mn - 07.05.2023 02:03

You have given a good explanation of class in vba through this example. Thank you sir.

I need vba codes to replace an excel file stored in google drive with new version of the same file from my PC. Please guide me.

Ответить
@nadermounir8228
@nadermounir8228 - 07.05.2023 00:25

Thank you for your video. I think class modules make the code more complicated because it requires a lengthier code to write. In other words, creating private variable makes it difficult. Why can't we just use public subs ? What i don't get at all is why we have to to dim a variable as new collection for instance then set it to be equal a new collection. It is very hard to comprehend.

Ответить
@mathijs9365
@mathijs9365 - 06.05.2023 09:36

Sorry. Its not made super simple. I would write let-get instead of get-let

Ответить
@hanshallebeek8161
@hanshallebeek8161 - 06.05.2023 09:05

Inspiring as always. You really cleared the sky with this tutotrial, after 30+ years of VBA programming Classes still hold (now held) a secret for me and I just counldn't grasp the essentials.
Thanks Paul
"IT" Always crosses your path ...

Ответить
@free3690
@free3690 - 06.05.2023 02:17

I've used class modules before, but eventually switched back to regular modules due to the difficulties I faced during the debugging process. Whenever there was a problem with a function within a class module, the debugger would jump to the first line, making it quite challenging to pinpoint and resolve the issue.

Ответить
@Pedritox0953
@Pedritox0953 - 06.05.2023 02:14

Great video!

Ответить
@schymi841
@schymi841 - 05.05.2023 21:59

Unfortunately VBA is very limited when it comes to OOP concepts. That is why it's not used in big projects that require advanced class structure. For me the big disadvantage is that you cannot pass parameters to the constructor. This may seem like a small issue but it can actually cause huge problems with data integrity as you cannot force the user to properly initialize an object with some required attributes...

Ответить
@hammeedabdo.82
@hammeedabdo.82 - 05.05.2023 21:37

Thanks Mr. Paul, Please , we want to apply it through more professional applications, so that the understanding is better.

Ответить
@alterchannel2501
@alterchannel2501 - 05.05.2023 20:26

Fantastic information. Thank you. I have a question: how did you make the edges of your msgboxes rounded??? VBA gives me only sharp old style edges????

Ответить
@kmslogic
@kmslogic - 05.05.2023 20:12

Great introduction, love to see new videos from you.

Ответить
@m_marcamo
@m_marcamo - 05.05.2023 19:36

Tanks Paul.

My first class module will have the method:
.SendThanksToPaul
(and I will call it inside a loop 😄)

Ответить
@serdip
@serdip - 05.05.2023 19:25

Another advantage of using Property procedures is that we can include validation code. I think that in its current state, the clsAccount class accepts negative values in the Credit() and Debit() methods, which should not be acceptable, I believe. Additionally, it seems that the Property Let Debit() procedure should not complete the transaction if the specified amount exceeds m_Balance.

Next level design would be, in my opinion, to create an interface IAccount for example, that has the properties and methods common to all kinds of accounts. Then separate classes for checking, savings, personal, commercial account types could be created, each one implementing IAccount, whose methods are exposed to the calling code but the internal implementation details, of which such as interest calculations, overdraft fees etc. would be specific to each class.

Next next level (is that a thing? LOL) would be to include RaiseEvent WarnCustomer() in the class modules that could be invoked by, say Credit() when m_Balance exceeds $250,000 (the FDIC insurance limit, I think), or by Debit() when the remaining m_Balance falls below a threshold, which could be different depending on the type of account.


Thanks again for another very clear, concise, and eminently practical lecture on VBA development techniques.

Ответить
@serdip
@serdip - 05.05.2023 19:12

Another excellent lecture! This video came along just at the time when I wanted to review the fundamentals of class modules in VBA. Thank you!

Ответить
@johnbutler2750
@johnbutler2750 - 05.05.2023 18:22

Still struggling to fully “get” class’s but wrote one to help me manipulate txt files and it was very useful. Hoping I find another use.

Ответить