Solved

Show form in VB.net

Posted on 2011-09-04
21
514 Views
Last Modified: 2012-05-12
Hi,

 I have two problems when I show forms in VB.net

------------------------------------> Problem (1) <---------------------------

If I write:

//
Dim Frm as new Form1
Frm.Show
//

fhe form show and after less then 1 second unload automatically.

I don't want that the form unload itself.

form1 is a normal form without any particular properties changed.

No other objects inside and no code.

Simply add new form .. not other.


-------------------------------- Problem (2) -----------------------

If I add this code inside the load event of form:

Dim a As Byte
Dim B As Byte
 
B = 200
a = (10 + 100) + B
 
Msgbox "Test"

The compiler don't show any errors (in this case overflow) and exit to the load event.

In short: don't show the msgbox and don't show any errors.

If I write the some code in the 'main sub' the compiler show the error normally.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I'am new in VB.net and probably the reason is very simply but not for me ...

Someone can help me to solve these 2 problems ??

Best Regards
0
Comment
Question by:luca345
21 Comments
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 36480301
Hello, you don't need to create object of a form in vb.net it is require in C# only. So, you write the below code

Form1.show()
0
 

Author Comment

by:luca345
ID: 36480306
//
Hello, you don't need to create object of a form in vb.net it is require in C# only. So, you write the below code

Form1.show()
//

It is false already tested yesterday becouse form1 is a class.

0
 
LVL 2

Expert Comment

by:prakharsaxena
ID: 36480323
It sounds silly but are you sure you are pointing to the correct form? Try to put a break point in the form and see if your code hits it.
0
 

Author Comment

by:luca345
ID: 36480396
Already do it, the break point exit to load event and go to activated event ...

The problem are 2:

1) The forms unload automatically.
2) No errors return inside the forms.

I don't known how I can solve ....
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36480567
What version VB.Net are you working in?

For problem #1, are you by chance showing new form and then closing the original form that was already open?  If so, is the original form the "startup object" in Project --> Properties?

For problem #2, are by chance working on an x64 machine?
http://connect.microsoft.com/VisualStudio/feedback/details/357311/silent-exceptions-on-x64-development-machines
0
 

Author Comment

by:luca345
ID: 36480583
Hi Idle_Mind ,

Compiler: Vb.NET 2010 (setting x86)
OS: Win 7 (64 bit)

here some update:

I have downloaded from planet source code some example project of previous version VB.net.

Result: all work.

I think the problem is same setting of compiler options.

please help me !!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36480592
So the exception in Form Load() problem supposedly can be remedied by a HotFix:
http://support.microsoft.com/kb/976038/en-us
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36480594
For the Show() issue, please describe the flow of the program and share all of the code.
0
 

Author Comment

by:luca345
ID: 36480610
I have undestand where there is the problems.

In short to use form I must create project template 'application form'

If I use 'application console' with main function there are all of this problem.

In VB.net I can't start with sub main if I want use a form .... in VB6 I have only start with sub main.

Do you have informations about this problem ??

I need to use form and I need to start with main function ... please help me !!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36480621
Again, what version VB.Net are you working in?

Why do you "need" to start with Main()?...there are other approaches and entry points that can be used that allow you to get the same end result as using Main() without actually starting with Main().

No, you shouldn't use a Console project if you want to work with Forms.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:luca345
ID: 36480628
Vb.NET 2010 4.0.30.319 is the version

I have re-open the original project and in the load event of the form don't show the error ..

Can you please halp me about the stardard /  common use of vb.net with forms ??

I have 15 Years of vb6 experience but zero experience in vb.net .
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36480642
I quick fix is to move the code from the Load() event to the Shown() event instead.
0
 

Author Comment

by:luca345
ID: 36480657
Idle_Mind:

Your solution seem work.

In the shown() event the compiler show the error.

At this point I can't use the load event becouse don't show any errors ... and this is can be very dangerous !!

For your opinion how I can simulate the 'main' sub ?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36480659
What are you doing in Main()?...
0
 

Author Comment

by:luca345
ID: 36480665
In all my project I always use the main to:

Initialize the global variable.
load the config file.
initialize the colors of the custom graph interface.
load the form of demo version (days left)
open the connection of database
......
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 36480686
You can use the Application Startup() event instead:
http://msdn.microsoft.com/en-us/library/w3xx6ewx(VS.80).aspx

In Project --> Properties, set the "Startup Object" to your main FORM.
Next, click on the Button labeled "View Application Events" in the bottom right.
In the left dropdown at the top, change it from "(General)" to "(MyApplication Events)".
In the right dropdown at the top, select "Startup".  This will add the following code:

        Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup

        End Sub

You can put code that was in Main() in that method stub.
0
 

Author Comment

by:luca345
ID: 36480695
Idle_Mind:

Thanks this is what I need !
0
 

Author Closing Comment

by:luca345
ID: 36480697
Very good !
0
 

Author Comment

by:luca345
ID: 36480700
Idle_Mind:

I have multiple questions (3/4)  to ask all of this are vb6 to vb.net problem conversion.

Can you help me ?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36480712
You can ask here but no one else will see them since the question is closed.  If I can't help you then make a new question.
0
 

Author Comment

by:luca345
ID: 36480730
Idle_Mind:

here my next question:

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_27290878.html

can you loot it please ?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now