473,396 Members | 2,009 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,396 software developers and data experts.

Sub Main()


Ok, I have a VB2005 Beta 2 project with several forms. I have Form1 set as
my startup form. I want to change this to have Sub Main of modMain (listed
below) to be the startup file. How do I do this? If I go to the
application properties and choose an Application Type of Windows
Application, I can only chose a startup Form, not the modMain.

Been reading about exception handling and I am trying to get started on it.

Thanks,

Thomas

Public Module modMain

Public Shared Sub Main()

AddHandler Application.ThreadException, AddressOf
Application_ThreadException

Try
Application.Run(New Form1)
Catch ex As Exception
LogException(ex)
End Try

End Sub

Private Sub Application_ThreadException(ByVal sender As Object, ByVal e
As System.Threading.ThreadExceptionEventArgs)

LogException(e.Exception)

End Sub

Private Sub LogException(ByVal ex As Exception)

' code that writes error to an sql database

End Sub
End Module

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #1
12 5845
<th*****@msala.net> schrieb:
Ok, I have a VB2005 Beta 2 project with several forms. I have Form1 set
as
my startup form. I want to change this to have Sub Main of modMain
(listed
below) to be the startup file. How do I do this? If I go to the
application properties and choose an Application Type of Windows
Application, I can only chose a startup Form, not the modMain.
Select "My Project" in the solution explorer -> "Application" -> [_] "Enable
application framework". Then you can select "Sub Main" from the "Startup
object:" combobox.
AddHandler Application.ThreadException, AddressOf


Note that VB 2005 provides application events, which can be handled by
clicking the "View Application Events..." button on "My Project"'s
"Application" tab.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

Thanks for the answer, but it is the same answer I have been getting from
all my web searching. I hope I am missing something here. I have attached
as screen shot. Select startup Form is all I see and Sub Main is not listed
in the dropdown.

Thanks,

Thomas
BM*

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #3

I guess my newsreader will not allow me to attach files.

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #4
Create a class, then add a member method to it - should be visible in the
project properties as a startup object.

Class MyApplication

<STAThread()> _
Shared Sub Main()

End Sub

End Class


<th*****@msala.net> wrote in message
news:43**********************@news.newsdemon.com.. .

Ok, I have a VB2005 Beta 2 project with several forms. I have Form1 set
as
my startup form. I want to change this to have Sub Main of modMain
(listed
below) to be the startup file. How do I do this? If I go to the
application properties and choose an Application Type of Windows
Application, I can only chose a startup Form, not the modMain.

Been reading about exception handling and I am trying to get started on
it.

Thanks,

Thomas

Public Module modMain

Public Shared Sub Main()

AddHandler Application.ThreadException, AddressOf
Application_ThreadException

Try
Application.Run(New Form1)
Catch ex As Exception
LogException(ex)
End Try

End Sub

Private Sub Application_ThreadException(ByVal sender As Object, ByVal e
As System.Threading.ThreadExceptionEventArgs)

LogException(e.Exception)

End Sub

Private Sub LogException(ByVal ex As Exception)

' code that writes error to an sql database

End Sub
End Module

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Nov 21 '05 #5
<th*****@msala.net> schrieb:
Thanks for the answer, but it is the same answer I have been getting from
all my web searching. I hope I am missing something here. I have attached
as screen shot. Select startup Form is all I see and Sub Main is not
listed
in the dropdown.


Your code suffers from the problem that it cannot be compiled. If you are
defining 'Sub Main' in a module, you must not mark it with the 'Shared'
modifier.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6

Robin,

I added the class just as you suggested, still all that is visible are the
forms in the project. If I change the Application Type to Console
application Sub Main then becomes a choice, but I don't want the console
poping up each time I run the application. Any more suggestions. This
seems like it would be easy to fix. Is it a VB2005 bug?

Thanks,

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #7

Herfried,
OK, I misread your posting. I had Enable application framework checked.
With it unchecked I can choose Sub Main. Unchecking gave me several errors
with some My.Application.Doevents() code. How should it be coded now? I
was using it a few places in my code.

Thanks,

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #8
<th*****@msala.net> schrieb:
I added the class just as you suggested, still all that is visible are the
forms in the project. If I change the Application Type to Console
application Sub Main then becomes a choice, but I don't want the console
poping up each time I run the application. Any more suggestions. This
seems like it would be easy to fix. Is it a VB2005 bug?


As I already said, it's sufficient to disable the application framework.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #9

Alot of my code doesn't work when I uncheck Enable Application Framework.
Lines of code like:

Me.Cursor = System.Windows.Forms.Cursors.WaitCursor

and

Form1.rtbAllAcq.Text = aryStatistics(0)

no longer work.

Anyway I am going to remove Sub Main and return Form1 as the
startup Form. I will have to do some reading on Exception
handling and see how to handle exceptions that I do not catch
at the form level. My code is working fine as is, but I wanted
to try and add some improvements.

Thanks,

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #10
<th*****@msala.net> schrieb:
OK, I misread your posting. I had Enable application framework checked.
With it unchecked I can choose Sub Main. Unchecking gave me several
errors
with some My.Application.Doevents() code. How should it be coded now? I
was using it a few places in my code.


Use 'System.Windows.Forms.Application.DoEvents' instead. What error message
are you receiving?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #11
Thomas,

A beta version can never have Bugs, only not yet well done things.

Cor
Nov 21 '05 #12

If I add Imports System.Windows.Forms to each of the modules that have code
that modifies controls in forms such as

gfrmExReports.prgReport.Value += intProgress (updates a progress bar)

and

Form1.rtbAllAcq.Text = aryStatistics(0) (updates a richTextBox)

Would these line of code start working again?

I am also reading about exception handling to try and correct the mistakes
you pointed out on my first post. The code
was copied from a newsgroup post on VB2003 or VB2002. I am trying to read
up on how to handle exceptions in VB2005.
This is my first VB.net project and I am really happy with how well it
functions. Just trying to keep improving it.
Thanks for all the help,

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #13

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

Similar topics

192
by: Kwan Ting | last post by:
The_Sage, I see you've gotten yourself a twin asking for program in comp.lang.c++ . http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=45cd1b289c71c33c&rnum=1 If you the oh so mighty...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
15
by: Fred Zwarts | last post by:
In C++ execution of a program starts already before execution of main(). The initialization of static variables defined outside the scope of main is performed first. I could imagine a program where...
75
by: Beni | last post by:
I have been programming in C for about a year now. It sounds silly, but I never took the time to question why a C(or C++ or Java) program execution begins only at the main(). Is it a convention or...
5
by: Seong-Kook Shin | last post by:
Hi, I'm reading Steve's "C Programming FAQs" in book version, and have two question regarding to Q11.16 ... Also, a `return' from `main' cannot be expected to work if data local to main might be...
13
by: Sokar | last post by:
I have my main function set up as int main(int argv, char *argv) so taht i can read in a variable which is passed to the program on the command line. The problem is that main calls other...
16
by: Geoff Jones | last post by:
Hi What is the closest equivalent to Main in a VB.Net form? Geoff
2
by: psuaudi | last post by:
I have a main query that I would like to call two different subqueries. In MS Access, I usually just save the two subqueries as separate queries which are then called by a third separate and main...
28
by: ravi | last post by:
Hello everybody, I am writing a small application which does some work before the user main function starts execution. I am trying to #define the main function. But the problem is that,
11
by: aarklon | last post by:
Hi all, I have heard many discussions among my colleagues that main is a user defined function or not. arguments in favour:- 1) if it is built in function it must be defined in some header...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.