CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Posts
    322

    Examples of really well-designed, well written VB apps

    Are there any examples of really well-designed, well-written VB Apps that are "approved" by the moderators and senior members of this forum, that could be used as examples ?
    I'm particulalry interested in COM clients, but could use an example of a simple, well written (NON-COM) VB-app, with just one form.

    I'm co-maintaining an app which I feel wasn't designed or written well, but I come from a C/C++ background.

    For example

    How much code should an Click event handler contain ?
    Should it call call another function in a .bas file to deal with the messy details- such as range checking the input parameters of a text box, or the Selection in a combo box, or should the range checking be done in the event handler itself ?

    What about globals ? I was always taught not to use them, unless abosutely necessary, to avoid having to re-write a lot of code to eliminate the globals.
    This app is just littered with globals everywhere. Uggh.

    Should .bas files be able to call subs/funcs in frm files (assuming they are public), or should only subs/funcs in .frm files call each other?

    thanks

  2. #2
    Join Date
    Aug 2003
    Location
    India
    Posts
    81

    Lightbulb Re: Examples of really well-designed, well written VB apps

    Quote Originally Posted by cappy2112



    How much code should an Click event handler contain ?
    That will depend on wot u want to execute.


    Quote Originally Posted by cappy2112
    Should it call call another function in a .bas file to deal with the messy details- such as range checking the input parameters of a text box, or the Selection in a combo box, or should the range checking be done in the event handler itself ?
    .bas files are modules files which generaally used to write sub/functions that are used frequently in writing a program. The example u r telling can be written within that click event itself.

    Quote Originally Posted by cappy2112
    What about globals ? I was always taught not to use them, unless abosutely necessary, to avoid having to re-write a lot of code to eliminate the globals.
    This app is just littered with globals everywhere. Uggh.
    globals can b used in a frm module as well as a .bas module. It is generally used to declare something globally so that u do not have to declare that thing again and again.




    Quote Originally Posted by cappy2112
    Should .bas files be able to call subs/funcs in frm files (assuming they are public), or should only subs/funcs in .frm files call each other?
    Yes, bas files are able to call subs/funcs in frm files. So, they both can call each other.

    Hope that helps

  3. #3
    Join Date
    Mar 2004
    Location
    South Africa
    Posts
    48

    Re: Examples of really well-designed, well written VB apps

    I'm certainly not one of the Admin's or mod's but here are my 2c for what it's worth (and with the South African Rand at the moment that's not much!)

    How much code should an Click event handler contain
    As little as possible! I'd say 10 lines is an maximum with very few exceptions.

    Should it call call another function in a .bas file to deal with the messy details- such as range checking the input parameters of a text box, or the Selection in a combo box, or should the range checking be done in the event handler itself ?
    A standard bas module should be created to handle input checking if a lot of checking is done AND the module can easily be reused by other forms/apps to perform similar checking.

    What about globals ?
    Yeah, globals can be messy, but I do make use of them for variables that are constantly referred to (I always prefix them with g_ though).

    Should .bas files be able to call subs/funcs in frm files (assuming they are public), or should only subs/funcs in .frm files call each other?
    Well.... not really. The best is to have your frm call a bas module which may or may not call other bas functions and return to the calling frm. The idea is to have bas modules easily reusable and not dependant on certain form elements (be they methods or whatever) being there. However IRL it's not always practical to do that.

    Remember that VB is supposed to be a RAD - not an enterprise development tool - even though it is all too often used as such.

    Anyway that's all just IMHO - use it, don't use it!

    Octavo
    Last edited by Octavo; September 27th, 2004 at 06:53 AM.

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Examples of really well-designed, well written VB apps

    'Agree with Octavo and will add my 2c to his.
    'bas and Froms are not the only module you have:
    'you can make use of Class modules also.
    'A classs module is the brick of OOP developing
    '(at least of the OOP you can access with Vb).
    'If you think to objects that ccan do a certain
    'job, you should also make them as independent
    'as you can from what is outside.
    'For example, imagine you have a class to make
    'some math you need in your software. It would
    'not be nice if this class relied on some global
    'var from somewhere else, or from an objcet
    'on some form. It would be better to have
    'a function that accept the needed data as parameter
    '(or even -but this I like less- to have properties
    'to fill with data before making it do some jobs).
    '
    'Now, to tell the truth, the general rule is:

    ' "there is not a general rule"

    'as you could code same app in many different
    'ways and each of them couldd be fine in a special
    'context.
    'For example:
    'When dealing with Com, you usually try to go with
    'OOP (thus classes -and classes that hold collections
    'of classes-, properies and methods and events and
    'objects in general).
    'But when you are dealing with Com+ and Asp, you might
    'do better forget about events and properties -and even
    'objects in general - as, if your component has to deal
    'with Asp, you should make it as stateless as you can,
    'and should think at it as something that in a single
    'call should do everithing included giving back values.
    'Of course you can make some OOP in Com+, but it would
    'tear down your server as in a Proxy-Server situations
    'Objects will never be passed to clients: they will stay
    'on server, enche each call to a method or property from
    'a client will trip (it is called "round-trip") to the
    'server...Thus if you have few objects, you can make it.
    'But if you have a collection of Customers and for each
    'Customer you have a collection of Order, and for each
    'Order you have a collection of Products, you will kill
    'the marshaller.

    'Thus, while is generally true that trying to follow at least
    'OOP rule of incapsulation:
    '(="make your code in general, your modules and even your
    'single functions in such a way that they can work without
    'knowing what is outside, and make the 'outside' so that
    'it does not need to know how your functions are done
    'internally" -or, in other words, "avoid public variables
    'as long as you can and pass local parameters without
    'creating half a million local variables, of course"),
    'sometimes "better written code" changes its meaning
    'from "code that is easy to understand to humans"
    'to "code that is most easily ported to some other app"
    '(note that usually -but not always- the two above are fully
    'compaatible and even the same), to "code that is optimized
    'for perfomance" -which last is really a blast to OOP fans,
    'as to get the most speed you should code....all inline,
    'avoiding objects as long as you can...!!
    '
    'Now I suggest you in any case to try first with code that
    'is "human and portable", that is: use classes and object
    'oriented. To go for speed against elegance is easier to learn
    'than the contrary.


    Btw, search for Codeguru Vb Articles. They might not contain best code
    of the world, but at least some moderator have had a look, and they
    might be better than standard quick code for small examples we all
    usually post here.
    Last edited by Cimperiali; September 28th, 2004 at 10:30 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured