I tried to define the x and y positions for the diagonal edges for each cell in the following picture:
I do not know if my way to obtain these positions is right or not so I need to print the output gagged array on txt file as matrix to check that, I wrote the following code :
using System;
using System.IO;
using System.Text;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using AUV_Topology;
using System.Collections.Generic;
namespace AUVtopology
{
public partial class Form1 : Form
{
static int[] cellsCenters;
static int[] columnsXs;
static int[][] rows;
public int[][] calculateCellsCenters(int intialPoint,int lastPoint)
{
FileStream fs = new FileStream("C:/Users/Welcome/Desktop/testPositions.txt", FileMode.Append, FileAccess.Write);
int d = lastPoint - intialPoint;
int cellSide = d /5;
int intialCell = intialPoint - cellSide;
columnsXs = new int[6];
columnsXs[0] = intialCell;
rows = new int[6][]; // jagged array
for (int i = 0; i < rows.Length; i++)
{
rows[i] = new int[6];
for (int k = 0; k < rows[i].Length; k++)
{
columnsXs[k] = columnsXs[k] + cellSide;
using (StreamWriter sw = new StreamWriter(fs))
{
sw.Write(" "+columnsXs[k]+ " ");
}
}
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine();
}
}
return rows;
}
private void selectedPath_Click(object sender, EventArgs e)
{
calculateCellsCenters(200, 325);
}
} // end-class
} // end namespace
I got the following error in the following picture when I pressed the button that call the method which is responsible to make these calculations and print the gagged array :
The details of this error :
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at AUVtopology.Form1.calculateCellsCenters(Int32 intialPoint, Int32 lastPoint, Int32 numOfcellsEachRow) in C:\Users\Welcome\Desktop\project\GAAPS\AUV_Topology\Form1.cs:line 935
at AUVtopology.Form1.selectedPath_Click(Object sender, EventArgs e) in C:\Users\Welcome\Desktop\project\GAAPS\AUV_Topology\Form1.cs:line 975
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1637.0 built by: NETFXREL3STAGE
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
AUV_Topology
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/Welcome/Desktop/project/GAAPS/AUV_Topology/bin/Release/AUV_Topology.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1586.0 built by: NETFXREL2
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1637.0 built by: NETFXREL3STAGE
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1586.0 built by: NETFXREL2
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Microsoft.VisualBasic.PowerPacks.Vs
Assembly Version: 10.0.0.0
Win32 Version: 10.0.30319.1
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic.PowerPacks.Vs/10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.PowerPacks.Vs.dll
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 10.0.0.0
Win32 Version: 14.6.1586.0 built by: NETFXREL2
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1638.0 built by: NETFXREL3STAGE
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Also, is my code right in which to get the right positions as I mentioned before ??