473,382 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to get code to run w/o user click?

(VB newbie, no flames please)

I have a simple one-form VB application which I want, on
invocation, to start up, initialize and display the form
(the UI), and then go execute some more code (a loop that
checks for certain things etc.).

Where would I put this "more code" -- now, I can make it
do whatever I want in response to a standard UI event
(like user clicks button) but I want the form to load and
initialize, then go off and do this "more code" w/o the
user having to make any clicks.

Is there an event (form initialized?) I can tie this to?
I see a Form1_Load Sub that I can use to initialize some
things, but once the form is loaded what can be used to
trigger further code w/o explicit user interaction?

Thanks,

Tom.
Nov 20 '05 #1
10 1164
"Tom Bower" <an*******@discussions.microsoft.com> wrote...
(VB newbie, no flames please)
Ah shucks, okay :-)
Where would I put this "more code"
What sort of "more code" are you hoping to run? Lots of stuff can be done
at load time. Do you mean you want it to run in the background while
keeping an eye on the controls or just that whatever it is doing needs to be
visible to the user until it finishes?
Thanks,
Tom.


Your welcome,
Tom
Nov 20 '05 #2
Hi,

Here is a list of all the form events

http://msdn.microsoft.com/library/de...ventsTopic.asp

Ken
-------------------------
"Tom Bower" <an*******@discussions.microsoft.com> wrote in message
news:d4****************************@phx.gbl...
(VB newbie, no flames please)

I have a simple one-form VB application which I want, on
invocation, to start up, initialize and display the form
(the UI), and then go execute some more code (a loop that
checks for certain things etc.).

Where would I put this "more code" -- now, I can make it
do whatever I want in response to a standard UI event
(like user clicks button) but I want the form to load and
initialize, then go off and do this "more code" w/o the
user having to make any clicks.

Is there an event (form initialized?) I can tie this to?
I see a Form1_Load Sub that I can use to initialize some
things, but once the form is loaded what can be used to
trigger further code w/o explicit user interaction?

Thanks,

Tom.

Nov 20 '05 #3
* "Tom Bower" <an*******@discussions.microsoft.com> scripsit:
I have a simple one-form VB application which I want, on
invocation, to start up, initialize and display the form
(the UI), and then go execute some more code (a loop that
checks for certain things etc.).

Where would I put this "more code" -- now, I can make it
do whatever I want in response to a standard UI event
(like user clicks button) but I want the form to load and
initialize, then go off and do this "more code" w/o the
user having to make any clicks.

Is there an event (form initialized?) I can tie this to?
I see a Form1_Load Sub that I can use to initialize some
things, but once the form is loaded what can be used to
trigger further code w/o explicit user interaction?


You will have to start the execution in a new thread (keyword:
"multithreading"). Have a look for this topic in the documentation --
if you have any questions, feel free to post them.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
>What sort of "more code" are you hoping to run? Lots of
stuff can be done at load time.
Do you mean you want it to run in the background while
keeping an eye on the controls or just that whatever it
is doing needs to be visible to the user until it
finishes?


Well, it's the latter, basically. This "more code" is a
loop, looking for a certain condition to be true, waiting
to take action. When I put it in the Form1_Load sub, the
form itself never showed up on the screen.

I want the form to show up, then have this additional
code loop to monitor the condition it needs to look for
every so often. Does that make sense? Thanks for your
help, I'll also have a look at multithreading but that's
a new area for me!

Nov 20 '05 #5
"Tom Bower" <an*******@discussions.microsoft.com> wrote...
What sort of "more code" are you hoping to run? Lots of
stuff can be done at load time.
Do you mean you want it to run in the background while
keeping an eye on the controls or just that whatever it
is doing needs to be visible to the user until it
finishes?


Well, it's the latter, basically. This "more code" is a
loop, looking for a certain condition to be true, waiting
to take action. When I put it in the Form1_Load sub, the
form itself never showed up on the screen.

I want the form to show up, then have this additional
code loop to monitor the condition it needs to look for
every so often. Does that make sense? Thanks for your
help, I'll also have a look at multithreading but that's
a new area for me!


That turns out to be the former actually. You want it to run in the
background while the main app continues to operate. So yes you will have to
have the routine run as another thread. The reason (as you've probably
figured out) that your form never appears is that the code that is executing
is your loop so it never has a chance to continue on and do the "normal"
things.

Tom
Nov 20 '05 #6
Cor
Hi Tom,

You mean something as this?
\\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
Threading.Thread.Sleep(10000)
////

The threading.thread.sleep is just an example to show that it stops and go
on.

I hope this helps?

Cor
I have a simple one-form VB application which I want, on
invocation, to start up, initialize and display the form
(the UI), and then go execute some more code (a loop that
checks for certain things etc.).

Where would I put this "more code" -- now, I can make it
do whatever I want in response to a standard UI event
(like user clicks button) but I want the form to load and
initialize, then go off and do this "more code" w/o the
user having to make any clicks.

Is there an event (form initialized?) I can tie this to?
I see a Form1_Load Sub that I can use to initialize some
things, but once the form is loaded what can be used to
trigger further code w/o explicit user interaction?

Thanks,

Tom.

Nov 20 '05 #7
If you want to execute a code as soon as a form is
visible, just do the following:
1. In your Form1_Activate sub of Form1:
if you have some code here, after that write:
me.show
me.refresh
Call MoreCode ' the "more code" that you want to call
and execute.
2. In the Form's code, write the following:
' your "more code" starts here....
Public Sub MoreCode()
Dim condition As Boolean

Do While condition = False
'... determine your condition here ....
'... and
'... set "condition = True" when your want to return.
'
If condition = True Then
Exit Do
End If
Loop
End Sub
' ... your "more code" ends here.
This will ensue that your form is visible, while
the "MoreCode" sub (it can be a Function also) loops
until your "condition" becomes "true".
Hope this works for your requirement.
IRFAN.
-----Original Message-----
What sort of "more code" are you hoping to run? Lots of
stuff can be done at load time.
Do you mean you want it to run in the background while
keeping an eye on the controls or just that whatever it is doing needs to be visible to the user until it
finishes?
Well, it's the latter, basically. This "more code" is a
loop, looking for a certain condition to be true,

waitingto take action. When I put it in the Form1_Load sub, theform itself never showed up on the screen.

I want the form to show up, then have this additional
code loop to monitor the condition it needs to look for
every so often. Does that make sense? Thanks for your
help, I'll also have a look at multithreading but that's
a new area for me!

.

Nov 20 '05 #8
"Tom Bower" <an*******@discussions.microsoft.com> schrieb
(VB newbie, no flames please)

I have a simple one-form VB application which I want, on
invocation, to start up, initialize and display the form
(the UI), and then go execute some more code (a loop that
checks for certain things etc.).

Where would I put this "more code" -- now, I can make it
do whatever I want in response to a standard UI event
(like user clicks button) but I want the form to load and
initialize, then go off and do this "more code" w/o the
user having to make any clicks.

Is there an event (form initialized?) I can tie this to?
I see a Form1_Load Sub that I can use to initialize some
things, but once the form is loaded what can be used to
trigger further code w/o explicit user interaction?


I think the main question (I have) is whether your only problem is to start
the "more code" directly after the form is shown, or whether you also want
that the user can use the Form while "more code" runs.

If it is only the former:

dim f as new form1

f.show
f.refresh
<more code>
If Form1 is the startup object (set in the project properties), you have to
write your own sub main:

shared sub main 'drop "shared" when in a module
dim f as form1

f = new form1
f.show
f.refresh
<more code>
application.run(f) 'drop this line if app should quit here
end sub

If you also want to keep the Form interact with the user, you've already
gotten Herfried's suggestion to execute it in a new thread.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9
"Tom Bower" <an*******@discussions.microsoft.com> wrote in message news:<d4****************************@phx.gbl>...
(VB newbie, no flames please)

I have a simple one-form VB application which I want, on
invocation, to start up, initialize and display the form
(the UI), and then go execute some more code (a loop that
checks for certain things etc.).

Where would I put this "more code" -- now, I can make it
do whatever I want in response to a standard UI event
(like user clicks button) but I want the form to load and
initialize, then go off and do this "more code" w/o the
user having to make any clicks.

Is there an event (form initialized?) I can tie this to?
I see a Form1_Load Sub that I can use to initialize some
things, but once the form is loaded what can be used to
trigger further code w/o explicit user interaction?

Thanks,

Tom.


Tom, easiest way is to call another Sub Procedure from the

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Which runs as soon as your form loads all of its contents
' and where Form1 is the name of your form

' -- do some code
Call MoreCode()

End Sub
Private Sub MoreCode()
' Put more code here
End Sub
Nov 20 '05 #10
Tom,

Just curious, why not use an event instead of a loop? I know it isn't
always possible, but when doable it is certainly more elegant.

"Armin Zingler" <az*******@freenet.de> wrote in message news:<uV**************@TK2MSFTNGP10.phx.gbl>...
"Tom Bower" <an*******@discussions.microsoft.com> schrieb
(VB newbie, no flames please)

I have a simple one-form VB application which I want, on
invocation, to start up, initialize and display the form
(the UI), and then go execute some more code (a loop that
checks for certain things etc.).

Where would I put this "more code" -- now, I can make it
do whatever I want in response to a standard UI event
(like user clicks button) but I want the form to load and
initialize, then go off and do this "more code" w/o the
user having to make any clicks.

Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
1
by: Stephen | last post by:
Hey Everyone, I have a problem with a web application due to the use of both client-side and server side script on the on-click event of a button. The client side script runs first as expected...
1
by: Stephen | last post by:
Hey All, I have a problem with a web application due to the use of both client-side and server side script on the on-click event of a button. The client side script runs first as expected however...
7
by: | last post by:
I am having trouble figuring out to call a database INSERT procedure from a simple submit form. It appears I should use the onclick event to trigger the procedure called BUT when I do this I...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
6
by: cefrancke | last post by:
I've read up on Access and the limits of creating visible controls at run-time. I'm using Access 2003 and assume that it cant be done. I did find a clever method of having a main form (and in...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
0
by: raypjr | last post by:
Hi everyone. I need a little help with some parts of a word guessing game I'm working on. I have some parts done but unsure about others and could use a little advice. Any help is very much...
4
NeoPa
by: NeoPa | last post by:
Introduction: Macro Security Levels in MS Office applications are recommended to be set to High. This stops any VBA code associated with a project from running, unless it is signed (with a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.