Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Procedure Sub Main in VB.Net

Posted on 2014-01-12
9
Medium Priority
?
391 Views
Last Modified: 2014-01-19
I'm new to VB.Net / Visual Studio . . .

I'm trying to write some simple sub procedures to interact with a SQL Server database - upload some files to a filestream column and run some stored procedures etc. Using the Empty Project template, I've created a simple project consisting of a single module and the appropriate references (System, System.Data). The problems is that although I've written a few subs, I can't seem to run or debug anything except the Sub Main procedure.

Obviously missing something basic here.
0
Comment
Question by:TimHudspith
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 14

Expert Comment

by:Matti
ID: 39774623
Hi!

binding on windows form and using it in sub main won't work, if it this case you must reorganize the database connection in the load process of the application.

matti
0
 

Author Comment

by:TimHudspith
ID: 39774724
The code is in a module, not a form. The code I have inside Sub Main runs (connecting to SQL Server and running a procedure). I'm wondering why no other procedures in this module run. I place the cursor inside them and press F5, but code execution goes straight to Sub Main and runs that instead. That's what I'm trying to understand.
0
 
LVL 13

Expert Comment

by:ktaczala
ID: 39774736
Set a break point in your code where you want then try debugging it.  Then step through your code my pressing F11

see link:
http://msdn.microsoft.com/en-us/library/y740d9d3.aspx
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:Matti
ID: 39774737
hmm.. you run it twice or multiple  times, are you sure there are no attempts to open a open database and so on, try global declaration or the connection sting.
0
 

Author Comment

by:TimHudspith
ID: 39774755
ktaczala - I did that but code execution jumped straight up to Sub Main, as if the other procedure did not exist.
0
 
LVL 13

Expert Comment

by:ktaczala
ID: 39774928
can you show us what you have in your sub main?  Load Event.
0
 

Author Comment

by:TimHudspith
ID: 39791840
I've requested that this question be deleted for the following reason:

This question stemmed from my unfamiliarity with the Visual Studio environment. What I was aiming at was stepping through procedures in a module by calling them from the Immediate window, which I now know how to do. Apologies for wasting people's time.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 39791828
VB6 was interpreted. It was compiled line by line as you went along in the development environment. It was basically executing your source code.

In VB.NET, the whole application needs to be compiled before you can use the debugger, and you are running over compiled code, not the source code. This changes the way some of the functions of the debugger works, and the Immediate window is one of these.

The use of the Immediate window is mainly to test code while the debugger is active. It can be used as it was used in VB6, but with a few changes.

The procedure should be in a module and be Public. It will run, but only if the application can compile, and only after it has compile, which might take time.

In my opinion, the best way to use it to test procedure is to put a breakpoint right at the start of Main, start the application, and then do you stuff with the Immediate window.

Methods that you call from there will execute on the spot, and can be execute many times without having to wait for the compiler to recompile the application.

And since the application is running, you will have access to methods that are Friend or Private in your module, which is not possible when using the Immediate window while the application is not running.
0
 

Author Closing Comment

by:TimHudspith
ID: 39791841
That's an excellent explanation. Now I understand. Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

876 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