The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,861 other subscribers

Archive for 2012

.NET/C#/WinForms: small code snippet to enable Ctrl-A for select all in a single/multi-line TextBox

Posted by jpluimers on 2012/12/04

WinForms does not automatically enable Ctrl-A as “Select All” action.

The below code snippet works when you bind it to the KeyDown event of a TextBox (actually the event is on Control).

The e.SuppressKeyPress = true suppresses the bell sound in a multiline TextBox, as e.Handled = true won’t.

        private void textBox_KeyDown_HandleCtrlAToSelectAllText(object sender, KeyEventArgs e)
        {
            TextBox textBox = sender as TextBox;
            if (null != textBox)
            {
                if (e.Control && e.KeyCode == Keys.A)
                {
                    textBox.SelectAll();
                    e.SuppressKeyPress = true;
                }
            }
        }

–jeroen

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

Commandline equivalents for FsMgmt.msc: net share / net view / net session / net file / net use

Posted by jpluimers on 2012/12/03

For viewing shares, sessions and open files, you can use the FsMgmt.msc management console plugin (on the same page, Petri also has some interesting information on the NTLANUI.DLL)

You can do the same from the command line, using the NET command.

Somehow, can remember the NET SHARE and NET SESSION command, but I always forget about the NET FILE command.

Luckily, SS64 has documentation on the NET SHARE/VIEW/SESSION/FILE/USE commands on one page.

Here is what they have on NET FILE:

Display all the open shared files on a server and the lock-id

NET FILE

Close a shared file (disconnect other users and remove file locks)

NET FILE id /CLOSE

Two tiny notes:

  • for NET FILE and NET SHARE you need to be Administrator (and run them from an elevated command prompt when running on Windows Vista and up).
  • you can pluralize these commands as well:
    – NET SHARES
    – NET SESSIONS
    – NET FILES
    They work just like the singular version.
    NET USES and NET VIEWS won’t work though.

–jeroen

via: net share / net view / net session / net file / net use.

Posted in Power User, Windows, Windows 7, Windows 8, Windows Server 2000, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Vista, Windows XP | Leave a Comment »

F3 in Excel: Show all named ranges in Excel – via: Spreadsheet Audit & Maintenance Tip | Chandoo.org – Learn Microsoft Excel Online

Posted by jpluimers on 2012/11/30

In Excel I always got confused with named ranges, as I thought they were hard to track.

Not!

The F3 keyboard shortcut gives you a list of named ranges including name and location. Which makes it way easier to work with named ranges.

See the excellent post Show all named ranges in Excel: It even has an animated gif image that shows  you F3 in action.

–jeroen

via: Show all named ranges in Excel – Spreadsheet Audit & Maintenance Tip | Chandoo.org – Learn Microsoft Excel Online.

Posted in Excel, Keyboards and Keyboard Shortcuts, Office, Power User | Leave a Comment »

Be aware of the three valued logic when NULL gets involved: SQL Server: JOIN vs IN vs EXISTS – the logical difference

Posted by jpluimers on 2012/11/29

Great post: SQL Server: JOIN vs IN vs EXISTS – the logical difference.

Be aware of the three valued logic when NULL gets involved.

EXIST comes closes to what you expect.

And be aware that with IN, you cannod pass one parameter containing more than 1 IN value: sql server 2005 – Passing multiple values for one SQL parameter – Stack Overflow..

–jeroen

Posted in Database Development, Development, SQL, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 7 | Leave a Comment »

VB.NET history: VBPowerPack download (formerly from GotDotNet) via: VB Helper: Tip: GotDotNet Visual Basic Power Pack Going Away

Posted by jpluimers on 2012/11/28

I was involved in porting a Visual Studio 2003 VB.NET solution to the latest Visual Studio.

One of the things present was a binary (don’t ask) version of the VBPowerPack, which used to be available on GotDotNet.

Though you can link against .NET 1.1 assemblies from .NET 2.0 and up, I’d rather have source.

That allows me to fix things whenever something comes up (it probably does, as VBPowerPack was pre-Aero, so the controls in it might need some adjustments).

GotDotNet was hated by many people, and finally closed in 2007 by Microsoft in favour of CodePlex (don’t you just love the cloud?).

Luckily, people do archive stuff, so VB Helper has VBPowerPack.

The download is a simple MSI installer, that you can extract using something like this:

msiexec /a PathToMSIFile /qb TARGETDIR=DirectoryToExtractTo

–jeroen

via:

Posted in .NET, Development, Software Development, VB.NET, Visual Studio 11, Visual Studio 2002, Visual Studio 2003, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | 1 Comment »

System Error Messages: anyone who has links for SQL Server > 2000?

Posted by jpluimers on 2012/11/27

I could only find the System Error Messages overview for:

Are there any such links for SQL Server 2005 and up?

The odd thing is online lists of Database Engine Error Severities are available for multiple versions of SQL Server: 2005, 2008 and 2008 R2.

–jeroen

Posted in Database Development, Development, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 7 | 1 Comment »

So I won’t forget: IPv4 private networks 10/8 (10.x.y.z), 172/12 (172.16-31.y.z), 192.168/16 (192.168.y.z) and 169.254/16 (169.254.y.z) (via: Private network – Wikipedia, the free encyclopedia)

Posted by jpluimers on 2012/11/26

So I won’t forget: below are IPv4 private network ranges that you can use behind your router.

Private networks:

  • 10/8
    (10.x.y.z)
  • 172/12
    (172.16-31.y.z)
  • 192.168/16
    (192.168.y.z)

Link-local network:

  • 169.254/16
    (169.254.y.z)

Network you should not configure yourself:

I tried finding statistics on the actual use of private networks, but couldn’t.

This is from my own experience:

  • Link-local is used when DHCP is not available.
  • Lot’s of routers use 10.0.0.x, 192.168.0.0, 192.168.1.0.
  • VMWare Workstation and VMWare Fusnion use 192.168.x.y.

–jeroen

via: Private network – Wikipedia, the free encyclopedia.

Posted in Internet, Power User | Leave a Comment »

UNC and IPv6 (via IPv6 address – Wikipedia, the free encyclopedia)

Posted by jpluimers on 2012/11/23

If you have a MYSHARE share on SERVER having an IPv6 of 2001:db8:85a3:8d3:1319:8a2e:370:7348, but your WINS fails, then you can use it in an UNC path like this:

\\2001-db8-85a3-8d3-1319-8a2e-370-7348.ipv6-literal.net\MYSHARE

Thanks to this part of the IPv6 addresses article on Wikipedia:

Literal IPv6 addresses in UNC path names

In Microsoft Windows operating systems, IPv4 addresses are valid location identifiers in Uniform Naming Convention (UNC) path names. However, the colon is an illegal character in a UNC path name. Thus, the use of IPv6 addresses is also illegal in UNC names. For this reason, Microsoft implemented a transcription algorithm to represent an IPv6 address in form of a domain name that can be used in UNC paths. For this purpose, Microsoft registered and reserved the second-level domain ipv6-literal.net on the Internet. IPv6 addresses are transcribed as a hostname or subdomain name within this name space, in the following fashion:

2001:db8:85a3:8d3:1319:8a2e:370:7348

is written as

2001-db8-85a3-8d3-1319-8a2e-370-7348.ipv6-literal.net

This notation is automatically resolved by Microsoft software without any queries to DNS name servers. If the IPv6 address contains a zone index, it is appended to the address portion after an ‘s’ character:

fe80--1s4.ipv6-literal.net

–jeroen

via: IPv6 address – Wikipedia, the free encyclopedia.

Posted in Microsoft Surface on Windows 7, Power User, Windows, Windows 7, Windows 8, Windows Vista | Leave a Comment »

SQL Server quick tip by Denis Gobo: use DBCC SHOWCONTIG for Min/Max/Average row sizes (via: sql server – Size of a single Record ? SQL – Stack Overflow)

Posted by jpluimers on 2012/11/22

Thanks SQLMenace (Denis Gobo) for this great tip on getting min/max/average row sizes (and more) using DBCC SHOWCONTIG.

Don’t forget the “with tableresults”, without it, it will skip the min/max/average recordsize from the results, and present the results as text (not as a row).

 

 

Run DBCC SHOWCONTIG with your table name

dbcc showcontig ('TableName') with tableresults

then look at max min and average record size

This feature works at least from SQL Server 2000 onward, though somewhere after SQL Server 2012 it will be removed.
As of SQL Server 2005 you can use sys.dm_db_index_physical_stats. An example on how to use that is here.

It just made me shiver when finding out an unindexed table with 9 million rows averaging about 300 bytes took 8 minutes to query.
Time to add some indexes, and have someone look at the disk back-end.

–jeroen

via: sql server – Size of a single Record ? SQL – Stack Overflow.

Posted in Database Development, Development, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 | Leave a Comment »

.NET/C# LINQ gem: How to check if a char in a list of characters (via Stack Overflow)

Posted by jpluimers on 2012/11/21

Often when comparing characters with a list of characters, that list does not consist of consts.

It if were, you could make a switch statement:

                    switch (item)
                    {
                        case '/':
                        case '\\':
                        case ';':
                            addSeparator(separatorsUsed, item);
                            break;
                    }

But reality is that you cannot do things like this:

                    switch (item)
                    {
                        case Path.AltDirectorySeparatorChar: // Error: A constant value is expected
                        case Path.DirectorySeparatorChar:
                        case Path.PathSeparator:
                            addSeparator(separatorsUsed, item);
                            break;
                    }

However, you can perform a small trick and use LINQ to write some pretty elegant code based on Contains.

                    char[] pathSeparators = { Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar, Path.PathSeparator };
                    // LINQ: http://stackoverflow.com/questions/1818611/how-to-check-if-a-char-in-a-char-array/1818635#1818635
                    if (pathSeparators.Contains(item))
                        addSeparator(separatorsUsed, item);

The LINQ logic has the logic backwards (you can think of it like “item in pathSeparators”, but it is far easier to read than this:

                    if ((item == Path.AltDirectorySeparatorChar) || (item == Path.DirectorySeparatorChar) || (item == Path.PathSeparator))
                        addSeparator(separatoseparatorsUsedrsInUse, item);

Full source of a demo application: Read the rest of this entry »

Posted in .NET, .NET 3.5, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, Development, LINQ, Software Development, Visual Studio 11, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | 2 Comments »