Showing posts with label Development. Show all posts
Showing posts with label Development. Show all posts

5 Aug 2010

Unable to copy from obj\debug to bin\debug

Arrrrgghgghgh this problem reared its ugly head again today.  Occurs whenever I try to build a solution (winforms) on Visual Studio 2010.

Previously adding this to the build events (My project, compile tab, click build events):
If exist "$(TargetPath).locked" del "$(TargetPath).locked"

But after working for ages I started getting the error again.  Found this online though, and added it and looks like we are good again:

If exist "$(TargetPath).locked" del "$(TargetPath).locked"
if not exist "$(TargetPath).locked" if exist "$(TargetPath)" move "$(TargetPath)" "$(TargetPath).locked"

Microsoft really want to sort this out, as developers typically build a solution more than once, can’t quite get the hang of perfect coding 1st time round yet.

24 Jun 2010

Becoming a better programmer

Recently we have started training one of our support guys, into becoming a junior developer.  It’s the 1st time we’ve trained someone on the team, who hasn’t coded commercially before.  It got me to thinking about what makes a good developer, and in turn how I can become a better developer.

I read a few other good blogs on this issue of being a better developer before starting this one.

It also got me to thinking about how I have improved at developing over my career.  Here are some of the things I’m definitely better at now than I was at university.

  • Naming of methods and refactoring.  I now use clear concise methods, both in their naming and what they do.  If you need to comment in what the method is doing, rather than that being obvious by the name, I think you are doing something wrong.
  • Becoming less likely to jump to a new technology straight away.
  • Building user interfaces that really guide the user from start to finish and require little or no introduction. SSW rules to have some great pointers here.
  • Dotting the i’s and crossing the t’s in a project, getting it deployed and not having it sit in development or ready for deployment state.
  • Searching Google (will it wasn’t there when I was at uni) but I now know when searching which paths it sends me down which are just plain ludicrous and which to follow.  Google can point you in one or two good directions when searching how to solve a coding issue, and thousands of wrong directions.

Then I started thinking, what am I worse at than I was when I came out of university.

  • Becoming less likely to learn a new technology quickly (didn’t I mention about that in the positives above) – yeah but there are pluses and minuses to it.
  • Deploying projects before they are fully ready.

My main tips to becoming a better developer

  • Name your methods and classes will, if they don’t make good sense when you are developing them, you are going to have a lot of trouble maintaining them.
  • REFACTOR REFACTOR REFACTOR!!!
  • Build user interfaces that don’t need instructions and are in the main self explanatory
  • Get involved in teaching others what tips & techniques you have acquired, this will crystallize them in your own mind and help your team.  Teaching will also show you where you are bluffing and don’t understand it, because if you don’t get it you certainly can’t explain it.
  • Learn a new technology once per month, and use it in a mini project.
  • Don’t let another member of your team become completely specialised into one technology – make sure you all have some awareness of what the other guys are coding.  My colleague is doing a WPF project, and I have no clue how it works, this shouldn’t happen.
  • Get to know the users of your software and LISTEN to them, also if possible use your software in the field.
  • Above all be passionate about coding and the software you write.

18 May 2010

DatagridView : Sort Generic List on any property (minimal code)

Had been wrecking my head with this for a few hours but got a good solution (with very little code).
Okay so it using reflection and mightn't have order log n speed, but so what if you are sorting collections with normally less than 50 items.

I handle the Column Header Mouse Click
Get the data property name.
Then use some reflection to sort the generic list.  (before this I had to use select case, and sort by knowing the property name in code, but when I add new properties this was a pain to maintain).


    Private Sub SelectionsCollectionsDataGridView_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles SelectionsCollectionsDataGridView.ColumnHeaderMouseClick
        Try
            Dim col = Me.SelectionsCollectionsDataGridView.Columns(e.ColumnIndex)
            Me.selectedMarket.SelectionsCollections.Sort(Function(p1, p2) p1.GetType.GetProperty(col.DataPropertyName).GetValue(p1, Nothing).CompareTo(p2.GetType.GetProperty(col.DataPropertyName).GetValue(p2, Nothing)))
            Me.SelectionsCollectionsBindingSource.CurrencyManager.Refresh()
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub

23 Mar 2010

.NET FlowLayoutPanel Large Vertical Gaps (unwanted)

Ran into this issue and found a post to fix it thanks to LewisG (as this was doing my head in).


http://www.windows-tech.info/3/c9cb6b44b9529869.php


When two controls that would fit width-wise are added to a Flowlayoutpanel, and the first one has FlowBreak = true, the FlowLayoutPanel inserts a significant amount of unwanted vertical blank space between the controls.
Even in design time it can be reproduced. Steps are:
- Create a new form
- Add a flow layout panel
- Add a label
- Add a button
- Set flowbreak=true on the label
- Resize the button width-wise. It jumps up and down, the unwanted blank space appears and dissappears, depending on whether it is large enough to fit alongside the label or not.
I'm really surprised noone has made a reference to this bug in msdn forums, or any of the usual search engines.
We have an application that creates controls dynamically, and the client is hammering us with this bug. Help is appreciated.


Re: Windows Forms General Flowlayoutpanel flowbreak bug. It creates unwanted empty space

LewisG 

I realize this issue is pretty old, but I ran into this bug myself and I figured out a workaround I thought might be useful to someone else.
The vertical size of the gap seems to be the same as the height of the control that follows after the flow break. So, I just add a panel of Size(0,0) with no margins after the flow break. That gets rid of the gap.

12 Jan 2010

Roboweb Labs

 

Tips: When entering a result with multiple winners, remember you may need to set dead heat count to zero (e.g. Soccer score anytime), as dead heat does not apply here.

Date Status Description
29-Jun-2010 Ready For Live Test robo Web can generate in-running to non arkle screens
29-Jun-2010 Ready For End User Test Rule4s can be entered against non sis racing markets (e.g. across the card doubles).
29-Jun-2010 2.4.05 Can now select multiple dates for creating numbers games
29-Jun-2010 2.4.05 Monday Millions Plus Draw now generated (these can be resent over top of existing 1 draw events).
     

 

12-Jan-2010 : Warns if event greater than 10 days in future or if date is blank
12-Jan-2010 : Attachment to email added as in line
12-Jan-2010 : Apply can send email
12-Jan-2010 : Saves to network drive/current/antepost

16 Dec 2009

SQL Server Transaction Log Full

Sometimes, for whatever reason the transaction log gets full up.
And shrinking via management studio doesn't work;

sp_detach_db [database name]
Then rename or delete the log file

Then
EXEC sp_attach_db @dbname = N'pubs',
@filename1 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf',
This will create a new blank log file and get you up and running.

15 Dec 2009

Checking Types in VB.NET

Easiest way I have found to date:


If TypeOf (Me.Button1) Is Button Then
MsgBox("is button", MsgBoxStyle.Information)
End If

26 Nov 2009

GUI Letting Users Know Which control has focus

When a control has focus there is a very subtle change in it's colour, that experienced windows users know.

However we develop software that is often the 1st windows programme the users have experienced.

To help, with this we sometimes set the background colour to yellow on focus and white on no focus. I've also modified the code, to allow you to set it up for making the border colour (color) go yellow on focus, and form colour on lost focus (bit like google chrome text boxes).

Here is some easy code to allow this:


#Region "ChangeColourOnHasFocus"

Private intFocusType As FocusType = FocusType.BackgroundColor
Private Enum FocusType
BackgroundColor = 1
BorderColor = 2
End Enum

Private Sub SetControlBackgroundToWhiteOnLostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim ctl1 As Control
ctl1 = sender
Debug.WriteLine(ctl1.Text)

Dim blChangeColour As Boolean
blChangeColour = Me.needToChangeControlColourOnFocusChange(ctl1)
If blChangeColour Then
Select Case intFocusType
Case FocusType.BackgroundColor
ctl1.BackColor = Color.White
Case FocusType.BorderColor
Dim g As Graphics = Me.CreateGraphics
Dim pen As New Pen(Me.BackColor, 5.0)
g.DrawRectangle(pen, New _
Rectangle(ctl1.Location, ctl1.Size))

End Select

End If

End Sub
Private Sub SetControlBackgroundToYellowOnFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim ctl1 As Control
ctl1 = sender

Dim blChangeColour As Boolean
blChangeColour = Me.needToChangeControlColourOnFocusChange(ctl1)
If blChangeColour Then
'ctl1.BackColor = Color.Yellow

Select Case intFocusType
Case FocusType.BackgroundColor
ctl1.BackColor = Color.Yellow
Case FocusType.BorderColor
Dim g As Graphics = Me.CreateGraphics
Dim pen As New Pen(Color.Yellow, 5.0)
g.DrawRectangle(pen, New _
Rectangle(ctl1.Location, ctl1.Size))

End Select


End If



End Sub

Function needToChangeControlColourOnFocusChange(ByVal control1 As Control) As Boolean
' Don't change colour if control is not enabled or read only
Dim blSetColour As Boolean = True
If control1.Enabled = False Then
Return False
End If
If TypeOf (control1) Is TextBox Then
Dim txt1 As TextBox
txt1 = control1

If txt1.ReadOnly Then
Return False
End If
End If
Return True
End Function

Sub AddChangeColourOnFocusLostFocusHandlers()
' Can call this on form load on whenever you want to enable the colour changing
For Each control1 As Control In Me.Controls
Me.AddHandlersForLostFocusOnControlAndChildControls(control1)
Next
End Sub

Private Sub AddHandlersForLostFocusOnControlAndChildControls(ByVal control1 As Control)
For Each ctrlChild As Control In control1.Controls
Me.AddHandlersForLostFocusOnControlAndChildControls(ctrlChild)
Next
If TypeOf (control1) Is TextBox Or TypeOf (control1) Is ComboBox Then
AddHandler control1.GotFocus, AddressOf Me.SetControlBackgroundToYellowOnFocus
AddHandler control1.LostFocus, AddressOf Me.SetControlBackgroundToWhiteOnLostFocus
End If
End Sub


#End Region




Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AddChangeColourOnFocusLostFocusHandlers()
End Sub

26 Oct 2009

SQL Server 2008 & Windows 7

We have just moved Arkle ePos to use SQL Server 2008. No problems at all.
We have also tested on Windows 7 (32 bit) and it works.

7 Oct 2009

Enums / Data Binding

I use enums in my code a lot.
Often I have to set the various enumerations into the text in a text box. This is simple:

Me.ComboBoxGameCode.DataSource = System.Enum.GetValues(GetType(NumbersGameDraw.GameType))

This is nice but not great.
Say we have enums representing multiple words (for example the following)
Paid
NotPaid (we would like NotPaid to display as Not Paid).

So I created enumhelper class to do this:

Public Class EnumHelper
Private Shared Function ChangeHungarianTextToSeperateWords(ByVal originalText As String) As String

Dim strOutput As String = ""
Dim i As Integer = 0
While i < originalText.Length
Dim char1 As Char
char1 = originalText.Substring(i, 1)

If Char.IsUpper(char1) Then
strOutput &= " " & char1
Else
strOutput &= char1
End If
i += 1
End While
Return strOutput.Trim

End Function

Public Shared Function GetEnumSeperateWordsList(ByVal enumType As Type) As ArrayList
Dim x = System.Enum.GetNames(enumType)
Dim y As New ArrayList

For Each item1 As Object In x
'item1 = Me.ChangeHungarianTextToSeperateWords(item1)
y.Add(EnumHelper.ChangeHungarianTextToSeperateWords(item1))
Next
Return y

End Function
End Class

6 Oct 2009

Numeric Up Down and the tab key

When users have to enter data in numerous numeric up down and tab between them, they can't just key the new amount.

Say 1 is in the numeric up down they have just tabbed to and they type 2, it will go to 21 (instead of 2 which they wanted).

So for this I have put a bit of code on the got focus

Private Sub NumericUpDown1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NumericUpDown1.GotFocus
Me.NumericUpDown1.Select(0, Me.NumericUpDown1.Value.ToString.Length)
End Sub



Private Sub NumericUpDown2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NumericUpDown2.GotFocus
Me.NumericUpDown2.Select(0, Me.NumericUpDown1.Value.ToString.Length)
End Sub

This selects the whole value and allows them to type.
Why does the control not just behave like this in the first place?

Also I'm toying with setting background colours to yellow when controls have focus and back to white when they do not, this is much better than the less subtle built in controls.

26 Sept 2009

T-SQL Get dates on a specific day when you don't care about time

Quite often I have to write queries to return rows where something happened on a specific day. But the values in the table could be anytime within that day.

Previous I would pass in a start date, end date to do this, but the query then needs 2 parameters and it looks a bit cumbersome.

I came across this method which I now employ. Don't know if this has much performance impact, but it certainly is quicker to code and takes less parameters from calling application.

Where
(
DateDiff(day, @ReportStartDate,TerminalSession.StartDate) = 0

--StartDate >= @ReportStartDate
--And
--EndDate >= @ReportEndDate
)

9 Sept 2009

Code Rush : Refactor

Had tried this out a few years back, and it ate up my CPU/Memory so unistalled it on the day I installed it.

Just downloaded the latest version available on their website

Structural highlighting is my favourite feature to date (even though it isn't much of a time saver)

Have to say no speed/cpu/memory issues now, and the product is SUPERB.
It is going to save me so much time coding I might cut down to a 6 day working week.