Solved

Procedure Sub Main in VB.Net

Posted on 2014-01-12
9
378 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 12

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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 12

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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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