View Single Post
Old 05-06-2015, 05:06 PM
hDC_0 hDC_0 is offline

* Expert *
Join Date: Feb 2004
Posts: 560
Default Some debugging "hints" for someone new to programming..

Thanks, passel, for adding the proper formatting..

Just a guess...but I'm not feeling comfortable with this line inside the buttonGraphPoints_Click event:
In general, I don't dispose of things until the app's main form is ready to close down (using the Form Closing Event).

Be careful, though, on relying on the form closing event when using an old .Net framework version, per this page:
Prior to the .NET Framework 2.0, the Form.Closed and Form.Closing events are not raised when the Application.Exit method is called to exit your application.
If you have validation code in either of these events that must be executed,
you should call the Form.Close method for each open form individually
before calling the Exit method.

Otherwise if you try to re-reference anything (after it's disposed/gone) while the program is still running, then it may yield an object not found error..

Another troubleshooting hint:
The "Private Sub buttonGraphPoints_Click" only has two parameters "sender" and "e".
Neither of these is actually used in the code contained within the sub.
So break out the Do loop and For Next loop into individual subs called from "Private Sub buttonGraphPoints_Click".
This may make it easier to trace what's going on.

Other than that it's hard to debug your code just from a snippet because other controls are involved,
(which means that other things may be happening outside this code snippet, effecting how it functions).

Speaking of hard to debug - global scoped variables (1, 2, 3).

Originally Posted by BigHairy
Public Module GlobalVariables
Public Series As String
End Module
Wikipedia has this to say:
They are usually considered bad practice precisely because of their non-locality:
a global variable can potentially be modified from anywhere
(unless they reside in protected memory or are otherwise rendered read-only),
and any part of the program may depend on it.
A global variable therefore has an unlimited potential for creating mutual dependencies,
and adding mutual dependencies increases complexity. See action at a distance.
Global variables also make it difficult to integrate modules because software written by others
may use the same global names unless names are reserved by agreement, or by naming convention.

In this StackOverFlow thread, they are a little more generous, citing Steve McConnell, the author of Code Complete.

Section 13.3 of the Code Complete book, though, talks about using access routines (page 340 onward).

Good (recommended) reading.
If you feel you have to use global variables, then it's good to know the risks and how to take precautions.

On a final side note..

Originally Posted by BigHairy
I am trying to create a small application in VB 2013 to graph (and eventually perform a linear regression on) data points supplied by the user
You do know that about Forecasting Formula (Chart Controls), which has, as it's first parameter, "RegressionType", that can be "Linear"?
This StackOverFlow thread has some relevant info also.

Last edited by hDC_0; 05-06-2015 at 06:19 PM.
Reply With Quote