Monday, June 22, 2009

Padding out a cell with leading zeros in Excel


Or you can use the Format->Custom and enter 0000

Excel Formula to extract the Path from a filename

If you have C:\Temp\Files\1.txt
this wil lreturn C:\Temp\Files\


Changing the Icon for an Application

For some reason I forgot about this. But when you launch an application, I know about having an icon for the form, but I forgot about having an icon for the application so that when it runs it has your icon on the task bar.

To do this its real simple. Just go to the Project Properties. Click on the Application Tab (it is probably the default selection). Then select "Icon:" and browse to in icon that you would lile. That's it.

Friday, June 19, 2009

How to return a dialog box result

I keep forgetting this but when you show a form via Showdialog you can check to see how that form was closed via  something like this:

If Form1.ShowDialog() = Windows.Forms.DialogResult.OK Then
End if

However when you do this in your Form1 you will need to specify the Dialog Result with something like this:

  Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
    Me.DialogResult = Windows.Forms.DialogResult.OK
  End Sub

  Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
    Me.DialogResult = Windows.Forms.DialogResult.Cancel
  End Sub

More info (barely) can be found here :

Wednesday, June 17, 2009

Read in a tab delimited file in

If its a comma delimited file you can change ControlChars.Tab to ","
        Dim fields As String()
        Dim delimiter As String = ControlChars.Tab
        Using parser As New TextFieldParser(MultipleInputFile)
          While Not parser.EndOfData
            ' Read in the fields for the current line
            fields = parser.ReadFields()
            ' Add code here to use data in fields variable.
          End While
        End Using

How to determine if the Mouse is over a Control that is within another Control

You could so something in the MouseMove, MouseEnter, MouseLeave events, but I like this solution below. It uses a Timer and the on the Timer Click events it can determine if a control has Focus. In the situation below, I have two controls that are within a splitcontainer. when I mouse over the control, I want that control to have focus. For some reason it wasn't happening, and this code below takes care of that situation. I also had to use the PointToScreen call because the Controls are within the splitContainer and I wasn't getting the proper position otherwise.

Private WithEvents mTimer As Timer
Public Sub New()
' This call is required by the Windows Form Designer.
' Add any initialization after the InitializeComponent() call.
mTimer = New Timer()
mTimer.Interval = 200
mTimer.Enabled = True
End Sub

Private Sub mTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles mTimer.Tick
Dim CursorPosition As Point = PointToScreen(Cursor.Position)
Dim Control1Bounds As New Rectangle(ImageContainer1.PointToScreen(Control1.Location), Control1.Size)
Dim Control2Bounds As New Rectangle(ImageContainer2.PointToScreen(Control2.Location), Control1.Size)

If Control1Bounds.Contains(CursorPosition) Then
ElseIf Control2Bounds.Contains(CursorPosition) Then
End If
End Sub

Detect Active Control on a Form

You can use the Me.ActiveControl property, additionally if a control is withing another control you can call this property from the control.  For Example if you have a SplitContainer which has another control in it you can do the following:

If Me.ActiveContainer Is SplitContainer1 Then
   If SplitContainer1.ActiveControl Is MyControl1 Then
        Do Something

Detect the Ctrl Key plus another key

Make sure the KeyPreview property is set to true
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.Modifiers = Keys.Control Then
            If e.KeyCode = Whatever key ou want
            End If
        End If
End Sub

Wednesday, June 3, 2009

itunes was unable to load provider data from sync services

I got this message when plugging in my ipod to my computer.

The solution seems to be this (at least it worked for me):
1.  I clicked ok, then waited for the sync to complete.  It appears that despite the message it still syncs but slowly and sometimes not all the files are synced with this error.  I then unplugged my ipod and closed itunes.
2.  Go to Control Panel > Administrative Tools > Services. Select 'Apple Mobile Device' and on the left side click 'Stop the service'. After it has stopped then select 'Start the service'. Then try opening iTunes again (I just plugged in my ipod back in and that launched itunes)

Solution was found towards the bottom of this page.  The message board has a lot of different solutions that seem to work for some but not for others