Re: right way to call a form?

From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 11/16/04


Date: Mon, 15 Nov 2004 20:43:10 -0500

Personally, for such a simple app, I'd move all the code from the bas module
into the form, change the declares from Public to Private, then add your
interface controls and call your main routine from the command button. You
can keep the module as the startup object and use it to call the main form
...

private sub main()
   frmMain.Show
end sub

This is in fact the preferred way to code since it provides an opportunity
for you to initialize anything required later by the form (eg application
defaults defined in the bas module, and it provides a means to bail out of
the app if the conditions for starting are not met (eg lack of a connection
to a server, for example.) In air code this gives you the chance to do
things like:

private sub main()

    someRequiredSetting1 = "xxxx"
    someRequiredSetting2 = "yyyy"
    someRequiredSetting3 = GetSetting "MyApp", ....

    If NetDriveIsConnected("X:") then
         frmMain.Show
    end if

end sub

Re the second part on classes ... it's not that wasteful. If you routinely
found you used three of thirty methods of the class, then yes, make a new
class with just those three methods. But in general most reusable classes
have methods that may never be called -- it's the nature of the beast.

-- 
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"MP" <nospam@Thanks.com> wrote in message
news:gBcmd.47639$ye4.23147@twister.rdc-kc.rr.com...
: Hi all,
: warning...dumb beginner question ahead!
: (I leave it to you to decide if its' the beginner or the question thats
: dumb)
: :-)
:
: I've written a bit of functionality in a std module.
: It reads text files and applies a specialized parsing action on the text
to
: divide into separate pieces, and then saves each piece as a separate text
: file.
: Now I've got that almost working, I decided to add a form as ui with a
: button for selection of the textfile to split up, and a listbox to display
: parsing results.
:
: part of my question is, what is the best way for a module and form to work
: together? - or should i put everything in the form and not use modules
: I think my options are:
: option 1: copy/ paste all the module stuff into the form and ditch the std
: modules all together. then make the startup object be the form.
:
: option 2: keep the startup object as sub main which i've been using while
: debuging/writing to call the sub that does the real work. and have the
: working sub call the form in order to use the command buttons for
selecting
: files and viewing the results.
:
: question part two....
: the app uses several toolbox functions i've written over the years and
have
: stored in classes.
: but in many cases the class, eg. clsStrings has lots of functions relating
: to string manipulation and maybe only one or two are used in this routine.
: Is it wasteful to create a class to use one or two functions only?
: Should I just copy/paste the actual function from the class to the app and
: dispose of the class or should i continue to use the toolbox utils class
as
: is?
:
: I'd appreciate any pointers, opinions,  or even hilarious laughter!
: :-)
: Tia
: Mark
:
: