Results 1 to 14 of 14

Thread: Create class module? RESOLVED

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Location
    Wpg, Manitoba, Canada
    Posts
    149

    Create class module? RESOLVED

    Hello all,

    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
    Attached Files Attached Files
    Last edited by ziggy2004; Jul 10th, 2004 at 04:06 PM.

  2. #2
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    check PM
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Location
    Wpg, Manitoba, Canada
    Posts
    149
    Hey there, EJ12N,

    What exactly does "check PM" mean or refer to?

    Thanx,
    ziggy2004

  4. #4
    Addicted Member SpeedyDog's Avatar
    Join Date
    Feb 2004
    Location
    Missouri, USA
    Posts
    189
    Private Messages... On the forums :-P

    Get to them by the User CP button at the top of the web page.

  5. #5
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    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.

  6. #6
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    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 ?

  7. #7
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    Why is it better to put the functions in a class instead of leaving them in the module? What advantage is there?

  8. #8
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    is matter of likes... if you want to do

    Boo.GetKey blah blah
    or GetKey(blah blah)

    i like class better...
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

  9. #9
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    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.

    Thats why

  10. #10
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    In his example his functions do not share any data and not have any "Attributes" and thus have no need for Public and Private functions.

    Therefore there is still no compelling need to put them in a class.

    I do realize there are advantages to Classes but there are also advantages to keeping things simple (K.I.S.S.).

    I asked clearly what the advantage is to group these clearly independant functions into a class, and you say "Why not"?

    That's not a reason _why_ to do something.

    Complexity is your enemy - keep it simple - leave API wrappers in a module where they belong until you have a compelling need to do otherwise.

  11. #11
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    Originally posted by EJ12N
    is matter of likes... if you want to do

    Boo.GetKey blah blah
    or GetKey(blah blah)

    i like class better...
    You mean to compare them then lets compare:

    VB Code:
    1. Dim SomeUselessClass
    2. Set SomeUselessClass = new clsMyUselessClass
    3.  
    4. SomeUselessClass.SomeFunctionBetterLeftInAModule SomeArg
    5.  
    6. Set SomeUslessClass = Nothing

    As opposed to:

    VB Code:
    1. SomeFunctionBetterLeftInAModule SomeArg

    Clearly the latter is simpler, no?

  12. #12
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    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...


  13. #13
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    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.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Location
    Wpg, Manitoba, Canada
    Posts
    149
    Hello all,

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width