Results 1 to 11 of 11

Thread: Inline Code/Class Question [Resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    116

    Resolved Inline Code/Class Question [Resolved]

    Hi,

    I'm creating a database application, which connects to a database and performs different queries on different forms. I've designed it two different ways:
    1. Using code in each form to make a new connection and then doing the query with that
    2. Using a class for the connection, and creating a global instance of it in a module, so that the connection is made when the application loads and the recordset is accessed by various Property Get statements.

    Which do you think is better programming practice? Generally, we're encouraged not to use global declarations, but this is an object, so I'm not sure if that's okay. Also, with the class, if I need to retrieve some information from a separate table (e.g. I have an ID number from one table, and I need to match that to a name from another), then I either have to store the orginal query and query again at the end of retrieving the new information, or create a new instance of the class.

    If this is unclear, and you want some code, just ask.
    Last edited by olamm2k; Feb 26th, 2005 at 03:37 PM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    116

    Re: Inline Code/Class Question

    Had another thought on this since earlier:

    What if I declared my connection object globally when the application starts and then created separate recordsets each time I needed them?

    There must be some standard way of doing this...

  3. #3
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Inline Code/Class Question

    Quote Originally Posted by olamm2k
    Hi,

    I'm creating a database application, which connects to a database and performs different queries on different forms. I've designed it two different ways:
    1. Using code in each form to make a new connection and then doing the query with that
    2. Using a class for the connection, and creating a global instance of it in a module, so that the connection is made when the application loads and the recordset is accessed by various Property Get statements.

    Which do you think is better programming practice? Generally, we're encouraged not to use global declarations, but this is an object, so I'm not sure if that's okay. Also, with the class, if I need to retrieve some information from a separate table (e.g. I have an ID number from one table, and I need to match that to a name from another), then I either have to store the orginal query and query again at the end of retrieving the new information, or create a new instance of the class.

    If this is unclear, and you want some code, just ask.
    #2 is definately more Object-Oriented than #1 so I would strongly recommend #2.

    However there is a third option, which is similar to #2; make #2 as an ActiveX EXE (out of process Object). This object would be stand-alone, running before and/or after your application loads. This gives you the advantages of encapsulation and the option to run the Object on your machine, or even a centralized server (a different machine).
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    116

    Re: Inline Code/Class Question

    Thanks for your reply.

    I've not created an ActiveX EXE before, so I've no idea how to go about this (not the creation, but how to use it once made).

    Could you give me an example, or point me to a site containing one?

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Inline Code/Class Question

    Either technic will work, it does however totally depends on your application architecture. If you don't need to keep connection open then why would you ever need to declare ti globally and visa versa ... You may get tons of recommendation but it's all your call - you're the designer so you must know all aspects ... There is however one thing to keep in mind: simplicity is what really counts after all - don't overcomplicate you program(s) if there is no need for it ...

    Cheers

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    116

    Re: Inline Code/Class Question

    The connection will be kept open the whole time, which is why I think it makes sense to just create it once, then make the various recordsets I need from it.

    Do you think a class approach would be better, or just declaring it in a module as a global object (Global objConn as New ADODB.Connection etc.)?

  7. #7

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    116

    Re: Inline Code/Class Question

    Fair enough - I'll go with the global object declaration.

    Just out of interest, though, how do you use an ActiveX EXE as suggested?

  9. #9

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    116

    Re: Inline Code/Class Question

    Thanks, I'll take a look.

  11. #11
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Inline Code/Class Question

    Quote Originally Posted by olamm2k
    Fair enough - I'll go with the global object declaration.

    Just out of interest, though, how do you use an ActiveX EXE as suggested?
    This may be a good place to start:

    http://www.vbforums.com/showthread.php?t=306032
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

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