<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-7916618003572713740</atom:id><lastBuildDate>Thu, 08 Apr 2010 18:29:07 +0000</lastBuildDate><title>Paul Maddox</title><description>Software development team leader specialising in Microsoft Visual C# and C++ from the Northwest of England.

Experience working in a globalised business and team; understanding of enterprise business operation and practices; experience reporting to executive management

Skills in numerous languages and technologies; knowledge of formal software development lifecycle; experience of architecture design</description><link>http://paulmaddox.net/</link><managingEditor>noreply@blogger.com (.)</managingEditor><generator>Blogger</generator><openSearch:totalResults>43</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-8567470191840398167</guid><pubDate>Sun, 21 Mar 2010 11:17:00 +0000</pubDate><atom:updated>2010-03-21T04:21:12.728-07:00</atom:updated><title>T-SQL Parameterized SELECT TOP @N</title><description>&lt;p&gt;If you wanted to select the TOP N rows from a table based on a stored procedure parameter you would likely have tried:&lt;/p&gt;&lt;p&gt;SELECT TOP @N * FROM MyTable&lt;/p&gt;&lt;p&gt;Having come across the error:&lt;/p&gt;&lt;p&gt;Incorrect syntax near '@N'&lt;/p&gt;&lt;p&gt;You would next have hit google and, like me, found a lot of FUD surrounding performing what you would think would be a relatively simple operation.  You would have found talk about dynamic SQL, and no doubt all kinds of other hacks to get around it.  However, from SQL 2005, you can do this:&lt;/p&gt;&lt;p&gt;SELECT TOP (@N) * FROM MyTable&lt;/p&gt;&lt;p&gt;It's as simple as that.  Another good example where the highest ranked result isn't necessarily the right one.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-8567470191840398167?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2010/03/t-sql-parameterized-select-top-n.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-1236695564994208233</guid><pubDate>Fri, 26 Feb 2010 20:34:00 +0000</pubDate><atom:updated>2010-02-26T12:34:03.357-08:00</atom:updated><title>Office 2007 – has its uses?</title><description>&lt;span xmlns=''&gt;&lt;p&gt;I've come across a lot of derision for Office 2007.  Why have Microsoft completely changed the menu; what do the XML formats offer; isn't this just showing that Office has nowhere useful to go and you may as well use Open Office?&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I've been using Office 2007 since the end of 2007 as our IT dept very quickly moved to Office 2007 (even though the rest of the business is using 2003 still, due to corporate requirements).  It took a good while before I got used to the menu ribbons, and each of my team spent time staring at their screen wondering how to do what with 2003 was a trivial task.  (Editing footer elements in a PowerPoint master page, for example.)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Over two years on since I began using it, I recently went back to Office 2003, and you know what – I couldn't find anything.  Changing page orientation, which is two clicks with 2007 is a nightmare to get to with 2003.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Those suggesting using OpenOffice because it looks like Office 2003 are really missing the point.  Whether you can immediately use it or not, Office 2007 has made usability improvements.   It's just a matter of getting used to them.  In a way Microsoft did take a big risk in making the change, but suggesting users use OpenOffice just because it's similar to Office 2003 really isn't the solution.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;And another thing – Word 2007 supports common blogging platforms – including Blogger used for this post.  Nice touch.&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-1236695564994208233?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2010/02/office-2007-has-its-uses.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-5806706935977551148</guid><pubDate>Tue, 01 Sep 2009 10:49:00 +0000</pubDate><atom:updated>2009-09-01T04:12:00.109-07:00</atom:updated><title>Twitter's Impending Doom: Apps and Games</title><description>Do you have that one annoying twitizen in your following list who talks jibberish all the time?  Do you wish you could politely filter some/all of their tweets without blocking them entirely?  Well, you can't.  But don't worry, things are going to get a whole lot worse.&lt;br /&gt;&lt;br /&gt;Twitter, by its very nature, treats all tweets equally.  That's great, under the assumption all tweets are created equally.  Unfortunately, apps like Twibbon, which trade a small service (adding a tiny graphic onto your profile pic) in exchange for an automated tweet from your account, change that, and they are only the tip of the iceberg.&lt;br /&gt;&lt;br /&gt;Soon I predict a whole ecosystem of Twitter apps and games vying for access to your precious account login, and it will result in one thing: massive increase in twitter noise.  (And you thought just having tweets your friends &lt;span style="font-weight: bold;"&gt;write&lt;/span&gt; is bad enough.)  App invitations, quiz results, and spam, will all become part of your daily twitter traffic.&lt;br /&gt;&lt;br /&gt;FaceBook apps and games, whether you love them or hate them, have two redeeming features: (1) you can block invitations for them, and (2) they are prohibited by FaceBook from forcing you to spam your friends (by, for instance, only allowing you access to the results of a quiz by spamming 10 of your friends).&lt;br /&gt;&lt;br /&gt;Pretty soon Twitter will have to start factoring in recipient-based filtering of tweets depending on the origin app, and I don't believe Twitter will be able to move fast enough, with such enormous tweet volumes, to stem the tide.  Without that, Twitter will quickly reach lowest-common-denominator proportions, and users will simply move on.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-5806706935977551148?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2009/09/twitters-impending-doom-apps-and-games.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-6981830912946271572</guid><pubDate>Fri, 15 May 2009 08:10:00 +0000</pubDate><atom:updated>2009-05-15T01:14:24.274-07:00</atom:updated><title>What happens if a statement fails in a SQL Server stored procedure?</title><description>Answer: it carries on regardless!  In other words: if you want a stored proc to specifically stop upon error, test for it and return.&lt;br /&gt;&lt;br /&gt;Take this example:&lt;br /&gt;&lt;br /&gt;CREATE TABLE [dbo].[PaulTest](&lt;br /&gt;     [Number] [int] NOT NULL&lt;br /&gt;) ON [PRIMARY]&lt;br /&gt;&lt;br /&gt;CREATE PROCEDURE uspPaulTest AS&lt;br /&gt;BEGIN&lt;br /&gt;     INSERT INTO PaulTest (Number) VALUES (NULL) -- fails as NULL is invalid&lt;br /&gt;     INSERT INTO PaulTest (Number) VALUES(1) -- still gets processed as the query doesn't return&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;-- Let's test it:&lt;br /&gt;&lt;br /&gt;SELECT * FROM PaulTest&lt;br /&gt;&lt;br /&gt;EXEC uspPaulTest&lt;br /&gt;&lt;br /&gt;SELECT * FROM PaulTest&lt;br /&gt;&lt;br /&gt;-- Output:&lt;br /&gt;&lt;br /&gt;Number&lt;br /&gt;-----------&lt;br /&gt;(0 row(s) affected)&lt;br /&gt;&lt;br /&gt;Msg 515, Level 16, State 2, Procedure uspPaulTest, Line 10&lt;br /&gt;Cannot insert the value NULL into column 'Number', table 'Test.dbo.PaulTest'; column does not allow nulls. INSERT fails.&lt;br /&gt;The statement has been terminated.(1 row(s) affected)&lt;br /&gt;&lt;br /&gt;Number&lt;br /&gt;-----------&lt;br /&gt;1&lt;br /&gt;(1 row(s) affected)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-6981830912946271572?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2009/05/what-happens-if-statement-fails-in-sql.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-4742355357902292311</guid><pubDate>Wed, 22 Apr 2009 17:19:00 +0000</pubDate><atom:updated>2009-04-22T10:19:58.682-07:00</atom:updated><title>Visual Studio 2008 Errors</title><description>&lt;p&gt;Recently I had my VS 2008 RTM/RC installation go pear shaped. Overnight I stopped being able to create VC++ smartdevice projects with the error&lt;/p&gt; &lt;p&gt;“Creating Project '&amp;lt;ProjectName&amp;gt;'... project creation failed”&lt;/p&gt; &lt;p&gt;‘No problem’, I thought, ‘I’ll just run setup and do a repair’.&amp;nbsp; Unfortunately, I got an error with the setup of&lt;/p&gt; &lt;p&gt;“A problem has been encountered while loading the setup components. Canceling setup.”&lt;/p&gt; &lt;p&gt;Luckily I came across a &lt;a href="http://stackoverflow.com/questions/114332/visual-studio-setup-problem-a-problem-has-been-encountered-while-loading-the-s" target="_blank"&gt;post on StackOverflow&lt;/a&gt; (which is running turning out to be a useful resource from the author of &lt;a href="http://www.codinghorror.com" target="_blank"&gt;CodingHorror.com&lt;/a&gt;) pointing to a Microsoft tool to ‘force’ uninstall various Microsoft products, including Visual Studio:&lt;/p&gt; &lt;p&gt;&lt;a title="http://msdn.microsoft.com/en-us/vstudio/bb968856.aspx" href="http://msdn.microsoft.com/en-us/vstudio/bb968856.aspx"&gt;http://msdn.microsoft.com/en-us/vstudio/bb968856.aspx&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://paulmaddox.net/writerpics/VisualStudio2008Errors_10188/image.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://paulmaddox.net/writerpics/VisualStudio2008Errors_10188/image_thumb.png" width="244" height="203"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-4742355357902292311?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2009/04/visual-studio-2008-errors.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-7627159016131473151</guid><pubDate>Tue, 21 Apr 2009 19:44:00 +0000</pubDate><atom:updated>2009-04-21T12:44:50.342-07:00</atom:updated><title>SQL Server 2008 Truncating Log File</title><description>&lt;p&gt;First find the filename labels for your database:  &lt;p&gt;&lt;strong&gt;select name from &amp;lt;DatabaseName&amp;gt;.dbo.sysfiles&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Next truncate the log:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;BACKUP LOG &amp;lt;DatabaseName&amp;gt; WITH TRUNCATE_ONLY&lt;/strong&gt;  &lt;p&gt;Finally shrink the database based on the log file in step 1:  &lt;p&gt;&lt;strong&gt;DBCC SHRINKFILE('NameAbove_log',2048)&lt;/strong&gt;  &lt;p&gt;2048 is the resultant file size in MB.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-7627159016131473151?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2009/04/sql-server-2008-truncating-log-file.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-1056595336563583275</guid><pubDate>Tue, 21 Apr 2009 19:39:00 +0000</pubDate><atom:updated>2009-04-21T12:40:08.663-07:00</atom:updated><title>Screen Real Estate Wastage</title><description>&lt;p&gt;Usually I’m a fan of Microsoft UI design, however having installed the latest version of Windows Live Messenger (or more accurately had it forced on me) I’m astounded by the amount of screen real estate squandered.&amp;nbsp; Clearly Microsoft have been buying too many 24” monitors.&amp;nbsp; After turning off as much of the unneeded fluff as possible I was still left with a window far larger than necessary, with no real benefit.&amp;nbsp; See below!&lt;/p&gt; &lt;p&gt;&lt;a href="http://paulmaddox.net/writerpics/ScreenRealEstateWastage_1216F/image.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://paulmaddox.net/writerpics/ScreenRealEstateWastage_1216F/image_thumb.png" width="226" height="244"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-1056595336563583275?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2009/04/screen-real-estate-wastage.html</link><author>noreply@blogger.com (.)</author><thr:total>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-8824611157802674244</guid><pubDate>Tue, 21 Apr 2009 12:07:00 +0000</pubDate><atom:updated>2009-05-15T07:38:19.010-07:00</atom:updated><title>SQL Quiz of the Day</title><description>&lt;pre&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;br /&gt;Let’s say you have raw data as so:&lt;br /&gt;&lt;br /&gt;Id          Counter     Ident&lt;br /&gt;----------- ----------- -----&lt;br /&gt;1           1           A&lt;br /&gt;2           2           A&lt;br /&gt;3           1           A&lt;br /&gt;4           3           B&lt;br /&gt;5           3           B&lt;br /&gt;6           2           A&lt;br /&gt;7           1           A&lt;br /&gt;8           4           C&lt;br /&gt;9           2           C&lt;br /&gt;10          1           B&lt;br /&gt;11          1           B&lt;br /&gt;12          4           B&lt;br /&gt;&lt;br /&gt;And you want to group by the Ident field, but&lt;br /&gt;only contiguous blocks.  So you want to display&lt;br /&gt;the following:&lt;br /&gt;&lt;br /&gt;Counter     Ident&lt;br /&gt;----------- -----&lt;br /&gt;4           A&lt;br /&gt;6           B&lt;br /&gt;3           A&lt;br /&gt;6           C&lt;br /&gt;6           B&lt;br /&gt;&lt;br /&gt;Naturally one can’t use GROUP BY, because this would&lt;br /&gt;aggregate multiple A’s and B’s.&lt;br /&gt;&lt;br /&gt;Answers on a postcard!&lt;br /&gt;&lt;br /&gt;====&lt;br /&gt;&lt;br /&gt;CREATE TABLE [dbo].[Test](&lt;br /&gt;        [Id] [int] IDENTITY(1,1) NOT NULL,&lt;br /&gt;        [Counter] [int] NOT NULL,&lt;br /&gt;        [Ident] [varchar](3)&lt;br /&gt;         COLLATE Latin1_General_CI_AS NOT NULL,&lt;br /&gt; CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED&lt;br /&gt;(&lt;br /&gt;        [Id] ASC&lt;br /&gt;)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]&lt;br /&gt;) ON [PRIMARY]&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-8824611157802674244?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2009/04/sql-quiz-of-day.html</link><author>noreply@blogger.com (.)</author><thr:total>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-1071376617410098228</guid><pubDate>Mon, 20 Apr 2009 20:27:00 +0000</pubDate><atom:updated>2009-04-20T13:29:44.435-07:00</atom:updated><title>MaddogTCP network TCP/IP fuzzer</title><description>A while ago - almost three years in fact - I wrote a fuzzer to test network security of TCP/IP connections.  Due to one reason and another I never really released it, and despite being published on the net it was hidden from Google, and hence remained undiscovered.&lt;br /&gt;&lt;br /&gt;Looking back, it was a reasonably succinct little program that deserves the light of day, so here it is:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.calcaria.net/MaddogTCP/"&gt;http://www.calcaria.net/MaddogTCP/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-1071376617410098228?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2009/04/maddogtcp-network-tcpip-fuzzer.html</link><author>noreply@blogger.com (.)</author><thr:total>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-2467149185228896569</guid><pubDate>Wed, 08 Apr 2009 20:16:00 +0000</pubDate><atom:updated>2009-05-15T07:39:59.667-07:00</atom:updated><title>Generic type parser using Generics C# .NET</title><description>&lt;p&gt;Recently I had the need to safely parse multiple types from text ignoring exceptions. Microsoft did not implement an IParsable interface (despite requests) so I thought a solution was crying out for using generics.&lt;/p&gt;&lt;p&gt;The concept was simple: pass in an object of type T and call T.Parse.  The .NET compiler can check at compile time that the type supports Parse, right?  Unfortunately not.  Although generics allows constraints such as new(), it does not support arbitrary method constraints.&lt;/p&gt;&lt;p&gt;Lack of method constraints means attempting to call T.Parse won't work.  The result is having to use reflection to get around this.  Of course passing in a type that does not support Parse will  throw an exception, but by virtue of the design this will be handled and the type will return the default.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;private T SafeParseAndAssign&amp;lt;T&amp;gt;(string val)&lt;br /&gt;  where T : new()&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;  T ValOut = new T();&lt;br /&gt;&lt;br /&gt;  MethodInfo MI = ValOut.GetType().&lt;br /&gt;    GetMethod("Parse", new Type[] { val.GetType() });&lt;br /&gt;&lt;br /&gt;  return (T)MI.Invoke(ValOut, new object[] { val });&lt;br /&gt;}&lt;br /&gt;catch&lt;br /&gt;{&lt;br /&gt;  // swallow exception&lt;br /&gt;}&lt;br /&gt;return default(T);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-2467149185228896569?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2009/04/generic-type-parser-using-generics-c.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-7131025347367091030</guid><pubDate>Tue, 30 Dec 2008 15:55:00 +0000</pubDate><atom:updated>2008-12-30T08:00:58.748-08:00</atom:updated><title>TinyHomepage - icon based favourites web app</title><description>My latest venture - an icon based favourites web app for mobile phones. Feedback gratefully received.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://tinyhomepage.com/" target="_blank"&gt;TinyHomepage.com&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="http://tinyhomepage.com/TinyHomepageScreenshot.png" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="http://tinyhomepage.com/TinyHomepageScreenshotWM1.png" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="http://tinyhomepage.com/TinyHomepageScreenshotWM2.png" /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-7131025347367091030?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/12/tinyhomepage-icon-based-favourites-web.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-2870208767798022211</guid><pubDate>Tue, 23 Dec 2008 12:30:00 +0000</pubDate><atom:updated>2008-12-23T04:35:18.326-08:00</atom:updated><title>.NET GetTempFileName throws System.IO.IOException: The file exists</title><description>Getting an exception System.IO.IOException: The file exists when calling GetTempFileName?  I had this problem with a legacy app, despite the call working fine on nearly all of our systems.  It turns out the temp directory had been filling with temp files and eventually went bang.  From the MSDN:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;                     The &lt;span&gt;&lt;span class="selflink"&gt;GetTempFileName&lt;/span&gt;&lt;/span&gt; method will raise an &lt;span&gt;&lt;a id="ctl00_rs1_mainContentContainer_ctl32" onclick="javascript:Track('ctl00_rs1_mainContentContainer_cpe873965_c|ctl00_rs1_mainContentContainer_ctl32',this);" href="http://msdn.microsoft.com/en-us/library/system.io.ioexception.aspx"&gt;IOException&lt;/a&gt;&lt;/span&gt; if it is used to create more than 65535 files without deleting previous temporary files.                 &lt;/li&gt;&lt;li&gt;                     The &lt;span&gt;&lt;span class="selflink"&gt;GetTempFileName&lt;/span&gt;&lt;/span&gt; method will raise an &lt;span&gt;&lt;a id="ctl00_rs1_mainContentContainer_ctl33" onclick="javascript:Track('ctl00_rs1_mainContentContainer_cpe873965_c|ctl00_rs1_mainContentContainer_ctl33',this);" href="http://msdn.microsoft.com/en-us/library/system.io.ioexception.aspx"&gt;IOException&lt;/a&gt;&lt;/span&gt; if no unique temporary file name is available. To resolve this error, delete all unneeded temporary files.                 &lt;/li&gt;&lt;/ul&gt;Simple really.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-2870208767798022211?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/12/net-gettempfilename-throws.html</link><author>noreply@blogger.com (.)</author><thr:total>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-8562090274957855534</guid><pubDate>Mon, 17 Nov 2008 21:21:00 +0000</pubDate><atom:updated>2008-11-17T13:23:30.819-08:00</atom:updated><title>C# .NET Image Manipulation Resize + Grayscale + TIFF</title><description>Code from the last three posts can be downloaded formatted properly here:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://paulmaddox.net/BlogFiles/ImageManipulation_Program.cs.txt"&gt;http://paulmaddox.net/BlogFiles/ImageManipulation_Program.cs.txt&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Note you need to add the System.Drawing reference in order to get it to work with a new project.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-8562090274957855534?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/11/c-net-image-manipulation-resize.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-5947735267855099559</guid><pubDate>Mon, 17 Nov 2008 21:10:00 +0000</pubDate><atom:updated>2008-11-17T13:17:15.779-08:00</atom:updated><title>Convert C# .NET Bitmap to grayscale</title><description>Here's some code to convert a Bitmap into grayscale using luminance.  Note, this does not change the color depth, rather it sets the pixels to grey within a 24bit color space.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-family:courier new;"&gt;private static Bitmap ToGrayscale(Bitmap bmIn)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;Bitmap bmOut = new Bitmap(bmIn.Width, bmIn.Height, PixelFormat.Format24bppRgb);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;for (int x = 0; x &amp;lt; bmIn.Width; x++)&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;for (int y = 0; y &amp;lt; bmIn.Height; y++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Color px = bmIn.GetPixel(x, y);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;int luminance = (int)((0.3f * px.R) + (0.59 * px.G) + (0.11 * px.B));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;bmOut.SetPixel(x, y, Color.FromArgb(luminance, luminance, luminance));&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;return bmOut;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-5947735267855099559?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/11/convert-c-net-bitmap-to-grayscale.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-7009836448997450306</guid><pubDate>Mon, 17 Nov 2008 21:04:00 +0000</pubDate><atom:updated>2008-11-17T13:09:20.163-08:00</atom:updated><title>C# .NET reading a bitmap, resizing / rescaling and saving as a TIFF</title><description>Here's some code to read in a bitmap and save a new bitmap at a quarter of the size.  Note. a boilerplate method is needed to get the encoder for the write format.  This makes it easy to change from TIFF to JPEG, PNG, etc.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;// Load the bitmap from first argument filename&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Bitmap bmIn = new Bitmap(inputFilename);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;// Create a new bitmap from the first, scaling down as we go&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Bitmap bmOut = new Bitmap(bmIn, new Size(bmIn.Width/2, bmIn.Height/2));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;// Create an parameter set that we use to save the file&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;EncoderParameters encParams = new EncoderParameters(3);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;// Set some parameters&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; encParams.Param[0] = new EncoderParameter(Encoder.ColorDepth, 24L);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;encParams.Param[1] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionNone);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;encParams.Param[2] = new EncoderParameter(Encoder.SaveFlag, (long)EncoderValue.MultiFrame);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;// Save bitmap to second argument filename&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;bmOut2.Save(outputFilename, GetEncoder(ImageFormat.Tiff), encParams);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;private static ImageCodecInfo GetEncoder(ImageFormat format)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   foreach (ImageCodecInfo codec in codecs)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      if (codec.FormatID == format.Guid)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;         return codec;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   return null;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;}&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-7009836448997450306?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/11/c-net-reading-bitmap-resizing-rescaling.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-1066021609459136135</guid><pubDate>Mon, 17 Nov 2008 20:52:00 +0000</pubDate><atom:updated>2008-11-17T13:04:22.181-08:00</atom:updated><title>Out of Memory / OutOfMemoryException on Graphics.FromImage with PixelFormat.Format16bppArgb1555 or PixelFormat.Format16bppGrayScale</title><description>If you have some code like this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Bitmap bmp = new Bitmap(100,100, PixelFormat.Format16bppArgb1555);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Graphics gfx = Graphics.FromImage(bmp);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You will find you get an out of memory exception upon executing the code.  The reason?  .NET does not actually support &lt;span style="font-weight: bold;"&gt;Format16bppArgb1555 &lt;/span&gt;or &lt;span style="font-weight: bold;"&gt;PixelFormat.Format16bppGrayScale&lt;/span&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-1066021609459136135?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/11/out-of-memory-outofmemoryexception-on.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-2022634613133491204</guid><pubDate>Wed, 05 Nov 2008 12:45:00 +0000</pubDate><atom:updated>2008-12-23T04:50:31.901-08:00</atom:updated><title>Visual Studio Errors</title><description>Thanks to Matt at Siemens for this one.&lt;br /&gt;&lt;br /&gt;"If you get similar errors to below then deleting everything in the C:\Documents and Settings\&lt;user&gt;\Local Settings\Application Data\Microsoft\VisualStudio\&lt;vs&gt;\ProjectAssemblies will solve this. Do not delete anything above this directory as you will lose all your toolbars and settings."&lt;br /&gt;&lt;br /&gt;Error   4       The "ResolveAssemblyReference" task failed unexpectedly.&lt;br /&gt;&lt;br /&gt;System.IO.IOException: Incorrect function.&lt;br /&gt;&lt;br /&gt;  at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)&lt;br /&gt;&lt;br /&gt;  at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption)&lt;br /&gt;&lt;br /&gt;  at System.IO.Directory.GetDirectories(String path, String searchPattern, SearchOption searchOption)&lt;br /&gt;&lt;br /&gt;  at System.IO.Directory.GetDirectories(String path, String searchPattern)&lt;br /&gt;&lt;br /&gt;  at Microsoft.Build.Tasks.SystemState.GetDirectories(String path, String pattern)&lt;br /&gt;&lt;br /&gt;  at Microsoft.Build.Tasks.ReferenceTable.FindSatellites(Reference reference)&lt;br /&gt;&lt;br /&gt;  at Microsoft.Build.Tasks.ReferenceTable.FindAssociatedFiles()&lt;br /&gt;&lt;br /&gt;  at Microsoft.Build.Tasks.ReferenceTable.ComputeClosure()&lt;br /&gt;&lt;br /&gt;  at Microsoft.Build.Tasks.ReferenceTable.ComputeClosure(DependentAssembly[] remappedAssembliesValue, ITaskItem[] referenceAssemblyFiles, ITaskItem[] referenceAssemblyNames, ArrayList exceptions)&lt;br /&gt;&lt;br /&gt;  at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute(FileExists fileExists, DirectoryExists directoryExists, GetDirectories getDirectories, GetAssemblyName getAssemblyName, GetAssemblyMetadata getAssemblyMetadata, GetRegistrySubKeyNames getRegistrySubKeyNames, GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue, GetLastWriteTime getLastWriteTime)&lt;br /&gt;&lt;br /&gt;  at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute()&lt;br /&gt;&lt;br /&gt;  at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean&amp;amp; taskResult)   MyProject&lt;br /&gt;&lt;/vs&gt;&lt;/user&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-2022634613133491204?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/11/visual-studio-errors.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-9048684480541405225</guid><pubDate>Thu, 28 Aug 2008 19:13:00 +0000</pubDate><atom:updated>2008-08-28T12:28:17.660-07:00</atom:updated><title>Encrypting ASP.NET web.config impersonation data</title><description>It always irked me that using impersonate for my ASP.NET web apps meant I had to expose the username and password in plain text.  Eg./&lt;br /&gt;&lt;br /&gt;&amp;lt;identity impersonate="true" username="BOB" password="NOTSOSECRET"&amp;gt;&lt;br /&gt;&lt;br /&gt;Luckily it irked someone at Microsoft too and they came out with a hotfix allowing the credentials to be stored in encrypted form in the registry.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://support.microsoft.com/kb/329290"&gt;http://support.microsoft.com/kb/329290&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-9048684480541405225?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/08/encrypting-aspnet-webconfig.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-7519401520835294591</guid><pubDate>Fri, 30 May 2008 14:01:00 +0000</pubDate><atom:updated>2008-05-30T07:06:22.436-07:00</atom:updated><title>Microsoft Source Analysis</title><description>Microsoft have released their previously internal tool Source Analysis (aka StyleCop). This allows project- and file- level source code analysis checking it meets a whole raft of style rules developed by Microsoft. Some you will agree with, some you won't. The good news is you can turn off rules you don't like, the bad news is you cannot develop your own.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blogs.msdn.com/sourceanalysis/archive/2008/05/23/announcing-the-release-of-microsoft-source-analysis.aspx"&gt;blogs.msdn.com&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-7519401520835294591?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/05/microsoft-source-analysis.html</link><author>noreply@blogger.com (.)</author><thr:total>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-7804261974498654557</guid><pubDate>Thu, 27 Mar 2008 12:33:00 +0000</pubDate><atom:updated>2008-11-17T13:26:23.851-08:00</atom:updated><title>Visual Studio 2008 IDE C# - UK Launch Notes</title><description>&lt;ul&gt;&lt;li&gt;VS08 allows seamless (re)targeting of apps to .NET 2.0, 3.0 and 3.5. This provides graceful upgrading of existing applications. Applications initially targeted for 3.x can also be targeted to .NET 2.0 as long as features of 3.x have not been used.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Properties have now been improved so the implementation of the get and set methods do not need to be provided if the default implementation is all that is required. Eg./&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public string FirstName { get; set; }&lt;/pre&gt;This creates a hidden private member variable.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;It is now possible to use braces to initialise multiple object properties:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;Thread myThread = new Thread(MyThreadMethod)&lt;br /&gt;{&lt;br /&gt;Name="my thread",&lt;br /&gt;IsBackground=true&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;Anonymous types can be created using the 'var' keyword. This is NOT weak typing - C# knows what the type is and it cannot change. Anonymous types are used in instances where the developer does not know the type, the primary instance of this being LINQ. Eg./&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;var anonobject = new {Name = "Bob", Age = "40"};&lt;br /&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;Anonymous methods are best described in detail here:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/04/05/C20/#S5"&gt;http://msdn.microsoft.com/msdnmag/issues/04/05/C20/#S5&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Partial methods can be used as a lightweight event system in cases where a large number of objects are held in memory (IE. LINQ) or where the method may be optionally implemented. Eg./&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;partial class MyClass&lt;br /&gt;{&lt;br /&gt;MyClass()&lt;br /&gt;{&lt;br /&gt; DisplayMessage(); // Only called if definition exists&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;static partial DisplayMessage(); // Not implemented&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;partial class MyClass&lt;br /&gt;{&lt;br /&gt;static partial DisplayMessage() // Optional&lt;br /&gt;{&lt;br /&gt; Console.WriteLine("MyClass created");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;Extension methods allow you to 'tack on' functionality to classes that you would otherwise not be able to due to inheritance being prevented (IE. .NET classes). Eg./&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public static class MyExtensions&lt;br /&gt;{&lt;br /&gt;public static bool&lt;br /&gt;  IsValidEmailAddress(this string s) // "this" keyword&lt;br /&gt;{&lt;br /&gt; Regex regex =&lt;br /&gt;  new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");&lt;br /&gt; return regex.IsMatch(s);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class MyClass&lt;br /&gt;{&lt;br /&gt;public void MyMethod()&lt;br /&gt;{&lt;br /&gt; string email = "paul@here.com";&lt;br /&gt;&lt;br /&gt; // Extension method used like a standard string method&lt;br /&gt; if (email.IsValidEmailAddress())&lt;br /&gt; {&lt;br /&gt;  Console.WriteLine("Valid!");&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-7804261974498654557?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/03/visual-studio-2008-ide-c-uk-launch.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-5672689601356208363</guid><pubDate>Thu, 27 Mar 2008 08:12:00 +0000</pubDate><atom:updated>2008-03-27T01:12:30.930-07:00</atom:updated><title>C# Programming - Part 2 - Conditions</title><description>&lt;span style="font-size:180%;"&gt;Scope of work&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The work is split into two parts: the first is a training part where you are encouraged to use books and the Internet to help you complete the questions; the second is a test part where you should complete the questions with no external help. The pass score is 80%.&lt;br /&gt;&lt;br /&gt;1. if, else if, else&lt;br /&gt;&lt;br /&gt;2. Nested conditions&lt;br /&gt;&lt;br /&gt;3. &amp;amp;&amp;amp; and&lt;br /&gt;&lt;br /&gt;4. switch statement&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Training Questions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create console applications to:&lt;br /&gt;&lt;br /&gt;1. Read a number from the console (use ReadLine and Int32.Parse) and using if, else if and else output one of the following&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;“The number is negative”&lt;br /&gt;&lt;br /&gt;“The number is lower than 100”&lt;br /&gt;&lt;br /&gt;“The number is 100 or above”&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;2. Read two numbers from the console (one after the other) and by nesting if, else if and else output one of the following:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;“The numbers are the same”&lt;br /&gt;&lt;br /&gt;“The numbers are not the same”&lt;br /&gt;&lt;br /&gt;– the first is lower than the second”&lt;br /&gt;&lt;br /&gt;“The numbers are not the same&lt;br /&gt;&lt;br /&gt;– the second is lower than the first”&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;3. Read two numbers from the console (one after the other) and using if, else if and else along with &amp;amp;&amp;amp; output one of the following:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;“The numbers are the same and are negative”&lt;br /&gt;&lt;br /&gt;“The numbers are the same and are positive”&lt;br /&gt;&lt;br /&gt;“The numbers are not the same”&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;4. Read a number from the console (use ReadLine and Int32.Parse) and using a switch statement with cascading, and depending on an input 1-10 output one of the following:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;“You entered an even number” or&lt;br /&gt;&lt;br /&gt;“You entered an odd number” or&lt;br /&gt;&lt;br /&gt;“You entered a number that is not 1-10”&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;5. Read a number from the console (use ReadLine and Int32.Parse) and by nesting if, else if and else output one of the following depending on what range the number is in, and whether it is divisible by 5:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;“The number is 0-25 and is divisible by 5” or&lt;br /&gt;&lt;br /&gt;“The number is 0-25 and is not divisible by 5” or&lt;br /&gt;&lt;br /&gt;“The number is 26-50 and is divisible by 5” or&lt;br /&gt;&lt;br /&gt;“The number is 26-50 and is not divisible by 5” or&lt;br /&gt;&lt;br /&gt;“The number is 51-75 and is divisible by 5” or&lt;br /&gt;&lt;br /&gt;“The number is 51-75 and is not divisible by 5” or&lt;br /&gt;&lt;br /&gt;“The number is above 75”&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;* Note. To check if a number is divisible by 5 you can use:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;(number % 5 == 0)&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Test Questions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create console applications to:&lt;br /&gt;&lt;br /&gt;1. Read two numbers from the console (one after the other) and using if, else if and else output one of the following:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;“The first number is lower than the second”&lt;br /&gt;&lt;br /&gt;“The second number is lower than the first”&lt;br /&gt;&lt;br /&gt;“The numbers are the same”&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;2. Read two numbers from the console (one after the other) and by nesting if, else if and else output one of the following:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;“Both numbers are negative”&lt;br /&gt;&lt;br /&gt;”Both numbers are positive”&lt;br /&gt;&lt;br /&gt;“The first number is positive, the second is negative”&lt;br /&gt;&lt;br /&gt;“The second number is positive, the first is negative”&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;3. Read a letter from the console and by if, else if and else with (or) output one of the following:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;“1” (if the letter is a, b or c)&lt;br /&gt;&lt;br /&gt;“2” (if the letter is d, e or f)&lt;br /&gt;&lt;br /&gt;“3” (if the letter is g, h or i)&lt;br /&gt;&lt;br /&gt;“4” (if the letter is j, k or l)&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;4. Read a number from the console (use ReadLine and Int32.Parse) and using a switch statement with cascading, and depending on an input 1-9 output one of the following:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;“You entered the number one, two or three” or&lt;br /&gt;&lt;br /&gt;“You entered the number four, five or six” or&lt;br /&gt;&lt;br /&gt;“You entered the number seven, eight or nine” or&lt;br /&gt;&lt;br /&gt;“You entered a number that is not 1-9”&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;5. Read three numbers from the console (one after the other) and by nesting if, else if and else sort the three numbers and output them in order:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Example: input numbers: 2 5 and 1&lt;br /&gt;&lt;br /&gt;Output: 1, 2, 5&lt;br /&gt;&lt;br /&gt;Example: input numbers 100, 45, 30&lt;br /&gt;&lt;br /&gt;Output: 30, 45, 100&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-5672689601356208363?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/03/c-programming-part-2-conditions.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-5241595598996428115</guid><pubDate>Sat, 22 Mar 2008 21:16:00 +0000</pubDate><atom:updated>2008-03-22T14:51:46.644-07:00</atom:updated><title>C# Programming - Part 1 - Strings</title><description>As languages become more high-level it seems training material focuses more on dragging and dropping components and interacting with the IDE than teaching fundamentals like problem solving and creating logical procedural code. From this deficit I created a set of C# Programming tasks that concentrate on problem solving and creating logical code. This work is made available by kind approval of &lt;a href="http://www.siemens.com/" target="_blank"&gt;Siemens AG Industry&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;The tasks are provided free of charge but may NOT be copied or redistributed. The work is copyright and all rights are reserved.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Scope of work&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The work is split into two parts: the first is a training part where you are encouraged to use books and the Internet to help you complete the questions; the second is a test part where you should complete the questions with no external help. The pass score is 80%.&lt;br /&gt;&lt;br /&gt;1. Manipulating strings&lt;br /&gt;&lt;br /&gt;2. Substrings&lt;br /&gt;&lt;br /&gt;3. Upper/lower case&lt;br /&gt;&lt;br /&gt;4. Concatenation&lt;br /&gt;&lt;br /&gt;5. Locating a character in a string&lt;br /&gt;&lt;br /&gt;6. Replacing characters in a string&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Training Questions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create console applications to:&lt;br /&gt;&lt;br /&gt;1. Store your name as a string literal and output it to screen.&lt;br /&gt;&lt;br /&gt;2. Read a string from the console and output it in upper case.&lt;br /&gt;&lt;br /&gt;3. Read a name from the console (for example "Bob") and output the following:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;"Hello, Bob!"&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;4. Use the following string:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;string telephone = "0800 123 4567";&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;and replace the space with a - so that the output is:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0800-123-4567&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;5. Use the following string:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;string alphabet = "abcdefghijklmnopqrstuvwxyz";&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;and output six letters starting from e, so that the output is:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;efghij&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;6. Create a simple CSV (comma separated values) parser capable of dealing with a string read in from the console. The string will always be in the format:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;firstvalue,secondvalue,thirdvalue&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Some example strings:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;"1,2,3"&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;"aa,bb,cc"&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;"apple,banana,pear"&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;The output (using the third string as an example) should be output to screen as follows:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;First value: apple&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Second value: banana&lt;br /&gt;&lt;br /&gt;Third value: pear&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Test Questions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create console applications to:&lt;br /&gt;&lt;br /&gt;1. Store your name in a string and output it to the screen in upper case.&lt;br /&gt;&lt;br /&gt;2. Use the following strings:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;string countryCode = “44”;&lt;br /&gt;&lt;br /&gt;string areaCode = “1260”;&lt;br /&gt;&lt;br /&gt;string number = “123456”&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;along with string literals to output:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;+44-1260-123456&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;to screen&lt;br /&gt;&lt;br /&gt;3. Use a string as follows:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;string test = "siemens automation and drives";&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Replace every i character with a 1 and then output the string in upper case as so:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;S1EMENS AUTOMAT1ON AND DR1VES&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;4. Parse the following string:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;string surnameforename = "Siemens, Werner";&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;so the forename appears before the surname as follows:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;"Werner Siemens"&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;store it in a string variable and output it to screen.&lt;br /&gt;&lt;br /&gt;5. Read in a string from the console that will always be in the following format:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;+&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;This should be done using the substring function.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;12+4&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Where the example would output:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;First number: 12&lt;br /&gt;&lt;br /&gt;Second number: 4 &lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-5241595598996428115?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2008/03/c-programming-part-1.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-111754035338468806</guid><pubDate>Fri, 23 Nov 2007 11:00:00 +0000</pubDate><atom:updated>2007-11-23T03:05:43.499-08:00</atom:updated><title>Resizing a logical volume without unmounting in Linux</title><description>I had a problem where the logical volume our kickstart image created was too small, despite the disk having enough space. As you see it only allocated 4GB:&lt;br /&gt;&lt;pre&gt;[root@example sbin]# df&lt;br /&gt;Filesystem           1K-blocks      Used Available Use% Mounted on&lt;br /&gt;/dev/mapper/VolGroup00-LogVol00&lt;br /&gt;                       4128448   3716732    202004  95% /&lt;br /&gt;/dev/sda1               101086     18598     77269  20% /boot&lt;br /&gt;none                   8203424         0   8203424   0% /dev/shm&lt;/pre&gt;&lt;br /&gt;The logical volume can be resized by running lvm (as root) at the command prompt and the following command (For 50GB):&lt;br /&gt;&lt;pre&gt;lvm&amp;gt; lvresize -L 50G VolGroup00/LogVol00&lt;/pre&gt;&lt;br /&gt;The issue we then had is that this isn't committed! Exit lvm, and then type the following:&lt;br /&gt;&lt;pre&gt;ext2online /dev/mapper/VolGroup00-LogVol00&lt;/pre&gt;&lt;br /&gt;After a few minutes of processing you will now find you have a larger volume:&lt;br /&gt;&lt;pre&gt;[root@example sbin]# df&lt;br /&gt;Filesystem           1K-blocks      Used Available Use% Mounted on&lt;br /&gt;/dev/mapper/VolGroup00-LogVol00&lt;br /&gt;                      51606140   3721676  45263616   8% /&lt;br /&gt;/dev/sda1               101086     18598     77269  20% /boot&lt;br /&gt;none                   8203424         0   8203424   0% /dev/shm&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-111754035338468806?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2007/11/resizing-logical-volume-without.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-1750038344618637165</guid><pubDate>Tue, 07 Aug 2007 21:55:00 +0000</pubDate><atom:updated>2007-08-07T14:55:37.197-07:00</atom:updated><title>Syntax highlighting in colour in HTML</title><description>I recently found a fantastic feature in GVIM that allows me to syntax highlight my code and turns it into HTML. I'm sure there are tools out there specifically for this job, but given the convenience of having this built into my editor I couldn't help but mention it.&lt;br /&gt;&lt;br /&gt;You can get &lt;a href="http://www.vim.org/" target="_blank"&gt;GVIM from their website&lt;/a&gt;. When you've loaded your code up (and practically every language is supported), click the Syntax -&gt; Convert to HTML menu option.&lt;br /&gt;&lt;br /&gt;Here's a sample:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color:#6a5acd;"&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#804040;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#6a5acd;"&gt;(&lt;/span&gt;&lt;span style="color:#008080;"&gt;isset&lt;/span&gt;&lt;span style="color:#6a5acd;"&gt;(&lt;/span&gt;&lt;span style="color:#804040;"&gt;&lt;b&gt;$&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#008080;"&gt;_GET&lt;/span&gt;&lt;span style="color:#6a5acd;"&gt;[&lt;/span&gt;'&lt;span style="color:#ff00ff;"&gt;album&lt;/span&gt;'&lt;span style="color:#6a5acd;"&gt;]))&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#6a5acd;"&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:#0000ff;"&gt;//echo 'gallery: ' . $_GET['album'];&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:#804040;"&gt;&lt;b&gt;$&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#008080;"&gt;d&lt;/span&gt; &lt;span style="color:#804040;"&gt;&lt;b&gt;=&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#008080;"&gt;dir&lt;/span&gt;&lt;span style="color:#6a5acd;"&gt;(&lt;/span&gt;'&lt;span style="color:#ff00ff;"&gt;Photos/&lt;/span&gt;' &lt;span style="color:#804040;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#804040;"&gt;&lt;b&gt;$&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#008080;"&gt;_GET&lt;/span&gt;&lt;span style="color:#6a5acd;"&gt;[&lt;/span&gt;'&lt;span style="color:#ff00ff;"&gt;album&lt;/span&gt;'&lt;span style="color:#6a5acd;"&gt;])&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color:#804040;"&gt;&lt;b&gt;$&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#008080;"&gt;bFirst&lt;/span&gt; &lt;span style="color:#804040;"&gt;&lt;b&gt;=&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#ff00ff;"&gt;true&lt;/span&gt;;&lt;br /&gt;        &lt;span style="color:#804040;"&gt;&lt;b&gt;while&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#6a5acd;"&gt;(&lt;/span&gt; &lt;span style="color:#6a5acd;"&gt;(&lt;/span&gt;&lt;span style="color:#804040;"&gt;&lt;b&gt;$&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#008080;"&gt;file&lt;/span&gt; &lt;span style="color:#804040;"&gt;&lt;b&gt;=&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#804040;"&gt;&lt;b&gt;$&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#008080;"&gt;d&lt;/span&gt;&lt;span style="color:#2e8b57;"&gt;&lt;b&gt;-&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#008080;"&gt;read&lt;/span&gt;&lt;span style="color:#6a5acd;"&gt;())&lt;/span&gt; &lt;span style="color:#804040;"&gt;&lt;b&gt;!=&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#804040;"&gt;&lt;b&gt;=&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#ff00ff;"&gt;false&lt;/span&gt;&lt;span style="color:#6a5acd;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color:#6a5acd;"&gt;{&lt;/span&gt;&lt;br /&gt;                &lt;span style="color:#804040;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#6a5acd;"&gt;(&lt;/span&gt;&lt;span style="color:#008080;"&gt;strpos&lt;/span&gt;&lt;span style="color:#6a5acd;"&gt;(&lt;/span&gt;&lt;span style="color:#804040;"&gt;&lt;b&gt;$&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#008080;"&gt;file&lt;/span&gt;, '&lt;span style="color:#ff00ff;"&gt;tb.jpg&lt;/span&gt;'&lt;span style="color:#6a5acd;"&gt;)&lt;/span&gt; &lt;span style="color:#804040;"&gt;&lt;b&gt;!=&lt;/b&gt;&lt;/span&gt;&lt;span style="color:#804040;"&gt;&lt;b&gt;=&lt;/b&gt;&lt;/span&gt; &lt;span style="color:#ff00ff;"&gt;false&lt;/span&gt;&lt;span style="color:#6a5acd;"&gt;)&lt;/span&gt;&lt;br /&gt;                &lt;span style="color:#6a5acd;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-1750038344618637165?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2007/08/syntax-highlighting-in-colour-in-html.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-7916618003572713740.post-4382455995150297320</guid><pubDate>Thu, 02 Aug 2007 22:02:00 +0000</pubDate><atom:updated>2007-08-07T15:03:24.675-07:00</atom:updated><title>Search Engine Effectiveness - Practical Test</title><description>I've been wondering recently how effective alternate search engines are compared to Google. As a small test I decided to take 25 searches I had performed in the last week and search on Google, Yahoo and MSN Live Search to compare results.&lt;br /&gt;&lt;br /&gt;The following table shows the results. A score of zero means the target info was found on the search page itself (I didn't have to click through to the site). A number 1-10 is the position of the search result with the target info. A blank score means the target info was not found on the first page of links.&lt;br /&gt;&lt;br /&gt;The score is a sum of each search position negated from 11. As so:&lt;br /&gt;&lt;br /&gt;Target info on search page: 11-0 = 11&lt;br /&gt;Target info on page result 4: 11-4 = 7&lt;br /&gt;Target info on page result 10: 11-10 = 1&lt;br /&gt;Target info not found: 0&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.paulmaddox.net/Files/search.gif" /&gt;&lt;br /&gt;&lt;br /&gt;Conclusions:&lt;br /&gt;&lt;br /&gt;I was pretty suprised Google was so far ahead compared to Yahoo and MSN.  Google won because it was better at finding more niche searches, whereas Yahoo and MSN failed completely.  For more obvious searches all three performed flawlessly and may do for day-to-day searches.&lt;br /&gt;&lt;br /&gt;Google tended to either have the result first, or not at all.  Yahoo had a few useful results in the top five.  MSN had some results nearer the bottom of the top 10.  This is significant for MSN because much lower results seriously increases the time taken to find what you want.&lt;br /&gt;&lt;br /&gt;Some oddities included Yahoo having numerous entries that were highly irrelevant and MSN having a curious slant to open source results, particularly source code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7916618003572713740-4382455995150297320?l=paulmaddox.net' alt='' /&gt;&lt;/div&gt;</description><link>http://paulmaddox.net/2007/08/search-engine-effectiveness-practical.html</link><author>noreply@blogger.com (.)</author><thr:total>0</thr:total></item></channel></rss>