473,902 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Thr eadException, AddressOf
Application_Thr eadException

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

End Sub

Private Sub Application_Thr eadException(By Val sender As Object, ByVal e
As System.Threadin g.ThreadExcepti onEventArgs)

LogException(e. Exception)

End Sub

Private Sub LogException(By Val 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.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #1
12 5912
<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 -> "Applicatio n" -> [_] "Enable
application framework". Then you can select "Sub Main" from the "Startup
object:" combobox.
AddHandler Application.Thr eadException, AddressOf


Note that VB 2005 provides application events, which can be handled by
clicking the "View Application Events..." button on "My Project"'s
"Applicatio n" 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.c om<<<<<<------
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.c om<<<<<<------
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.Thr eadException, AddressOf
Application_Thr eadException

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

End Sub

Private Sub Application_Thr eadException(By Val sender As Object, ByVal e
As System.Threadin g.ThreadExcepti onEventArgs)

LogException(e. Exception)

End Sub

Private Sub LogException(By Val 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.c om<<<<<<------
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.c om<<<<<<------
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.c om<<<<<<------
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.W aitCursor

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.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #10

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

Similar topics

192
9059
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 programmer that you pretend to be, why don't you just write some? (And oh, void main is still not allow by the C++ standard.) Seeming as how you tried to quote the standard in an attempt to pretend you're right, I'll quote the standard to once...
45
3644
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 themselves are an exception to this), and 'bootstrap' your program by instantiating a single application object in main(), would that place any limitations on what you could accomplish with your program? Are there any benefits to doing things that...
15
2897
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 the whole job can be done in the constructor and destructor of a static variable. (Wouldn't that be the ultimate OOP program, just the creation and deletion of an object?) Does the C++ standard require to have a (dummy) main() function in such...
75
9927
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 is there some deeper underlying reason?
5
2815
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 needed during cleanup. (Finally the two forms are obviously not equivalent in a recursive call to `main'). My questions are
13
7795
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 functions and some of them need to start jump to the start of main. If my main setup was just int main() this would be no problem, i could just call main(); The problem is main needs parameters passed to it now. Would any1
16
2153
by: Geoff Jones | last post by:
Hi What is the closest equivalent to Main in a VB.Net form? Geoff
2
2678
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 query. However, I'd like to put them all into one SQL command. Is this possible? Here are the queries: -This query calls the other two queries below- SELECT ., ., Format(((.Date)-(.Date)),"Fixed") AS , .Type FROM INNER JOIN ON (. = .) AND...
28
6073
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
3595
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 file but it is n't.
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10870
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10981
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10499
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5893
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4725
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4306
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.