Solved

Procedure Sub Main in VB.Net

Posted on 2014-01-12
9
369 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 14

Expert Comment

by:Matti
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:TimHudspith
Comment Utility
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
Comment Utility
can you show us what you have in your sub main?  Load Event.
0
 

Author Comment

by:TimHudspith
Comment Utility
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
Comment Utility
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
Comment Utility
That's an excellent explanation. Now I understand. Thanks.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

11 Experts available now in Live!

Get 1:1 Help Now