Solved

Procedure Sub Main in VB.Net

Posted on 2014-01-12
9
376 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

815 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

12 Experts available now in Live!

Get 1:1 Help Now