Quantcast
Viewing all articles
Browse latest Browse all 32057

My custom C# program was working, now it's certainly not =(

I have an exe program that was created using Visual 2010 C#, it was working fine and for some odd reason it decided not to work anymore. Here are the codes, just copy and paste to your C# and run the debug. I cannot find out the reason why it's not working, PLEASE HELP.




Form1: Auto EXCEL



textPath:  this is to type in the path of the folders


btnBrowse: Browse  - This is to browse the folders location.


btnParse: Execute Parse  - This is to exercute the program to look for """SyncToyLog.log*** with the word ***Completed, Sync**  (because log files can be very long so I only need the line that contains the workd Completed), then open up the Logs.xlsx file and copy paste to the according lines. Each the logs.xlsx is in the main folder  - Within the main folder there are about 10 user folders, each  sub folder contains SyncToyLog.log file.


Error:  After Browsed to the folder,when trying to Execute Parse, I get the following error
Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue......etc


Goal:  To grab completed sync information for each user and export into excel.


Assuming: I am thinking there is a problem with the Break points, but I am not sure as I am a noob.


P.S
I will send $30 via PayPal to the person that help me resolve this issue. Yes I know it's not a lot, but it's just my appreciation for your time to help me.


 


 
using
System;

using
System.Collections.Generic;

using
System.ComponentModel;

using
System.Data;

using
System.Drawing;

using
System.Linq;

using
System.Text;

using
System.Windows.Forms;

using
Microsoft.Office.Core;

using
Excel = Microsoft.Office.Interop.Excel;

using
System.IO;

using
System.Text.RegularExpressions;



namespace
AutoEXCEL

{


publicpartialclassForm1 : Form

{


public Form1()

{

InitializeComponent();

}


privatevoid btnParse_Click(object sender, EventArgs e)

{


string strLine = ""; //variable for outputing to Excel File Line With The "Completed" String

Excel.
Workbook wb;

Excel.
Application excelApp = new Excel.Application();


string strExcel = textPath.Text + "\\Logs.xlsx";


if (File.Exists(strExcel))

{

wb = excelApp.Workbooks.Open(strExcel);

}


else

{


MessageBox.Show("Could NOT Find Excel File Named LogText.xls underneath the Folder You've Specified!");


return;

}




string [] fileEntries = Directory.GetDirectories(textPath.Text);


string strFile = "";


string strText = "";


int nExcelRow = 1;


foreach (string folderName in fileEntries)

{



strFile = folderName +
"\\SyncToyLog.log";


if (File.Exists(strFile))

{

strText = System.IO.
File.ReadAllText(strFile);


int nCompl = 1;


int nOldCompl = nCompl;


while (true)

{

nCompl = strText.IndexOf(
"completed", nCompl + 5);


if (nCompl == -1)


break;



nOldCompl = nCompl;

}


//now switch back

nCompl = nOldCompl;


int nStart = nCompl;


//go backwards until we find


while (strText.Substring(nStart, 5) != "SYNC:")

nStart--;


int nEnd = strText.IndexOf("\r\n",nCompl);




if (nEnd > nStart)

{

strLine = strText.Substring(nStart, (nEnd - nStart));

}


else

{

strLine =
"Couldn't find the right line to insert in Log File!";

}

excelApp.Cells[nExcelRow, 1] = folderName;

excelApp.Cells[nExcelRow, 2] = strLine;

nExcelRow++;

}
// if file Exists... BIG IF, do lots of stuff, if not inform the user


else

{

excelApp.Cells[nExcelRow, 1] = folderName;

excelApp.Cells[nExcelRow, 2] =
"No LOG File Found Underneath " + folderName;

nExcelRow++;

}

}

wb.Save();

wb.Close();





}


privatevoid btnBrowse_Click(object sender, EventArgs e)

{


FolderBrowserDialog dlg = newFolderBrowserDialog();

dlg.ShowDialog();

textPath.Text = dlg.SelectedPath;

}

}

}
using
System;

using
System.Collections.Generic;

using
System.ComponentModel;

using
System.Data;

using
System.Drawing;

using
System.Linq;

using
System.Text;

using
System.Windows.Forms;

using
Microsoft.Office.Core;

using
Excel = Microsoft.Office.Interop.Excel;

using
System.IO;

using
System.Text.RegularExpressions;



namespace
AutoEXCEL

{


publicpartialclassForm1 : Form

{


public Form1()

{

InitializeComponent();

}


privatevoid btnParse_Click(object sender, EventArgs e)

{


string strLine = ""; //variable for outputing to Excel File Line With The "Completed" String

Excel.
Workbook wb;

Excel.
Application excelApp = new Excel.Application();


string strExcel = textPath.Text + "\\Logs.xlsx";


if (File.Exists(strExcel))

{

wb = excelApp.Workbooks.Open(strExcel);

}


else

{


MessageBox.Show("Could NOT Find Excel File Named LogText.xls underneath the Folder You've Specified!");


return;

}




string [] fileEntries = Directory.GetDirectories(textPath.Text);


string strFile = "";


string strText = "";


int nExcelRow = 1;


foreach (string folderName in fileEntries)

{



strFile = folderName +
"\\SyncToyLog.log";


if (File.Exists(strFile))

{

strText = System.IO.
File.ReadAllText(strFile);


int nCompl = 1;


int nOldCompl = nCompl;


while (true)

{

nCompl = strText.IndexOf(
"completed", nCompl + 5);


if (nCompl == -1)


break;



nOldCompl = nCompl;

}


//now switch back

nCompl = nOldCompl;


int nStart = nCompl;


//go backwards until we find


while (strText.Substring(nStart, 5) != "SYNC:")

nStart--;


int nEnd = strText.IndexOf("\r\n",nCompl);




if (nEnd > nStart)

{

strLine = strText.Substring(nStart, (nEnd - nStart));

}


else

{

strLine =
"Couldn't find the right line to insert in Log File!";

}

excelApp.Cells[nExcelRow, 1] = folderName;

excelApp.Cells[nExcelRow, 2] = strLine;

nExcelRow++;

}
// if file Exists... BIG IF, do lots of stuff, if not inform the user


else

{

excelApp.Cells[nExcelRow, 1] = folderName;

excelApp.Cells[nExcelRow, 2] =
"No LOG File Found Underneath " + folderName;

nExcelRow++;

}

}

wb.Save();

wb.Close();





}


privatevoid btnBrowse_Click(object sender, EventArgs e)

{


FolderBrowserDialog dlg = newFolderBrowserDialog();

dlg.ShowDialog();

textPath.Text = dlg.SelectedPath;

}

}

}


 


 


 


 



 

Viewing all articles
Browse latest Browse all 32057

Trending Articles