Tuesday, June 28, 2011

How can Visual Studio search and replace be so utterly broken ?

I have the thankless task of editing a ton of HTML files. I have a bunch of URLs that all have different IDs, but I want to point to the same place. So, I investigated regex searching in VS. Well, the regex was easy, and the search found all my strings. Replace, however, leaves the regex section behind. My search was s=c&vl=vlg&vi=\d*, and it would replace s=c&vl=vlg&vi= and leave my digits behind.

Some googling told me that VS has it's own Regex syntax ( although using standard syntax WAS matching my strings ), so I tried that. Still no dice, I get matches, but it won't replace the bit matched by regex. I am unsure what the point of that is.

So, I decided to try wildcards. s=c&vl=vlg&vi=#* works perfectly, it searches AND replaces. So, I showed it to friends I'd been asking for help with the regex. Some guy says 'but you always want there to be a number, * is zero or more'. I KNOW I was reading MSDN, so I grab the entry to prove him wrong. Here is the text from MSDN:

One or more characters * Matches zero or more characters. For example, new* matches any text that includes "new", such as newfile.txt.

So, is it one or more, or zero or more ? It's one or more. But, I had to test, because the documentation contradicts itself. How very helpful.

Saturday, April 23, 2011

WPF loves to divide by zero

Ignoring for a moment how worthless the WPF designer is ( and I've not tried the VS2010 one b/c VS2010 is so slow and buggy that I don't want to move my projects there ), it seems like at random points, my large WPF project will compile, and fail to run, with a divide by zero error at the root of the project, in the App class. Rebuilding will fix it, there's never a bug in my code.

Wednesday, April 20, 2011

string.Split

There is no question that, compared to C++, C# makes working with strings a lot easier. However, some things still don't make sense. I have used the split method on the string class countless times. I could count on one hand the number of times I had more than one argument to split by. Why is there no overload that takes a single string or char, and doesn't force me to write code that creates a single element array inline so I can satisfy the method signature requirements ?

A little thing...

When I create a new project in VS, it gives me two textboxes, one for a project name, and one for a folder. If I type in to the folder textbox, it autocompletes based on paths that exist. This is nice. When I get a list of folders that exist, if I select one and press 'enter', the OK button gets triggered and 'WindowsFormApp1' gets created in the location I chose. Surely the fact that it's the default, useless name, is a clue that I was entering the path first ?

Wednesday, March 23, 2011

MVC bread crumbs

Wow, is it a year since I posted here ? I just gave up posting, I still find things broken in MS products every day. At the moment I am working on an MVC website in VS 2010. The fun thing is that VS2010's web server blue screens my PC about 8 times a day. But that's not what I wanted to say. In MVC, there's XML files to set up site maps and related pages. These can then be iterated over to create links to related pages, and breadcrumbs. That's kind of groovy, although having to synch up a lot of XML files or your site blows up is very Javabeans IMO.

Now, we all know that XML is case sensitive. So, what does this mean ? It means when I create my own links to my pages in my site, if I don't get the case right, these features do not work. That's right - my pages render with no links to related pages and no bread crumbs. In other words, Microsoft have succeeded in making URLs case sensitive. Well done, Microsoft !!!

Tuesday, May 4, 2010

Context menus

So, I have a ton of database connections in VS2008, because they are all SQLite databases. I can right click on one and delete it. If I select more than one, the right click menu is gone. Why can't I select all my random DB files and delete the connections at once ? The DEL key also did not work, if there's a way to do it, I didn't see it.

Friday, April 30, 2010

Random properties in WPF UI Elements

So, in WPF, I have some tool windows showing. I want to only show one at a time. I want when I show one, to hide the others. And, when I show one, I want it to go to the last position it had. Seems simple enough. My windows are all borderless, so I have a button for dragging and I use the DragMove() method to make that all work. So, if you click the button within a certain timeframe, it toggles hide/show, otherwise it calls DragMove, which does the rest for you.

The issue is that DragMove allows you to move the window, but when you're done, it has the old Left/Top values. In other words, the values in the control are not tied to what they represent, they are free agents that sometimes get updated when the control moves, but not always. This reminds me of what I realised the 'Width' and 'Height' properties are provided for some sort of joke, and the ActualWidth and ActualHeight ones are needed ( because the Width is not the ActualWidth, right ? ). I suspect this has something to do with the half cocked move to respecting DPI settings, but I'm not sure, I just know I've never needed or found the Width or Height property to be worth anything.

So, I try to track the mouse to keep the values stored myself. Well, it turns out the the methods in WPF to get the mouse position do not work during a drag operation. So, the whole thing is useless. I needed to p/invoke GetCursorPos, then track for myself my left and top positions on the basis that WPF is incapable of doing so. It works nicely now. I should add, the Left and Top are settable, which is obvious ( so you can move a window ), but useful to me now, because I can tell it where it is, as it plainly does not know. And the fact my windows do not move at ALL when I lift my mouse is a good double check that the values I calculated are correct, unlike the ones WPF tracks.