You are correct. By default Enums will start with 0 for the first enum item. - I usually define explicit values for the enum items, that's why I made that mistake. Thank you very much for pointing this out!
For decades of years I did not understand the sense of Enums, although I to read books and Online Helps in Access. After watching this great Video tutorial all things are clear!! Thank you very much.
always good to be explicit :) another good video on giving thought to code. I can see where enumerations are a great benefit when used as type for parameters ... nice to be prompted with choices. I've put comments in the code specifying values for parameters and what they mean, never giving a though to intellisense ... but as you demonstrate, I can see where enums could be extremely useful to supply choices when coding. I've read code with enums, and understand the logic -- just never saw any benefit till you show it so explicitly. I have an application I can use them in right now, and just might! Thanks for the idea and clear demonstration, Phillip
Very good video, thank you. I have a question please, XlLineStyle is enum in excel VBA. Is XlLineStyle part of any class in VBA? where is located compare to other VBA object hierarchy. Thanks again.
Some things to add for Enum 1) I think enum values are of data type Long which is worth noting if values require conversion to say Integer etc. 2) Can also have an enumeration of the Enum values by adding at the end [_First] and [_Last] eg Public Enum CustomerSegment NormalCustomer = 1 VIPCustomer = 2 [_First] = NormalCustomer [_Last] = VIPCustomer End Enum Sub TestEnum Dim customerType As CustomerSegment For customerType = CustomerSegment.[_First] To CustomerSegment.[_Last] SendCustomerReports(customerType) Next End Sub
Thank you for 1), that's worth mentioning. - Not sure about 2), though. It's rather rare to iterate over all values of an enum. For .. Next works here by converting the first and last value to a long. That's not going to work when the enum values are NOT a gap-less sequence of integers.
@@codekabinettcomen Thanks for point 2) It only works for if the values declared within the Enum are sequential www.cpearson.com/excel/Enums.aspx. That makes it limiting for validation of input of enum values. Enjoying going through your videos some really interesting advanced topics. Ps Was hoping there was one on IEnumVariant
What exactly have you in mind with IEnumVariant? - I did nothing on that topic yet, but there is a chance that I've got something planned in that regard already.
@@codekabinettcomen Sounds very interesting. Ultimately to implement IEnumerable/ICollection/IList classes which will probably require a general-purpose IEnumVariant. Eg for extending the Dictionary project github.com/MarkJohnstoneGitHub/VBA-IDictionary, which could be used with repositories containing various list implementations that say could be used for eg a VBA JSON parser etc. I've done a bit of research thou most code is in VB6 and requires a "bit" of work to get running in VBA. Probably the easiest method is creating an IDL which don't have any experience thou looks reasonably simple, once you get past the learning curve. (another idea for a video creating IDL and tlb files). It gets complicated if attempting to do it solely in VBA when dealing with different data types i.e. Strings, Objects. It be nice to see both implementations as doing it VBA gives good insight to what is occurring under the hood. Eg To extend the dictionary project to make it enumerable, "likely" to require the ability to select the enumerator other than the default by key, ie. a dictionary entry (key, value pair), as the Scripting.Dictionary doesn't allow enumeration by item. I'll have to organize the IEnumVariant research done a few months back and being meaning to focus back on it.
I've got a book recommendation page for Access and VBA here: codekabinett.com/rdumps.php?Lang=2&targetDoc=access-vba-book-recommendations Once you got a solid foundation on Access/VBA you should look for books that focus on writing good, readable, error proof and maintaiable code. Unfortunately, I don't know any such that is dealing with VBA.
Very helpful lesson. But are you sure first enum variable is assigned 1 and not 0 by default?
You are correct. By default Enums will start with 0 for the first enum item. - I usually define explicit values for the enum items, that's why I made that mistake. Thank you very much for pointing this out!
For decades of years I did not understand the sense of Enums, although I to read books and Online Helps in Access. After watching this great Video tutorial all things are clear!! Thank you very much.
I need to admit that I was not aware about that I can use Enum as sub/function parameter. It can be soo useful! Thanks!
Always wondered what enum meant and how to use it. Thanks again.
always good to be explicit :) another good video on giving thought to code. I can see where enumerations are a great benefit when used as type for parameters ... nice to be prompted with choices.
I've put comments in the code specifying values for parameters and what they mean, never giving a though to intellisense ... but as you demonstrate, I can see where enums could be extremely useful to supply choices when coding.
I've read code with enums, and understand the logic -- just never saw any benefit till you show it so explicitly. I have an application I can use them in right now, and just might! Thanks for the idea and clear demonstration, Phillip
Very nice, I just went back through some of my code and was able to get rid of the comments and replace with ENUM. Much more readable now.
Excellent... Phillip, very easy and understandable english..i really appreciate it and will follow for my learning to excel VBA.
I used to use Enums, but stopped for some reason. Now, I will go back and use them more often.
Awesome tutorial, many thanks!
I had no idea you could do this, thanks Phil.
Very good video, thank you. I have a question please, XlLineStyle is enum in excel VBA. Is XlLineStyle part of any class in VBA? where is located compare to other VBA object hierarchy. Thanks again.
Some things to add for Enum
1) I think enum values are of data type Long which is worth noting if values require conversion to say Integer etc.
2) Can also have an enumeration of the Enum values by adding at the end [_First] and [_Last] eg
Public Enum CustomerSegment
NormalCustomer = 1
VIPCustomer = 2
[_First] = NormalCustomer
[_Last] = VIPCustomer
End Enum
Sub TestEnum
Dim customerType As CustomerSegment
For customerType = CustomerSegment.[_First] To CustomerSegment.[_Last]
SendCustomerReports(customerType)
Next
End Sub
Thank you for 1), that's worth mentioning. - Not sure about 2), though. It's rather rare to iterate over all values of an enum. For .. Next works here by converting the first and last value to a long. That's not going to work when the enum values are NOT a gap-less sequence of integers.
@@codekabinettcomen Thanks for point 2) It only works for if the values declared within the Enum are sequential www.cpearson.com/excel/Enums.aspx. That makes it limiting for validation of input of enum values.
Enjoying going through your videos some really interesting advanced topics.
Ps Was hoping there was one on IEnumVariant
What exactly have you in mind with IEnumVariant? - I did nothing on that topic yet, but there is a chance that I've got something planned in that regard already.
@@codekabinettcomen Sounds very interesting.
Ultimately to implement IEnumerable/ICollection/IList classes which will probably require a general-purpose IEnumVariant. Eg for extending the Dictionary project github.com/MarkJohnstoneGitHub/VBA-IDictionary, which could be used with repositories containing various list implementations that say could be used for eg a VBA JSON parser etc.
I've done a bit of research thou most code is in VB6 and requires a "bit" of work to get running in VBA. Probably the easiest method is creating an IDL which don't have any experience thou looks reasonably simple, once you get past the learning curve. (another idea for a video creating IDL and tlb files).
It gets complicated if attempting to do it solely in VBA when dealing with different data types i.e. Strings, Objects. It be nice to see both implementations as doing it VBA gives good insight to what is occurring under the hood.
Eg To extend the dictionary project to make it enumerable, "likely" to require the ability to select the enumerator other than the default by key, ie. a dictionary entry (key, value pair), as the Scripting.Dictionary doesn't allow enumeration by item.
I'll have to organize the IEnumVariant research done a few months back and being meaning to focus back on it.
thank you Philip! do you recommend any book for vba programming in access?
I've got a book recommendation page for Access and VBA here: codekabinett.com/rdumps.php?Lang=2&targetDoc=access-vba-book-recommendations
Once you got a solid foundation on Access/VBA you should look for books that focus on writing good, readable, error proof and maintaiable code. Unfortunately, I don't know any such that is dealing with VBA.
I didn't know you could call the enum with dot syntax and then the values like in objects notation
cool stuff
❤️
want to learn VBA and i will be seeking your support
Очень интересно. Раскрываются с точками словно как свойства.
Nice videos, but I am sick of the music at the start. Please play music from Mozart or Vivaldi in future videos. Thanks.
Noted. - I will think about the music. Replacing it with Vivaldi or Mozart is rather unlikely though.
@@codekabinettcomen - Your videos are cool, they deserve cool music, such as: ruclips.net/video/T22GJNt1SbE/видео.html