by Andrew Jackson
23. August 2010 14:32
If your desktop policy has removed the Add/Remove Windows Components from Control Panel and want to install IIS or other windows components your a bit stuck.
A bit of googling came up with the following that worked a treat.
Open up a command prompt in the C:\Windows\Inf folder and run the command line
Sysocmgr.exe /i:sysoc.inf
This will bring up the standard list of optional components and your ready to go.
Currently rated 2.5 by 13 people
- Currently 2.538461/5 Stars.
- 1
- 2
- 3
- 4
- 5
Tags:
by Andrew Jackson
1. August 2010 17:51
Having just got Froyo on my HTC Desire I wanted to see why my apps couldn't be moved to the SD Card.
It turns out you have to do something special in your manifest which is 2.2 specific but even if you want to support older OS's you can still include it, this page tells you everything you need to know and I can say it works for all my apps at least.
Currently rated 2.3 by 3 people
- Currently 2.333333/5 Stars.
- 1
- 2
- 3
- 4
- 5
Tags:
Android
by Andrew Jackson
17. January 2010 15:52
Thought I'd post this link as it was annoying me and took a little while to find a straight forward explanation.
I've just recently moved over to Windows 7 and decided to go for the 64bit version, using Visual Studio 2008 I find that I can't edit whilst in debug mode.. all something to do with Visual Studio not being a true 64 bit app.
Well this helpful article told me all I needed to do to get this working again, just changing build configuration and adding a new active solution platform of x86.
Full details can be found here, well worth a read:
http://blogs.msdn.com/habibh/archive/2009/10/12/how-to-edit-code-when-debugging-a-64-bit-application.aspx
by Andrew Jackson
13. October 2009 11:58
On the server inside the webservice method call, you have access to the HttpContext object. Using HttpContext.Current, you have access to a number of objects (including the request object).
From the request object you can find out information, including the host address from which the request comes from.
If you need to map this address to a hostname , you can use UserHostName property instead
' Example web method
<WebMethod()> _
Public Function TestMessage( ) as String
Trace.WriteLine("GetMessage called from : " + HttpContext.Current.Request.UserHostAddress + " " + HttpContext.Current.Request.UserHostName )
Return "Hello"
End Function
by Andrew Jackson
13. October 2009 11:53
#Region " Enable\Disable a Form's Close Button "
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal revert As Integer) As Integer
Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As Integer, ByVal ideEnableItem As Integer, ByVal enable As Integer) As Integer
Private Const SC_CLOSE As Integer = &HF060
Private Const MF_BYCOMMAND As Integer = &H0
Private Const MF_GRAYED As Integer = &H1
Private Const MF_ENABLED As Integer = &H0
Public Sub DisableFormCloseButton(ByVal form As System.Windows.Forms.Form)
' The return value specifies the previous state of the menu item (it is either
' MF_ENABLED or MF_GRAYED). 0xFFFFFFFF indicates that the menu item does not exist.
Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)
Case MF_ENABLED
Case MF_GRAYED
Case &HFFFFFFFF
Throw New Exception("The Close menu item does not exist.")
Case Else
End Select
End Sub
Public Sub EnableFormCloseButton(ByVal form As System.Windows.Forms.Form)
EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND)
End Sub
#End Region
by Andrew Jackson
12. September 2009 11:55
IF OBJECT_ID('tempdb..#some_temp_name') IS NOT NULL
PRINT '#some_temp_name exists.'
ELSE
PRINT '#some_temp_name does not exist.'
by Andrew Jackson
15. August 2009 11:50
The following SQL will report the name of the currently executing stored procedure
/* Begin */
PRINT ISNULL(OBJECT_NAME(@@PROCID), '<none>')
/* End */
To fetch this into a variable use :
/* Begin */
DECLARE @procedure_name VARCHAR(255)
SET @procedure_name = ISNULL(OBJECT_NAME(@@PROCID), '<none>')
/* End */
The key to this is @@PROCID, however, this returns NULL if not executing in a stored procedure, the ISNULL prevents a NULL value being used
by Andrew Jackson
11. July 2009 12:23
select cast(convert(varchar, getdate(), 108) as datetime)
Note: Code 108 returns the time portion of a date in the format hh:mm:ss
by Andrew Jackson
7. July 2009 10:57
More a note to myself for this age old problem when restoring SQL databases.
Run this against the database you have the orphaned user in and it will fix the record in the master database.
Username/Password is for the user you need to fix.
EXEC sp_change_users_login 'Auto_Fix', 'username', NULL, 'password'
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Tags:
SQL
by Andrew Jackson
5. July 2009 12:20
DECLARE @SearchType int
DECLARE @SearchText varchar(50)
SET @SearchType = 1
SET @SearchText = 'A'
SELECT
*
FROM
[TableNameGoesHere]
WHERE
(@SearchType=1 AND [Field1] LIKE @SearchText + '%')
OR
(@SearchType=2 AND [Field2] LIKE @SearchText + '%')
ORDER BY
CASE @SearchType
WHEN 1 THEN [Field1]
WHEN 2 THEN [Field2]
END
by Andrew Jackson
26. June 2009 09:46
Well I decided on my smartphone platform and have bought into the whole Google world and gone with the Android platform. Logical since I already had a heavy tie in to GMail and Google Calendars.
I'm starting to develop a few apps for it and will put them on Market when I'm happy with em. The first is a simple ASCII Chart just to get me used to the Android SDK.
You can find my apps by searching Market for CodeChimp or using the below barcode;
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Tags:
Android
by Andrew Jackson
11. September 2008 12:25
Easy - check me.DesignMode e.g.
Put this code into the load event of your control and the control will turn red when in design mode
If Me.DesignMode Then
Me.BackColor = Color.FromKnownColor(KnownColor.Red)
End If
by Andrew Jackson
21. August 2008 11:47
This has bugged me for ages and I've finally spent 10 minutes finding the solution to it.
I develop lots of custom controls which I will never place on a form at design time, their add-on components that are loaded at runtime and docked in conditionally. This ended up with Solution bloat meaning every time I first went into a design view of a form Visual Studio went into a fit building up a complete toolbox of things I'd never need.
One simple attribute was all that was needed to stop them being populated in future;
<System.ComponentModel.DesignTimeVisible(False)> _
Public Class MyUserControl ....
Hopefully someone else will find this useful for the future.
by Andrew Jackson
9. November 2007 17:46
Just released is a new version of my Folder Launcher utility.
This basically allows you quick access to obscure UNC paths, sitting in the system tray next to the clock a single click will list all of your pre-defined paths.
This has been entirely re-written in C# and uses per-user settings files.
Available free for download in my Desktop Enhancements area.
by Andrew Jackson
18. October 2007 16:31
Having recently bought a U3 Drive I've got the bug for portable apps. This unfortunately has jarred with my love of the settings provider provided within .net 2 which insists on storing settings in the Documents and Settings folder structure.
I've done some research into whether it is possible to change this default functionality and as with just about everything in .net there is!
I've taken the time to write this up as a Code Project article available from My Code Project articles.
The article covers creating a general xml settings file that resides in the applications folder, but also includes a class for U3 specific functionality.
I've also produced U3 specific versions of my ThumbGen and MiniCalc applications, available from my U3 Downloads area.
by Andrew Jackson
5. October 2007 21:11
I've finally got round to writing a visualizer I've been wanting for years, one that will give a decent representation of a SQL Command object, allowing you to view both the connection details and the list of parameters, their properties and values.
Below is a screenshot of what the visualizer looks like when you press the little magnifier when hovering over a Command object instance.
Available free from my Visual Studio 2005 Tools area as a VSI which will automatically install it.

Update:
If your having trouble with the vsi try renaming it to a .zip file, opening the file then copying the SQLVisualizer.dll to your My Documents\Visual Studio 2005\Visualizers folder.
I will research why the vsi's are occasionally giving this error.
by Andrew Jackson
5. October 2007 18:50
I'm doing my slow migration to C# from VB and getting through a good thick reference book to learn all the language shortcuts that C# seems to be full of.
The experienced C# developers will laugh but I found the Ternary operator syntax not particularly memorable so I created a code snippet to insert a template for me. Now all I do is type Ternary<tab><tab> and it puts the snippet in with declarations highlighted.
It's quite trivial but I thought I'd offer it up for anyone interested. I have posted it onto gotCodeSnippets.net
This is a great little site that needs far more support so I've added all my snippets on there and will continue to do so when I come up with more that are general enough for the world at large.
by Andrew Jackson
1. October 2007 20:39
Continuing my migration to C# I have now created a C# variant of my Debug Visualizer that has been around for some time for VB.
The VSI (Visual Studio Installer) package installs new C# and VB projects that appear under the My Templates area when creating a new project. The projects include all relevant references and a starter method to get you going. Just follow the comments to get a visualizer working for your chosen type.
Available from the Visual Studio 2005 Tools area as usual.

Currently rated 4.0 by 1 people
- Currently 4/5 Stars.
- 1
- 2
- 3
- 4
- 5
Tags:
by Andrew Jackson
1. October 2007 17:05
There's one major gripe I have with the VB language.. the With/End With block. Although it shortens code lines when setting lots of properties I find it harder to read, error prone when moving code around, and very awkward to debug since you can't just select the property and add a watch.
I never use this syntax in my own code, always preferring to have everything in long form, it doesn't increase typing too much with intellisense and we all have fairly large displays these days so line length is less of an issue as well.
So when using code I find on the net or from colleagues the first thing I do is remove with blocks. Getting fed up with this time consuming but quite dumb task I've created a Visual Studio macro to do it.
As an example, code with a With statement like the following;
Public Sub AWithExample()
With Me
.Text = "Hello"
.Tag = "This"
MessageBox.Show(.Text, "Title " & .Text)
Dim x As String
x = .Text
End With
End Sub
Becomes;
Public Sub AWithExample()
Me.Text = "Hello"
Me.Tag = "This"
MessageBox.Show(Me.Text, "Title " & Me.Text)
Dim x As String
x = Me.Text
End Sub
The Macro's quite trivial, just create a new macro and add the following code; More...
by Andrew Jackson
25. September 2007 20:02
Last year I published a VSI package containing NUnit Projects/Items/Snippets to allow you to quickly add tests, whether its a whole test project in its own right, a class within the current project or just a quick test method within your normal code class. This was all for VB, my language of choice since the year dot.
I am just starting to migrate over to C# and so I thought it was a good idea to update this package so it supports C# as well.
When you run the VSI it prompts which elements you want to install so you can un-select all the VB or C# elements if you really don't want them, but the package is very small so I'd just install the lot, you never know you may make the change one day as well.
Available at the Visual Studio Tools download area here.
This doesn't mean the end of my VB days and code posts here, I'm just trying to diversify and so will post elements on both languages depending on what I'm working on.

by Andrew Jackson
28. August 2007 21:37
Now available for download is a new revision of ThumbGen.
I've taken the time to convert it to .net 2, fix some annoying UI inconsistencies, give better progress feedback when creating thumbnails and also wrap it all up in a nice installer.
If you've never used ThumbGen before it is a utility for Windows XP & Vista that allows easy creation of thumbnail graphics.
Just drag your files onto the ThumbGen file list, choose your image size, filename prefix or suffix and the file type then press Create Thumbnails.
Thumbnails of your chosen images will be placed in the original images folder.
Available for free from my Desktop Enhancements download area.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Tags:
Site News
by Andrew Jackson
10. August 2007 18:05
One thing that seems to be a bit hidden to most developers is that opening files within Visual Studio works the same as opening them within a standard file explorer window in that you can specify the default way of opening a file.
This is particularly useful for forms/user controls in that 90% of the time you'll want to dive straight into the code, not go into the form designer even though Visual Studio defaults to opening the form designer which takes an age if you have lots of controls on your form.
To change the default is easy, this example will illustrate changing a VB form from the designer to the code editor.
- Right click on a form within the Solution Explorer window and select Open With...
- A dialog appears listing applicable editors within Visual Studio you can use.
- Select Microsoft Visual Basic Editor
- Click the Set As Default button.
And that's it, from now on every time you double click on a VB form you'll bring up the code window rather than the designer.
The association is for the whole of Visual Studio, regardless of solution/project loaded.
by Andrew Jackson
11. April 2007 04:00
Richard, a colleague of mine should take the credit for this as he originally found it but since he doesn't have a blog I thought I'd blog it here so I don't forget, and perhaps help someone else at the same time.
Have you ever noticed how the text property on a lot of controls have an ellipses button and allow you to bring up a big edit box.. well we wanted to do the same with our own control. I thought it was probably an attribute and I was right, just add the following to your text property;
<System.ComponentModel.Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(System.Drawing.Design.UITypeEditor)), System.ComponentModel.Localizable(True)> _
Now the credit to Richard who put me onto a great tool for finding this out, Lutz Roeder's excellent Reflector which allows you to drill down into just about any .net component and disassemble it getting useful bits like this. Given the .net object model it looks a little daunting but once you've done it once it's pretty easy. To illustrate I'll show you the navigation used to get to the text property.
Reflector by default will show you the base .net object model, you know it's a form control so drill into the system.windows.forms assembly , then the DLL (there can be more than one), then system.windows.forms namespace. Now choose the Textbox property and disassemble it (right click menu). Unfortunately nothing tells you here about the magic attribute but you can see that it overrides something. Looking back at the TextBox itself you can see that it inherits TextBoxBase, navigating to this via the hyperlink in the info pane at the bottom left and scrolling down to the Text property and there you go, that mysterious attribute revealed!
A handy technique once you know what information Reflector is giving you and where to look for more.
by Andrew Jackson
31. January 2007 18:04
Another VSI package for you, this time handling common win forms settings.
It provides auto upgrade code for new versions of your application, window size and position loading and saving.
It handles the initial loading of an app as well as closing whilst minimized/maximized.
I'd recommend installing them into a Settings folder under your My Documents\Visual Studio 2005\Code Snippets\Visual Basic\My Code Snippets folder.
You can download the package from my Visual Studio 2005 Tools downloads area.
by Andrew Jackson
30. January 2007 17:00
This isn't something I came up with - I'm not taking credit for it. I just found it on the net a long time ago and a colleague asked me about it so I thought I'd put it here for future reference.
With VS2005/.net 2 you get the ever so useful my.settings stuff. This is fine except it's version specific. When you release a new version of your app it creates a whole new settings file, ignoring the previous one for the old version.
To overcome this put in a new boolean setting, I call mine CallUpgrade, and set it's default value to True.
Then in your form load/get settings sub do the following;
If My.Settings.CallUpgrade Then
My.Settings.Upgrade()
My.Settings.CallUpgrade = False
End If
Now every time your app load it will look at your current CallUpgrade value, if it's the first time that version's been run it will be true and so the specific My.Settings Upgrade method will run which looks for a previous version and ports the setting values across. Then setting the CallUpgrade flag to false for future loads to not waste time trying to upgrade the settings.
Simple, a little cludgy on Microsoft's part not to have a more clear solution to it but this does the job.
by Andrew Jackson
11. January 2007 22:58
One thing that I've always understood, but always been frustrated by is corporate firewalls where they block both inbound and outbound ports.
Yeah, I know the reasons, stopping unauthorised software having freedom to do what it pleases and that's a good thing.. but sometimes things go a little too far for convenience. Take incoming email for example, good old port 110 is most often used and is one of the first to be blocked by most sys admin's. Again, sort of understandable but annoying if you want to check your own email account from work, you have to use some usually awful webmail system and keep refreshing it all the time.
Recently I've been doing a lot of work with web services and this got me thinking, you can do pretty much anything on port 80, why not just write services that do all that naughty stuff and host that on the outside world, then write small app's sitting inside your organisations firewall that just talk to the service.. and it works!
I wrote a small web service that had one method, GetMessageCount which took a mailserver, port, username and password as parameters and returned the number of messages in that inbox. Simple stuff when you have a pop3 library to hand.
Then I wrote a small tray application that called this web service every 10 minutes with appropriate mailbox details and displayed a message balloon if the number of mail messages increased over previous checks, therefore prompting me to login to my webmail and take action.
So, if you want simple status reports, or perhaps even more complex systems, as long as you've got some programming interface to it why not wrap it up in a service and write yourself some desktop app's to interact with it. Until your company implements content filtering as well as port filtering you'll be happy!
by Andrew Jackson
24. December 2006 21:54
Now available for download is my Mini Calc application.
It just has a simple entry box and a result area. You can always see the exact calculation your performing and go back and edit it if the result isn't what you wanted.
All basic maths operations are supported including bracketed calculations.
The system menu includes options so the calculator is always on top of other applications and also to automatically copy the results of a calculation onto the clipboard.
Due to the cost of hosting this site I'm charging a token amount of just 5 US Dollars to try and get in a little to pay some of the bills so if you like this site and use a calculator please give it a go. Payment processed via PayPal.
Available from my Desktop Enhancements download area.
by Andrew Jackson
21. December 2006 21:39
I got to browsing the VS2005 keyboard shortcuts again and found a new little gem I've never ever seen before.
Using Ctrl K H by default does a "Toggle Task List Shortcut" which makes a little blue curving arrow appear on your current code line within the text editor.
All very pretty I thought but what can I do with these blue arrows... it turns out that the Task List tool window adds a new Shortcuts option to the filter combo (which you can only see once you have at least one blue arrow).
Choosing to display Shortcuts in the task list shows you each line of code that is set with a shortcut and allows you to tick them off once you've attended to them, delete them and the usual double click to go to each one.
An interesting alternative to bookmarks as it allows you to quickly see a list of all your shortcuts rather than having to next/previous through them.
by Andrew Jackson
13. December 2006 20:05
This has been bugging me for ages.. I'm a big right click open in new window fan, and with IE 7 I naturally started using open in new tab, a vast improvement and saved cluttering up the task bar (yes, I know firefox users are saying about time but I'm an IE person).
All was well on my lovely laptop, but my desktop pc just wouldn't show open in new tab.. after a bit of obscure googling it turns out it's to do with rogue add-ins.. in this case an out of date Google toolbar. Update the toolbar and all is fine.
So.. if your having problems as well, just go and update your add-ins and see if that fixes it!
by Andrew Jackson
9. December 2006 06:25
As you know if you've been keeping up with this blog, I've got rather into my snippets and templates for Visual Studio.
I've followed the msdn examples on how to create vsi packages manually and all is hunky dory with that, but sometimes you just want a quick knock up package and crafting xml, renaming zip files and stuff just seems like too much hassle.
If your into vsi packages check out the Visual Studio Content Installer Power Toys it makes it far easier to create packages.
And if you just want to create code snippets easily then check out the Visual Basic Snippet Editor it has a great ui for creating snippets, specifying parameters and shortcuts and even saving it all as a vsi.
by Andrew Jackson
8. December 2006 20:37
Continuing my sifting through the bits and pieces I've accumulated I present two visual basic code snippets for handling wait cursor functionality within win forms easily.
Again it's a VSI package - once installed you will have two snippets;
- One which goes to a wait cursor then back to default.
- The second one remembers the current cursor, displays the wait cursor then goes back to the previous cursor.
Both are shortcutted beginning wait, so from Visual Studio just type wait? then tab.
You can download the package from my Visual Studio 2005 Tools downloads area.
by Andrew Jackson
2. December 2006 19:44
I'm trying to go through all my bits and pieces and either file, delete or publish them.
Here's a little something I thought I'd share with you, it's a simple GUID Visualizer I created using my Visualizer Template. It just displays a text box displaying the value in string format of the current guid. If you've ever tried debugging guids before you'll know that it's not easy, always giving you a misleading empty, which is actually a property of the guid type rather than its actual value.
This is my first add in I've wrapped up into a VSI package (Visual Studio Installer), it's actually quiet easy to do and I might revisit some of my other packages and wrap them up as well. Unfortunately it requires signing to stop the warning about dangerous code so maybe I'll have to commit to buying a code signing certificate.
You can download the package from my Visual Studio 2005 Tools downloads area.
by Andrew Jackson
25. November 2006 21:40
I'm sure most Visual Studio users have heard of Carlos, he's the man behind MZTools, one of the most useful Visual Studio AddIns around. I've been working with it since the vb6 days and have converted most of my colleagues to using it as well.
If your into Visual Studio extensibility then this blog is worth a read - as are his regular forum posts, I've certainly learnt a lot from him in the small amount of work I've done in this area.
The blogs available here as html and the rss is here
by Andrew Jackson
24. November 2006 21:08
I've been investigating NUnit recently and was getting frustrated by the amount of repetitive code you had to write for each item you wanted to test, so I wrapped it all up into some helper project and item templates. Then went a bit further and created a few code snippets to help as well.
I thought I'd make it available to you lot as I'm sure its something everyone sits down and has to write all the time.
The templates/snippets are all for VB.net but I'm sure you could adapt them for C# if you so wished, there seems to be a lot more demonstrations for C# out there anyway so I thought I'd try and even the balance.
You can download the vsi package containing them from my Visual Studio 2005 Tools downloads area.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Tags:
VB.net
by Andrew Jackson
14. November 2006 20:00
I've been after a usb drive caddy for some time, wanting something I could use as an on the go backup for my laptop, bulk file shifter and just general big bit of space to chuck stuff.
Went for the Thecus Yes Nano N1050 which does all the above plus gives you this nifty on the go feature where I can plug in a little battery pack to give it some juice (4xAA's), connect my camera lead to it, press a button and it copies all the files from my camera to a new incremental folder.
I got it from Scan who had it on a bundle special along with a 100GB Samsung drive last week. I didn't have any spare 2.5" laptop drives so thought I'd go the whole hog.
Power requirements are very low, I've plugged it into my Asus laptop, numerous pc's, my Infrant ReadyNas box and no complaints from any of them. It comes with a lead to provide power from a second usb port if required but I think that'll remain in my bag.
The only small gotcha is that for the "on the go" copy function to work your drive must be formatted to FAT32 (I assume the controller board only talks to this format). WindowsXP by default will not format large drives (above 32GB) to this so I found a great little utility called Fat32Format from Ridgecrop which does it for ya, and very quickly at that!
by Andrew Jackson
11. November 2006 17:40
As part of moving away from my old domain I've now completed the move of the file downloads area.
You can get access to the new one by clicking on the downloads link in the navigation bar, or directly by http://www.codechimp.org/filepal
At the moment all of my existing freely available applications are listed, thats;
Desktop Utilities (PaperMatic, FolderLauncher, ThumbGen)
VB/Visual Studio add-ins (Cyclomatic Complexity, Visual Studio 2005 Visualizer Project Template)
Source libraries (Query String Attributes Class)
The new downloads area will be supporting PayPal payments for a few new items coming up, but my intention is to still give a lot of stuff away for free, or trial versions.
The FilePal application is something I've developed myself using vb/asp.net 2. It has a fully web based admin interface and stores its data in xml files. Obviously at the moment I'm still testing it but if anyones interested in using the application themselves let me know and I might wrap it up into a purchasable product.
Currently rated 5.0 by 1 people
- Currently 5/5 Stars.
- 1
- 2
- 3
- 4
- 5
Tags:
Site News
by Andrew Jackson
9. November 2006 15:24
Just upgraded my home network. I had a very nice, albeit noisy 3com 10/100 rackmount 12 port switch ticking along nicely but I'd been hankering for a gigabit switch for a while now.
Dell ran a promotion recently on their network gear and I managed to pick up a PowerConnect 2716 16 port gigabit switch for under a 100 quid.
It's not for big business certainly, but it's rack mountable, unmanaged/web managed, supports 10/100/1000 auto switch on all ports and supports jumbo frames. Best of all, no fans! It just slotted in as a replacement for my 3com and I enabled jumbo frames on it, my pc and my Infrant ReadyNas and got a bit of a performance boost from it. It's not 10 times faster like the numbers suggest.. but it was a 100 quid well spent.

by Andrew Jackson
23. October 2006 19:00
I needed to do the usual thing, present a drop down list with the first item as a fake one being something like "-- Choose a Category --"
I jumped straight in and started thinking about custom validation etc etc and lost the will to live very quickly - considering this was just supposed to be a quick knock up project.
Then I found this little snippet, using the RequiredFieldValidator you can specify an InitialValue, put this to be your "-- Choose a Category --" and your away, it won't validate unless it's something other than that!
OK, it's not the most elegant solution, I'd prefer value, or even item being 0 comparison but it does in a push and worth remembering.
by Andrew Jackson
22. October 2006 16:49
I submitted my first article to CodeProject today.
It's one of my favourite sites when looking for articles on new areas I haven't dealt with before so I thought i'd share my technique of using custom attributes and reflection in vb.net. I demonstrate how to use it to read query string parameters easily into fields without all the repetitive code.
Have a read and see what you think
by Andrew Jackson
25. August 2006 17:34
Took me a while to find this when I was looking for it so I'll reproduce it here.
If you want to make the little feed button light up in IE7 to indicate you have an RSS/Atom feed available then this is what you want to do;
For RSS add the following link to your page head
<link rel="alternate" type="application/rss+xml"
title="your feed title here" href="http://www.company.com/feedurl.rss" >
For Atom add the following link to your page head
<link rel="alternate" type="application/atom+xml" title="your feed title here" href= "http://www.company.com/feedurl.xml" >
I got this from the MS RSS Team Blog
It's got some useful stuff on it so worth a look.
by Andrew Jackson
1. August 2006 17:31
I needed to knock up a small custom debug visualizer for a project I'm working on. There really easy but I always have to lookup the exact references etc to include which is actually the longest part of the process.
To ease matters next time I spent a little time creating a project template, something I've never done before. Now when I want a new visualizer I just start a new project based on the template and it's got all the references etc done for me, all I have to do is read the todo messages and replace a few lines to include the functionality I need.
I thought I'd share the visualizer template with you since I'm sure others will have googled this several times over to remember how to do it.
You can download the vsi package from my Visual Studio 2005 Tools downloads area
by Andrew Jackson
26. July 2006 17:29
Working on a train with a laptop you soon get to learn that using a mouse is very unproductive. Certainly on the trains in the UK your continually jossled by ropey train tracks or the person crammed in next to you.
I've taken to trying to learn a new shortcut key every day in visual studio and to aid in this I've found a handy switch that in 2005 at least is switched off by default. On the Tools/Customize screen theres a checkbox called "Show shortcut keys in ScreenTips", switch this on and next time you mouse to a toolbar you'll have the opportunity to learn that function. Ctrl KK, KN, KP have saved me so much time over using the bookmark buttons.
I've also remapped a few keys, particularly the Ctrl Up and Ctrl Down to take you to the top of your current or next method when in text editing mode, much better than scrolling the screen a line at a time which is there default operation.
by Andrew Jackson
24. July 2006 17:27
One slight problem I've encountered with developing purely on my laptop for my own projects is source control. I take regular backups using Microsoft Sync Toy to my NAS box at home which is fine for the disaster recovery scenario. What I was lacking though was a way to version and recover my code back to a time before I made a stupid decision.
I've not known anything but source safe in my work environments and I've never found it that good, especially for branching and rollback scenarios, but I've stuck with it as I've been concerned about visual studio integration with other products. But now I've found a solution.
Subversion is a good open source version control system and theres a lot of different ui's about for it as well.. the one that caught my eye was SVN Tortoise, which instead of plugging into a design environment plugs directly into explorer. Right click on files/folders and you have complete source control, far more powerful than source safe ever offered and because it's at explorer level you can version manage anything from text files up!
I'm just using it for simple single user roll back/tag scenarios but it's full multi user, merge as well as locking support and supports web based access to it. Give it a try.
by Andrew Jackson
23. July 2006 17:25
Whilst I'm on a blogging roll I thought I'd mention my favourite icon editor of all time as well, Axialis Icon Workshop.
Version 6 has a truely inspired design mechanism that lets you build icons with glossy shine to em in minutes using just drag and drop. I'd definately recommend you check it out if you have to knock up icons quickly.
by Andrew Jackson
23. July 2006 17:24
If your looking for a color picker for whatever reason, web design, win forms development, graphic design then check out Visual Color Picker by Novosib Software. It's a free utility and it has so many different ways of choosing/capturing colors you'll be spoilt for choice.
It also provides you with a simple output screen which you specify your favourite development environments color function and it'll fill it all in for you just ready to copy and paste. Whether it's rgb, cmy, comma separated, hex, you name it'll provide it.
by Andrew Jackson
23. July 2006 17:23
I've just had one of those doh! moments so I thought I'd write about it here in case I ever forget it.
I've avoided using the listbox for years and years (since VB5 I think) since it doesn't fill a specified height.
Forced back to a listbox for a bit of owner draw code I want to implement (which is really cool and easy in .net by the way) I was hit by my age old problem.. then a property just jumped out at me, IntegralHeight which is set to true by default, this is the magic little thing I've been looking for which (if set to false) stops the listbox resizing to a multiple of it's item height. I'm not sure how long this has been here and I feel an idiot for missing it if it was in VB5 but now I know, and I'll use listboxes for more stuff rather than stick with listviews in detail mode.
by Andrew Jackson
5. July 2006 12:33
Bit of an un-usual one but if you want to return a result set in a random order then you can use this;
SELECT *
FROM table
ORDER BY NEWID()
NEWID creates a unique value every time it's executed, the values are non-consecutive.
by Andrew Jackson
17. June 2006 16:31
Where you have multiple rows that you need to either display or report on as one single, concatenated field you can use the Coalesce function to merge them.
You can either do this in a stored procedure or create a function so it can be used inline in Select statements.
Below is an example of a function that will merge multiple policy numbers into one string containing them separated by commas.
CREATE FUNCTION dbo.fn_MergePolicyNums
(@HGNum as int)
RETURNS varchar(100) AS
BEGIN
declare @PolNums varchar(100) /* Holds multiple MEC numbers */
SELECT @PolNums = COALESCE (@PolNums + ', ' + PolicyNum, PolicyNum, @PolNums) FROM tblPolicy WHERE HGNum = @HGNum
RETURN ISNULL(@PolNums, '')
END
by Andrew Jackson
4. June 2006 17:22
I've been looking for a portable solution every since the company I work for stopped letting us use laptops forcing us to go into the office and just work from there so I've been bored on the train with nothing but my iPod for company. I needed something to keep myself occupied and since I no longer could work on company projects I thought I'd like to develop the many project I've had on my mind for ages and hopefully actually finish some of them.
I finally took the plunge last week whilst I was off work and scoured Tottenham Court road for the best deal on an ASUS W5, got it in black as the white ones looked a bit grubby even in the shops and I'm just not that cool to have a white one. I'd looked around at all sorts of things, the UMPC's that are just coming out, the Apple MacBook, but they were either too expensive, too limited or in the case of the Apple, were very tempting but I just have too much dependence on Microsoft. I knew I could dual boot but I just don't think I'd every boot into OS X so didn't see the point.
The Asus is very nice, big enough to be able to type on and see the screen yet small and light enough to fit in my bag and not stand out as a mugging opportunity or do my back in!
I'm a big fan of hibernation, finding it the best bet when pulling into Liverpool Street to be able to quickly save what I'm doing, and get back to it when I need to without waiting for a full re-boot. The trouble was, I was getting an occasional message about "Insufficent System Resources Exist to Complete the API" and hibernation not working, requiring a rushed shut down or standby to get me off the train. A bit of googling later and I find it's a common bug identified by Microsoft for pc's with more than a gig of ram in them. There is a hot fix patch available but you have to phone Microsoft to request it. I did the dutifull thing and tried ringing, got a "only in office hours" message, so then I went the web route but my oem version of XP Pro wasn't offered support.. so finally I googled some more and found the file available on numerous sites (presumably by other people who couldn't see the sense in not having access to this file). I'm not going to post the file here as I'm not sure about the legal implications but if you want it, the exact filename is WindowsXP-KB909095-x86-ENU.exe which I'm sure using your favourite search engine you'll find in no time.
by Andrew Jackson
12. April 2006 18:24
This really bugged me until I found the solution so I thought I'd share it here.
When you create a Visual Studio Setup project all is fine for the first version, it builds your msi, you distribute it and it just works.
When you come to distribute a new version however it detects the previous version and forces you to uninstall it manually before installing the new version. Very frustrating.
The solution to this is very easy, just not very obvious. In the Setup Project Properties you have a Version property, just up the number in here. Major, minor or revision all work.
When upping the version it will recommend changing the Product Code which is a GUID in the project properties. I always specify yes to this.
Do this each time you build a release copy of your installer and all will be fine, no more prompting to uninstall.
by Andrew Jackson
30. March 2006 17:09
I had an annoying thing happen earlier this week. I was looking at DotNetNuke for a potential project and used their VSI package which allows you to create new sites from within Visual Studios New WebSite wizard.
Due to an incompatibility I wanted to go from version 4.2 to 4.0, there was no un-install functionality for the VSI package and installing 4.0 over the top of 4.2 made visual studio just freeze trying to bring up the new web project dialog.
After a bit of googling I found Microsoft have a power toys kit for VSI, it allows listing of all installed VSI packages with the option to un-install them, it also gives you lots of help to create your own package, something I haven't looked at yet but at least I know it's there if I need it.
So if you want to trim down some of the packages you've installed I'd highly recommend getting this tool (just look on microsoft/msdn downloads, I'm sure the link will change if I put it here).
by Andrew Jackson
24. March 2006 12:28
' Check to see if we are being debugged - (this is effectively the only way i've
' found to check "in ide")
If System.Diagnostics.Debugger.IsAttached Then
' Force the code to bread
System.Diagnostics.Debugger.Break()
End If
This is an alternative to Debug.Assert( )
by Andrew Jackson
5. March 2006 17:08
If you haven't looked into using attributes you really should. We've all used the serialization ones I'm sure but think about using your own, it's not that difficult, just a simple class with an attribute telling it that it itself is an attribute and where it can be used then a bit of code using reflection techniques to interogate them.
I'm using it as an ORM technique, describing the stored procs to get/save classes and also describing the property to field mappings. It's early days with my architecture but I'm liking it, for all those simple objects its going to do away with the whole persistence code that we all write over and over. I've seen lots of other ORM solutions but attributes is my personal choice of where I'm going, it keeps the description with the object rather than in some config file or other complicated solution. It also means you can carry your class to another project with ease, very little dependency involved as long as you have your ORM persistance class/assembly carried over as well.
by Andrew Jackson
14. January 2006 17:07
Just in case you haven't spotted it yourself have a look at the applications settings improvements in VS 2005.
Earlier versions of VB.net gave you the app.config file which was a god send, but now you don't even have to write all the persistence/retrieval code. In the properties for whatever visual element you have go to the ApplicationSettings property under Data and you can bind any control/form property to a value in your .config file.
I use it all the time for form size/position persistance, last entered values, splitter sizing etc.etc.
Simply superb, theres just no reason for an app not to save user preferences now, it's a 2 minute point and click job.
by Andrew Jackson
18. November 2005 17:06
In your main form put the following piece of code, replacing the YOURMAINFORM with the name of the form.
Shared Sub Main()
' check for previous instance
If PrevInstance() Then
MsgBox("Application is already running!", MsgBoxStyle.OKOnly Or MsgBoxStyle.Critical)
Else
' Runs the application.
Application.Run(New YOURMAINFORM)
End If
End Sub
Private Shared Function PrevInstance() As Boolean
' array of running processes with this assembly name
Dim p() As Process = Nothing
Try
' put the processes into an array
p = Diagnostics.Process.GetProcessesByName(System.Reflection.Assembly.GetExecutingAssembly.GetName.Name())
' if there's more than one process with this name
If p.Length > 1 Then
' program is running...return True
PrevInstance = True
Else
PrevInstance = False
End If
Catch ex As System.Exception
' set return to False
PrevInstance = False
Finally
' clean up
p = Nothing
End Try
End Function
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Tags:
by Andrew Jackson
18. November 2005 17:05
To add simple logging to a log file you can intercept your trace messages and put these to a log file.
To do this add the following code;
Imports System.IO
Dim LogStream As FileStream 'should be at a level with enough scope for your logging
'Start the logging to your file - probably to go in your frmMain.load
LogStream = New FileStream(System.IO.Path.Combine(System.Environment.CurrentDirectory, "MYFILE.log"), FileMode.OpenOrCreate)
Dim objTraceListener As TextWriterTraceListener = New TextWriterTraceListener(LogStream)
Trace.Listeners.Add(objTraceListener)
'Whenever you want to log a message use the vb.net
trace.writeline("message")
'and it will get written to the log file.
'Close the log file when your application ends
If Not LogStream Is Nothing Then
Trace.Flush()
LogStream.Close()
End If
Currently rated 3.0 by 2 people
- Currently 3/5 Stars.
- 1
- 2
- 3
- 4
- 5
Tags:
by Andrew Jackson
11. July 2005 17:04
Seems as though 7/7 has got everyone thinking the what if's should you or a loved one be caught in an emergency situation.
Heres a useful one found at the link below - just put a contact in your mobile called ICE (In Case Of Emergency) with the mobile/home numbers of the person you want the emergency services to call should something happen and your unable to make that call yourself.
Pass it on, the more of us that use it the more the emergency services will know to look for it.
http://www.eastanglianambulance.com/content/news/newsdetail.asp?newsID=646104183
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
Tags:
by Andrew Jackson
10. July 2005 12:40
This article describes how to delete a single row, when it is found that row is duplicated
Set Rowcount 1
Delete From
Table
Where
ID = 999 (Or any field name/value combination that identifies the duplicate row)
Set Rowcount 0
by Andrew Jackson
10. July 2005 12:35
This article describes how to identify duplicate records in a SQL table.
Use the Group By / Having combination in a Select statement
Select
ID
From
Table
Group By
ID
Having
Count(ID) > 1
by Andrew Jackson
23. January 2005 17:03
Spent quite a lot of time today getting to grips with dynamically placing user controls on a page at run time. I wanted a series of buttons which were determined by database entries and these buttons needed to have code to display a page when clicked. If your wondering how to do this yourself you need to know about Page.LoadControl and AddHandler;
- Create a sub for the click handler with the usual ByVal sender As System.Object, ByVal e As System.EventArgs parameters.
- Use controlvariable = Page.LoadControl to load an ascx into a variable (defined to be the type of the user control)
- Assign the controlvariable.id to something useful
- Do a me.controls.add controlvariable to add it to the page (or a me.container.controls.add if you've got your page divided up into tables or the like)
- Do an AddHandler ctype(me.controls(controlindex), control type).Clicked, AddressOf nameofclickhandler
The click handlers sender property will have the control (as type object so you have to cast it again) so you can inspect the ID and find out which button was clicked and act accordingly. For my example I made a custom control which had a few basic properties of a button object exposed plus an additional one for the page name associated with the button. That way it was instantly available from the object passed into the click event handler and i could do a response.redirect with it.
A lot of work casting back and forth for a newbie to this but it works, would recommend putting these controls into a table/div/whatever block so you can keep track of the control indexes, also found it useful to make a quick hash table to store the control objects and their ID's for easy access to each control.
by Andrew Jackson
23. January 2005 17:02
Spent the last week on an ASP.net training course with Pygmalion.
Good course, even though I knew a little of asp.net before I started I learnt a lot and went away confident at writing apps from scratch rather than cobbling together bits.
A big thing that came out of it for me was a renewed determination to fully embrace Option Strict in all my .net code, being from a VB background I'd enjoyed years of clumsy programming letting the compiler work it out for me. Spent the weekend prototyping a system for work and stuck Option Strict on and forced myself. It was annoying at first but I soon found myself making informed decisions on what my code was doing rather than just object.mystical property to object.mystical property and keeping my fingers crossed.
Oh, and the best thing about the course.. great lunches every day, and some interesting people on the course from a wide background, all asking questions that I found useful as well.
by Andrew Jackson
2. November 2004 16:43
ASP.net adds very handy functionality by default, in that it throws an error if your form contains any html on it's submission. Handy for html injection techniques, but not if your writing an entry form for techies that requires it.
To disable this validation add the following code to your aspx pages, just remember you've done it and the consequences of doing so.
<%@ Page Language="VB" validateRequest="false" CodeBehind= etc etc etc %>
by Andrew Jackson
5. September 2004 16:43
Ever come across the problem of when you go to save an image in IE/Outlook the only option you have is bitmap?
Simple little fix, just clear your temporary internet files in IE and all is well again. Dunno why, it just does.
by Andrew Jackson
18. June 2004 17:49
Had a tricky problem today whilst working on my wallpaper application.
The program resides in the tray and has a settings form that I don't want to really quit the application when closed, just hide the window and still sit in the tray. The trouble was I wanted to respond to windows shut down requests and actually quit the application, without the following fix my application cancelled the windows shutdown!
After much searching I came across the handy WM_QueryEndSession message. The code snippet below shows it's use for detecting a true windows shut down rather than just a close of the form.
Private Shared WM_QUERYENDSESSION As Integer = &H11
Private Shared systemShutdown As Boolean = False
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_QUERYENDSESSION Then
systemShutdown = True
End If
' If this is WM_QUERYENDSESSION, the closing event should be fired in the base WndProc
MyBase.WndProc(m)
End Sub 'WndProc
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Not systemShutdown Then
Me.Visible = False
e.Cancel = True
Else
e.Cancel = False
End If
End Sub
by Andrew Jackson
3. June 2004 17:52
It's always a problem giving users settings they can change.. where exactly should you save these... first it was win.ini, then the registry and now it's the users application data folder.
This new place has the advantages that it's user specific and relatively secure and it's easy to see/edit/move to another machine.
.net has Application.UserAppDataPath which returns the current recommended path for application data for this application. Unfortunately it also appends the current version number of the application, which although good for large applications where versions may change radically, for minor revisions it's annoying in that every new build would effectively loose users settings and they'd have to set it up again (or copy the file)
I've knocked up this simple function that simply removes the version info and returns a path that can then just have your settings file appended to get a consistent path. Thought I'd share it here for the masses;
Public Function AppSettingsPath() As String
Dim AppPath As String
Dim LastSlash As Int16
AppPath = Application.UserAppDataPath
LastSlash = InStrRev(AppPath, "\")
Return AppPath.Substring(0, LastSlash)
End Function