f



Getting rid of the event handling

I was wondering if there was a way to work around the event driven nature of
VB. Basically I have some code that automates Excel and hence I really do
not need a button to be pressed for this purpose. Would be grateful for any
help.
Thanks,
- Nirmal


0
nt6000 (5)
6/18/2004 2:57:30 PM
comp.lang.basic.visual.misc 10153 articles. 0 followers. Post Follow

7 Replies
241 Views

Similar Articles

[PageSpeed] 26

> I was wondering if there was a way to work around the event driven
nature of
> VB. Basically I have some code that automates Excel and hence I really
do
> not need a button to be pressed for this purpose. Would be grateful
for any
> help.

Add a BAS Module to your program (Project/AddModule on VB's menu), put

     Sub Main()
         '
         ' Your code goes here
         '
     End Sub

in the module you just added, remove the default Form (right-click its
entry in the Project window and select Remove Form1), and change the
Startup Object to Sub Main (General tab on the dialog box that pops up
when you click Project/Properties in VB's menu).

Rick - MVP

0
6/18/2004 3:10:20 PM
> I was wondering if there was a way to work around the event driven
> nature of VB. Basically I have some code that automates Excel and
> hence I really do not need a button to be pressed for this purpose.
> Would be grateful for any help.
> Thanks,
> - Nirmal

Don't let Bill Gates catch you doing this, but all you have to do is set 
up the project to start in a module and the module can call forms or not 
as it sees fit. In project properties you will find a startup 
specification which is normally "frmMain" or some such form. Change it to 
the SUB call option. Define the SUB and that's that. But doing this is 
shocking to purist programmers...   ;-)





0
6/18/2004 3:22:06 PM
Thanks to both of you. It worked great! :-)

"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:b-ydnTYRJehEmE7dRVn-ig@comcast.com...
> > I was wondering if there was a way to work around the event driven
> nature of
> > VB. Basically I have some code that automates Excel and hence I really
> do
> > not need a button to be pressed for this purpose. Would be grateful
> for any
> > help.
>
> Add a BAS Module to your program (Project/AddModule on VB's menu), put
>
>      Sub Main()
>          '
>          ' Your code goes here
>          '
>      End Sub
>
> in the module you just added, remove the default Form (right-click its
> entry in the Project window and select Remove Form1), and change the
> Startup Object to Sub Main (General tab on the dialog box that pops up
> when you click Project/Properties in VB's menu).
>
> Rick - MVP
>


0
nt6000 (5)
6/18/2004 4:29:49 PM
On Fri, 18 Jun 2004 15:22:06 GMT, Bert Byfield
<BertByfield@nospam.not> wrote:

>> I was wondering if there was a way to work around the event driven
>> nature of VB. Basically I have some code that automates Excel and
>> hence I really do not need a button to be pressed for this purpose.
>> Would be grateful for any help.
>> Thanks,
>> - Nirmal
>
>Don't let Bill Gates catch you doing this, but all you have to do is set 
>up the project to start in a module and the module can call forms or not 
>as it sees fit. In project properties you will find a startup 
>specification which is normally "frmMain" or some such form. Change it to 
>the SUB call option. Define the SUB and that's that. But doing this is 
>shocking to purist programmers...   ;-)

It is not shocking - it is how /all/ VB Apps should be coded

Always use an 'instance' of a Form - never the prototype

( I wish somebody told me that about 5 years ago )
0
erewhon (1218)
6/18/2004 4:36:35 PM
"NT" <nt6000@hotmail.com> wrote in message news:<cauvsf$6v5$1@news-int2.gatech.edu>...
> I was wondering if there was a way to work around the event driven nature of
> VB. Basically I have some code that automates Excel and hence I really do
> not need a button to be pressed for this purpose. Would be grateful for any
> help.
> Thanks,
> - Nirmal

Nirmal,

   Maybe you could be a bit more specific? Do you mean that you have
Visual Basic code you want to execute without any user interface? If
that's the case, just write your code in a module, remove the form,
and make the program's startup Sub Main() instead of Form1. If that's
not what you mean, could you explain? Thanks!

Matthew
0
6/18/2004 8:04:18 PM
Even better. Using Goto/Gosub and line numbers / labels you can make your
entire Sub Main run like a classic BASIC program. It's pretty neat.

"NT" <nt6000@hotmail.com> wrote in message
news:cav59i$8qj$1@news-int2.gatech.edu...
> Thanks to both of you. It worked great! :-)
>
> "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
> news:b-ydnTYRJehEmE7dRVn-ig@comcast.com...
> > > I was wondering if there was a way to work around the event driven
> > nature of
> > > VB. Basically I have some code that automates Excel and hence I really
> > do
> > > not need a button to be pressed for this purpose. Would be grateful
> > for any
> > > help.
> >
> > Add a BAS Module to your program (Project/AddModule on VB's menu), put
> >
> >      Sub Main()
> >          '
> >          ' Your code goes here
> >          '
> >      End Sub
> >
> > in the module you just added, remove the default Form (right-click its
> > entry in the Project window and select Remove Form1), and change the
> > Startup Object to Sub Main (General tab on the dialog box that pops up
> > when you click Project/Properties in VB's menu).
> >
> > Rick - MVP
> >
>
>


0
cmoyaX (98)
6/21/2004 5:34:34 AM
How is that shocking? If by purist you mean beginner then maybe. However, I
think that's how all good VB programmers do it (All Apps should enter
through Sub Main).

"Bert Byfield" <BertByfield@nospam.not> wrote in message
news:Xns950C73A05D65CBertByfield134nospam@24.24.2.165...
> > I was wondering if there was a way to work around the event driven
> > nature of VB. Basically I have some code that automates Excel and
> > hence I really do not need a button to be pressed for this purpose.
> > Would be grateful for any help.
> > Thanks,
> > - Nirmal
>
> Don't let Bill Gates catch you doing this, but all you have to do is set
> up the project to start in a module and the module can call forms or not
> as it sees fit. In project properties you will find a startup
> specification which is normally "frmMain" or some such form. Change it to
> the SUB call option. Define the SUB and that's that. But doing this is
> shocking to purist programmers...   ;-)
>
>
>
>
>


0
cmoyaX (98)
6/21/2004 5:36:46 AM
Reply: