Sub Main() refusing to work

C

Chris

Adam said:
This is probably the most silly question asked here but I just can't figure
it out.

In VB6 letting Sub Main() be the app's startup directory was real easy under
project properties.

In VB.Net however I don't see such an option, all I see is which form I want
the program to start in.

I've added a Sub Main() into forms, modules, and classes (using the shared
parameter) but I just can't
get project properties to let me choose it as the startup sub. It's always
in some form_load it wants
to startup.

Why?

Adam
Show us the code you use to make the the module sub main. It should
show up as Main in the drop down.

Chris
 
C

Chris

Adam said:
It doesn't like it when I turn off the framework option.

Just loads the form and then exits the program.

Public Sub Main()

Dim NewInstance = New frmMain

NewInstance.show()

End Sub

do ShowDialog not Show

Chris
 
A

Al

In Project Properties there is a check box Enable Application Framework. If
it's checked then there is no Sub main option. If you uncheck it then Sub
Main option appears in the list of startup objects.
You create Sub Main in a module and it works. At least I did what I
described.

Al
 
A

Adam Honek

This is probably the most silly question asked here but I just can't figure
it out.

In VB6 letting Sub Main() be the app's startup directory was real easy under
project properties.

In VB.Net however I don't see such an option, all I see is which form I want
the program to start in.

I've added a Sub Main() into forms, modules, and classes (using the shared
parameter) but I just can't
get project properties to let me choose it as the startup sub. It's always
in some form_load it wants
to startup.

Why?

Adam
 
A

Adam Honek

In a module I did it like this:

Module Module1

Public Sub Main()

End Sub

End Module

Similar in a form or class.

Adam
 
A

Al

I have Sub Main in a module:
Sub Main()

objConn = New SqlConnection

'objConn.ConnectionString = "Data Source=DELLNEW;Initial Catalog=SRSNew;User
ID=administrator;Password=developer4242;"

objConn.ConnectionString = "Data Source=DELL205;Initial
Catalog=SRSNew;Integrated Security=True"

objConn.Open()

Application.Run(New MDIMain)

End Sub

I open SQL Connection and start MDI form. Everything works fine.
You are trying to show the form, not to start the application. This is the
reason why it doesn't work I think.
 
A

Adam Honek

It doesn't like it when I turn off the framework option.

Just loads the form and then exits the program.

Public Sub Main()

Dim NewInstance = New frmMain

NewInstance.show()

End Sub
 
A

Al

Adam,
I have a very long experience with VB6, with VB2005 I'm just starting. I did
already several nice looking forms with Infragistics and did not notice any
visual problem.
I cannot be sure that turning on or off Enable Application Framework may
affect visual stuff. Maybe it's related somehow, but as I said I do not see
problems yet.
I tried to attached a couple of screen shots , but they are not accepted by
the server (sizes 50 K and 90 K - to make them smaller to make them look
worse).

Al
 
A

Adam Honek

Thanks, that made it startup without crashing.

Disabling the framework seems to take away functionality within the
controls.

For example the icons I used in the tree view control suddently get a black
border thus look ugly. Turn on the framekwork and bingo they're nice again.

I think it's to do with disabling Windows XP visual styles.

Adam
 
A

Adam Honek

If I do what Chris stated and turn off the framework things go ugly in terms
of visuals.

But I then can use Sub Main().

Is the it then true that MS stopped allowing Sub Main() even when the
framework is turned off? Surely they can't mean
to imply professional coding has the app starting in a form right under
form_load or form_activate?

Adam
 
A

Al

I hate XP style myself and even did not try to run under XP desktop
settings. After your answer I tryed and saw that many controls changed their
appearance, but they still look fine. Just different than they are under
Classic settings. Now I need to check all controls, because my users tastes
are not the same as mine, so they may use XP settings. So far I did not find
any problem.

Al
 
A

Adam Honek

Those are nice looking screens indeed.

In that case it must not affect all controls (the visuals going downhill)
because on mine I have a menu strip
and tree view amongst other graphical control and both suffered visual loss
when turning off the framework.

On one side .NET seems easier than VB6 but on the other there's many places
to just ask ?????'s
about even simple things.

At least we can still use the Win32API if unsure and I'm sure it's faster
than this freamework wrapper
interpreted code anyway.

Adam
 
G

gene kelley

It doesn't like it when I turn off the framework option.

Just loads the form and then exits the program.

Public Sub Main()

Dim NewInstance = New frmMain

NewInstance.show()

End Sub

If that's the only code in your Sub Main and frmMain is your startup
object, then there is no logical reason to use a SubMain.
If there is other code, you might want to look at possibly using
Sub MyApplication_Startup in the Application Designer>

Gene
 
C

Cor Ligthert [MVP]

Adam,

One of the thousand messages Armin, Herfried and Jay have written about this
in this newsgroup.

It is an old message from Herfried but therefore probably very good in your
case.

http://groups.google.com/group/microsoft.public.dotnet.languages.vb/msg/1f37ecbe95e32ad1

If you want to read more about it, than check for the by them often used
word messagepump.

I don't use it in form applications the inbuild is fine enough for me.

I hope this helps,

Cor
 
A

Adam Honek

Hmmm, that's how I expect things to work, more how VB6 RIP worked. Thanks.

So why the framework? What exactly happens when it's disabled in the
application settings?

The .NET framework it used anyhow is it not?

Maybe MS is trying to tell us there's no point in using Sub Main() anymore,
it's fine to just use a startup forms _load or _activate event?

Adam
 
A

Adam Honek

I think it must be because the images you're using aren't 32bit hence you
can't
tell the difference in quality.

Even 24bit isn't 32bit quality because of the alpha 8 bit channel despite
both being 16.7m colours.

Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top