Visual Studio debugging on a 64bit version of Windows

by Andrew Jackson 17. January 2010 08: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

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

How to find out the host address of the caller of webmethod

by Andrew Jackson 13. October 2009 04: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

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.net | Development | VB.net

Enabling/Disabling a Windows Forms Close Button

by Andrew Jackson 13. October 2009 04: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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

How to determine if a SQL temp table exists

by Andrew Jackson 12. September 2009 04:55
IF OBJECT_ID('tempdb..#some_temp_name') IS NOT NULL
PRINT '#some_temp_name exists.'
ELSE
PRINT '#some_temp_name does not exist.'

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | SQL

How to find out the name of the stored procedure that is currently executing

by Andrew Jackson 15. August 2009 04: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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | SQL

Get the time portion of a date in SQL

by Andrew Jackson 11. July 2009 05: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

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | SQL

Fixing SQL orphaned users

by Andrew Jackson 7. July 2009 03: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:

Development | SQL

How to change SQL Order By clause based on a variable expression

by Andrew Jackson 5. July 2009 05: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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | SQL

How can my custom control know if it is in design mode?

by Andrew Jackson 11. September 2008 05: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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Stopping Custom Controls from being added to Visual Studio Toolbox

by Andrew Jackson 21. August 2008 04: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.

  kick it on DotNetKicks.com

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Custom Settings Providers and Portable applications/U3 Drives

by Andrew Jackson 18. October 2007 09: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

SQL Command Visualizer for Visual Studio 2005

by Andrew Jackson 5. October 2007 14: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.

SQLVisualizer

Available free from my Visual Studio 2005 Tools area as a VSI which will automatically install it.

kick it on DotNetKicks.com

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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development

New Ternary code snippet for those learning C#

by Andrew Jackson 5. October 2007 11: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

C# | Development

With Contempt

by Andrew Jackson 1. October 2007 10: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...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | Productivity | VB.net

NUnit Templates and Snippets for Visual Studio 2005 - Now support C#

by Andrew Jackson 25. September 2007 13: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.

kick it on DotNetKicks.com

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | C#

Speed up your development day

by Andrew Jackson 10. August 2007 11: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | Productivity | VB.net

Large Text Properties and Reflector

by Andrew Jackson 10. April 2007 21: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development

New Download - Settings Snippets for Visual Studio 2005

by Andrew Jackson 31. January 2007 11: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Upgrading My.Settings files

by Andrew Jackson 30. January 2007 10: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Beating that corporate firewall

by Andrew Jackson 11. January 2007 15: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!

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development

Visual Studio 2005 - Keyboard shortcuts again

by Andrew Jackson 21. December 2006 14: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | Productivity

VSI Help

by Andrew Jackson 8. December 2006 23: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | Recommendations | VB.net

New Download - WaitCursor Snippets for Visual Studio 2005

by Andrew Jackson 8. December 2006 13: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

New Download - GUID Visualizer for Visual Studio 2005

by Andrew Jackson 2. December 2006 12: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Quick and dirty asp.net DropDownList selection required validation

by Andrew Jackson 23. October 2006 12: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.net | Development

My first CodeProject article

by Andrew Jackson 22. October 2006 09: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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

IE7 RSS Feed Auto Discovery

by Andrew Jackson 25. August 2006 10: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development

Visual Studio Debug Visualizers

by Andrew Jackson 1. August 2006 10: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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Know your Tools

by Andrew Jackson 26. July 2006 10: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development

Source Control on the go

by Andrew Jackson 24. July 2006 10: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development

Great Icon Editor

by Andrew Jackson 23. July 2006 10: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | Recommendations

Lisbox, IntegralHeight property

by Andrew Jackson 23. July 2006 10: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Returning SQL Results in a random order

by Andrew Jackson 5. July 2006 05: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | SQL

How to merge a field from multiple rows into one concatenated string

by Andrew Jackson 17. June 2006 09: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

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | SQL

Visual Studio Setup Project Versioning

by Andrew Jackson 12. April 2006 11: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development

Visual Studio 2005 VSI Power Toys

by Andrew Jackson 30. March 2006 10: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).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development

Programmatically raise a breakpoint in VB.NET Code

by Andrew Jackson 24. March 2006 05: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( )

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Attributes in VB.net

by Andrew Jackson 5. March 2006 10: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

VB.net 2005 - Easy settings persistance

by Andrew Jackson 14. January 2006 10: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Deleting Duplicate Record Entries in SQL

by Andrew Jackson 10. July 2005 05: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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | SQL

Finding Duplicate Record Entries in SQL

by Andrew Jackson 10. July 2005 05: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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | SQL

Dynamic User Controls on an ASP.net Page

by Andrew Jackson 23. January 2005 10: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.net | Development

ASP.net Training

by Andrew Jackson 23. January 2005 10: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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.net | Development

Allowing HTML to be entered into text boxes on ASP.net

by Andrew Jackson 2. November 2004 09: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 %>

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.net | Development

.net Tray Applications and Shut Downs

by Andrew Jackson 18. June 2004 10: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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Saving Settings

by Andrew Jackson 3. June 2004 10: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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About Me

Andrew Jackson

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008,2009 Andrew K. Jackson

RecentComments

Comment RSS