|
dsamvelyan wrote: System.Reflection class
Its a namespace.
You use it to create instance of Excel object at runtime using Assembly.CreateInstance . And then create or open file using this object. You can find on google about writing code using reflection.
"If you had to identify, in one word, the reason why the human race has not achieved, and never will achieve, its full potential, that word would be 'meetings'." - Dave Barry
|
|
|
|
|
Assembly assembly = Assembly.LoadFrom(@"C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Excel\11.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll");
object obj = assembly.CreateInstance("Microsoft.Office.Interop.Excel.ApplicationClass");
Excel.Application app = obj as Excel.ApplicationClass;
app.Visible = true;
Excel.Workbook wb = app.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
I have same error in this code!
|
|
|
|
|
This works for me!!
objClassType = Type.GetTypeFromProgID("Excel.Application");
oExcelApp = Activator.CreateInstance(objClassType);
"If you had to identify, in one word, the reason why the human race has not achieved, and never will achieve, its full potential, that word would be 'meetings'." - Dave Barry
|
|
|
|
|
|
How would I write a regular expression of,
the set of binary strings NOT containing 01 as a substring
Thanks
|
|
|
|
|
I would recommend buying the book 'Mastering Regular Expressions' and downloading the program 'Expresso' to master basic regex.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Try this :
string result = Regex.Replace(inputString, @"(01)", "");
|
|
|
|
|
Thanks alot for yr response all. I am actually trying to find just a mere regular expression for a set of binary string that doesn't contain 01 as a substring.
I am not doing any coding in a program at the moment.Tried searching on expresso but no clue.
|
|
|
|
|
|
Yes I did. Thank you very much for the guidance.
|
|
|
|
|
You're welcome
|
|
|
|
|
Hello
Is it possible to test a datagridview column to know if it is numeric ?
I see nothing, but it must be something because when entering text in a numeric column I get an exception !
Warning : My need is not to handle the exception but to know wich column are numeric in order to set the alignemeent !
Many thanks for any help !
|
|
|
|
|
If you are usimg a DataTable to fill the GridView, then you can get the column metadata in separate datatable. This table holds the datatype for each column. I am unable to recall the function now, but it was something like GetSchema.
Hope it helps
|
|
|
|
|
Thank you
But I finaly found a better way
It is to use the "ValueType" property
for (int i = 0; i < dgv_ScanStat.ColumnCount; i++)
{
System.Type Tp = dgv_ScanStat.Columns[i].ValueType;
bool isNumeric =
Tp == typeof(byte) ||
Tp == typeof(System.Int16) ||
Tp == typeof(System.Int32) ||
Tp == typeof(System.Int64) ||
Tp == typeof(sbyte) ||
Tp == typeof(System.UInt16) ||
Tp == typeof(System.UInt32) ||
Tp == typeof(System.UInt64) ||
Tp == typeof(float) ||
Tp == typeof(double) ||
Tp == typeof(decimal);
if (isNumeric)
{
dgv_ScanStat.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
}
}
|
|
|
|
|
Hi,
I need to learn how to do unit tests for certain functions. I have googled and come accross some stuff, but all the examples are easy.
I read multiple articles on code project, but it didn't help. Usually, I see examples of unit testings functions that take in 1-2 parameters and perform addition/multiplication/etc.
I need to know how to unit test functions that return nothing, take in no parameters, and so on. For example, how do I write unit tests for a function that simply executes a SQL stored procedure? Or a function that just calls other functions?
For example:
private static void DoStuff()
{
int x = 0, y = 0, z = 0;
Function1();
x = Function2();
if(x > y)
Function3();
}
Or something like:
private static void ExecProc(int vidID)
{
try
{
SqlCommand cmd = new SqlCommand("blah", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@vidID", vidID));
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine("error: " + e.ToString());
}
}
I know how to do unit tests for the simple examples, where functions take in a parameter or two, and give some output in certain cases. However, when there is no output, when there is no input, when they talk to the DB or execute stored procs...what are proper unit tests?
I am using Visual Studio 2005 (C#) and have access to nUnit. Ideally, I'd like to learn how to write unit tests (manually) for the above examples, and then learn to use nUnit.
Any help you can provide is appreciated. Also, any links my googling didn't turn up would be appreciated as well. I'm really lost, and am sick of finding the same example that uses functions performing simple arithmetic.
Thanks!
|
|
|
|
|
You don't test private methods normally. DoStuff() method is hard to test as it has dependencies with other methods. You can use Interaction testing[^] to test DoStuff() method. You should refactor the dependencies to separate classes and just test it calls the expected methods. You have to use mock objects to do this. I suggest you to look at RhinoMocks, a mocking framework.
In the ExecProc() methods you have used ADO.NET classes which is hard to test. So you need to abstract it behind and interface, mock the interface while testing. Check the following,
class ProcedureExecution
{
IDataAccess dataAccess;
public ProcedureExecution(IDataAccess dataAccess)
{
this.dataAccess = dataAccess;
}
public void ExecProc(int vidID)
{
try
{
dataAccess.Execute("blah",vidID);
}
catch (Exception e)
{
}
}
} We have abstracted the SQL execution code behind an interface named IDataAccess and we supply it through constructor. It is called dependency injection. While testing you can easily mock IDataAccess . AFAIK, there is no testing required for the above said method as there is nothing to test. Also using static will make testing tough.
If the shown code is your data layer code, then test your method itself and check the values in the database. It's tedious, but it drives out of bugs.
|
|
|
|
|
Thanks for your help.
I think I'm on the right track now.
I suppose I can do something similar for testing calls to a web service?
I have to read about Interaction testing, and look into RhinoMocks.
|
|
|
|
|
I have been making my own web browser in C# and something that isn't necessarily bad is always having to click my 'GO' button. I have gotten used to being able to just hit the 'ENTER' key and be on my way to the web site. I am fairly new to c# coding so I am thinking I am missing a solution somewhere. Any help would be appreciated.
|
|
|
|
|
Hi guys.
I try to save and get data from clipboard but this exception occur
Object reference not set to an instance of an object
This is my snippet code.
XElement data = (from node in X_Element.Descendants(nodeName)
select node).First();
Clipboard.Clear();
Clipboard.SetData("XElement", data);
XElement newXmlNode = (XElement)Clipboard.GetData("XElement");
MessageBox.Show(newXmlNode.Name.ToString());
I'm sure that there is a XElement data in data
What's wrong with it?
Thanks in advance
|
|
|
|
|
Mohammad Dayyan wrote: Object reference not set to an instance of an object
That generally means there is a missing new ....
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
But I'm sure that there is a data in it
|
|
|
|
|
Mohammad Dayyan wrote: I'm sure that there is a data in it
Are you 100% absolutely sure?
You can't assume that it is always going to put data in there. Common practice in my shop is to declare the object and instantiate it with the new , then try to populate with the data. It does save from a lot of headache.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Are you looking at this in the debugger? Which line throws the exception?
If you can't look at it in the debugger for some reason, wrap each line in a try/catch and figure out which line is throwing the exception.
|
|
|
|
|
Thanks for reply
JoeRip wrote: Which line throws the exception?
this line :
XElement newXmlNode = (XElement)Clipboard.GetData("XElement");
|
|
|
|
|
In the following struct:
public struct myStruct
{
public static int CumulativeCountOfInstances;
public myStruct(int SomeUnusedData)
{
CumulativeCountOfInstances++;
}
}
If concurrent processes are creating myStruct structs, what prevents collisions as each instance tries to increment CumulativeCountOfInstances ?
|
|
|
|