I was wondering if anyone would like to help me convert the attached module, in the project, to a Class module. I sort of understand the basics of Class programming, but I'm a newbie at it and would like someone to help me out with this little project.
The Functions that I want to have are:
SetKey
GetKey
DelKey
DelKeyValue
For instance, I would like to be able to use the Class as follows:
Code:
Sub Main()
'Example for local machine:
Dim Registry As clsRegistry
Set Registry = New clsRegistry
If Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\Testing", "TestValue", "TestSetting") = "Error" Then
Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\Testing", "TestValue", "TestSetting") = "Last Name"
MsgBox "Value was set"
Else
MsgBox "Error setting value"
End If
End Sub
Any advice/help is greatly appreciated,
Thanx,
ziggy2004
Last edited by ziggy2004; Jul 10th, 2004 at 04:06 PM.
Originally posted by Dave Sell Do you have a compelling reason to group all those functions into a Class?
Good Object-Oreinted techniques do not recommend grouping functions into a class just for the sake of keeping them together.
If the functions are related to eachother logically and need to pass and share common data between eachother, then is the time to make a Class.
Since you are a beginner I thought I'd pass that along for your future reference.
The hell are you smoking? Thats a perfect example of needing a class...what is there that you dont like about functions that set get delete etc registry values ?
Originally posted by Dave Sell Why is it better to put the functions in a class instead of leaving them in the module? What advantage is there?
If he is going to start calling various types of Registry functions why the hell not create a class...instantiate it ... and clean up afterwards...its called OOP...at its finest (sometimes..sorry VB..sometimes). He also has more control with his class (public vs. private) and he can control entities or attributes on that object directly.
You dont see the full details of what he / she is trying to accomplish. Nor do you understand the complexities involved when applications become bigger and all of a sudden the client needs you to compare / delete / add / update / transform / move / various objects or entites. Your ONE function or many functions is gonna begin to look a tad bit on the ugly / messy side. You have no control of private / public, nor can you directly modify an object...nor are you thinking of scope or visibility that may be needed.
Class all the way...Dave snatch a book on OOP...learn how to use them effectively. And my reason was never "why not" that was a little pun for you...
Originally posted by jhermiz You dont see the full details of what he / she is trying to accomplish.
The original poster is trying to learn something new. They want to try to learn classes by getting their feet wet. All I was doing was sounding a warning that this is not always the best idea.
Nor do you understand the complexities involved when applications become bigger and all of a sudden the client needs you to compare / delete / add / update / transform / move / various objects or entites. Your ONE function or many functions is gonna begin to look a tad bit on the ugly / messy side.
You obviusly have no clue what I do and do not understand. There is no need to attack my credibility here. I know all too well what happens as projects become larger / older / more complex. This is exactly why I am making my statement. I have seen decisions early on in a project adversly affect the project later on down the road. If the original hackers had used good programming techniques all along much of the work of making changes to it would not exist.
My most successful projects are when my clients require changes mid-stream and I had designed my code in very good OOD techniques and kept things as simple as possible - such that making fundamental changes was very painless.
You have no control of private / public, nor can you directly modify an object...nor are you thinking of scope or visibility that may be needed.
Again, in his particular case, there is no object, there are no scope issues, and there are no public or private scope requirements. I hate repeating myself.
Class all the way...Dave snatch a book on OOP..
Snatch a book? I have read several books on the topic - on top of getting formaly educated in a modern University in Computer Science and receiving my second Bachelor's degree - on top of 10 years OOP/OOD on top of 10 more years of non-OOP/OOD.
I make valid points. You should stick to attacking my points instead of attacking my character. Otherwise you end up looking quite childish.
I'm ending this post because it has gotten a little too personal between different peoples objectives as to "why" one should or shouldn't do things.
What did I really learn? Well, I got a class module that works perfectly regardless of the reasoning as to "why" I wanted it. It is a simple class that shows "how" to create and use Class modules with some API functions, which I am very grateful, "EJ12N", Thanx.
I am a little disappointed as to the direction that this post went to. Perhaps, in the futue, there will be a little less "Ignorance" or "Credibility" challenges to sidetrack the original question.
I don't mind a good debate if each individual can justify his/her reason for doing so, but I don't think that there is room for personal attacks here or anywhere else.
Anyway, thanx for the advice guys and try to lighten up a little when us "Newbies" seek answers.
Cheers,
ziggy2004
P.S I hope that I didn't offend anyone with this post, that is certainly not my intention.
I like this forum and will continue to bring my questions, no matter how "Questionable" they may be, because of the quick responses and quality of the replies.