Wednesday, March 13, 2013

Use XPathDocument if you have plan to work with XPath Queries rather than XmlDocument

Don't use the XmlDocument class if you are going to work with XPath queries. .NET has its own class for this purpose called XPathDocument, which does not run any validation checking. When using XPath, avoid using to reduce the search, because searches the complete document.

XPathDocument Doc = new XPathDocument(FileName);
XPathNavigator nav = Doc.CreateNavigator();
XPathNodeIterator Iterator = nav.Select("/bookstore/book");
while (Iterator.MoveNext())
{
   Console.WriteLine(Iterator.Current.Name);
}

Get the list of installed drivers from command prompt

driverquery /v

Task Manager Tips

  • Hit Ctrl+Alt+Del and click on Task Manager
  • Hit Ctrl+Shift+Esc to bring up Task Manager

Catch a key stroke before the actual control

// KeyDown event of some control
private void SomeControl_KeyDown(object sender, KeyEventArgs e)
{
    // 1. Event is called directly after the key stroke
    // If the user hits Enter, we catch the
    // event and do our own things
    if (e.KeyCode == Keys.Enter)
    {
        // Suppress key stroke, so that
        // the control don't receives it
        e.SuppressKeyPress = true;
        // Perform something important...
    }
}
// KeyPress event of some control
private void SomeControl_KeyPress(object sender, KeyPressEventArgs e)
{
    // 2. Event is called during the key stroke
}
// KeyUp event of some control
private void SomeControl_KeyUp(object sender, KeyEventArgs e)
{
    // 3. Event is called after the key stroke 
}

String Comparision Performance Test

Comparasion done Replacing String.Compare with the below listed priorities.

we can priorities as follows:
  1. a == b - the most efficient and visual style
  2. String.Equals(a,b) - equally efficient but pain to read from the code
  3. a.Equals(b) - not fast but more sane than the Object one
  4. Object.Equals(a,b) - very obscure way to compare strings
  5. String.Compare(a,b)==0 - bad way to check equality
I have done a performance test below are the results.
 
Time Taken for comparing 100000000 Strings:

Time taken by == comparison 484 milliseconds
Time taken by CompareOrdinal method 537 milliseconds
Time taken by String.Compare method 18076 milliseconds
Time taken by String.Equals method 490 milliseconds

Enable mouse scroll-wheel in VB6


VB6 would let us use the mouse scroll-wheel like later versions of VS does. Here's a add-in for VB6 that I have used that does just that!

Download \Visual Basic 6\vb6mousewheel\VB6MOU~1 from Microsoft web site

·         Copy the VB6IDEMouseWheelAddin.dll to somewhere on your local machine where it won’t get deleted. I use “C:\Program Files\Microsoft Visual Studio 6”.

·         Click Start, click Run, type regsvr32 \VB6IDEMouseWheelAddin.dll, and then click OK.

·         Start Visual Basic 6.0.

·         Click Add-Ins, and then click Add-in Manager.

·         In the Add-in Manager list, click MouseWheel Fix.

·         Click to select the Loaded/Unloaded check box, and then click to select the Load on Startup check box.

·         Click OK.

Online C++ Compiler

Please find the Online Compiler for running C++ and other different programs: http://codepad.org. Below is the sample template code for C++:

#include
using namespace std;

int  main()
{

 char str[10];

 sprintf(str,"%3d%2d",311,12);

 cout<

 cout<

 return 0;

}