Featured Posts

<< >>

Chef Boy-R-Gee’s Mac & Cheese

Ingredients: 1 1/2 pounds (or so) of cooked elbow macaroni 8-10 ounces (total) of Sharp Cheese and Extra Sharp Cheese 4 Eggs beaten in 1.5 cups milk Cooking: Mix all ingredients in a large casserole dish and cover almost all the noodles with the egg/milk mixture Add salt and pepper Bake at 350 for 45 minutes [...]

Print Friendly

Enable/Disable Integrated Windows Authentication (VBScript)

Option Explicit ‘———————————————————————– ‘ Enable/Disable Windows Integrated Authentication setting in IE8 ‘ Developer: Tom Gee ‘ Date: 12.16.2011 ‘———————————————————————– Dim WSHShell, RegKey Dim strInput, strCurrValue, strEnabled, strDisabled, strNewValue strEnabled = “enabled” strDisabled = “disabled” set WSHShell = CreateObject(“WScript.Shell”) RegKey = “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\EnableNegotiate” ReadRegistry strInput = MsgBox(“Integrated Windows Authentication is currently ” & strCurrValue & “.” [...]

Print Friendly

Increase/Decrease Textbox Font Size Programatically (VB.NET)

Private Sub frm_Main_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown ‘ Ctrl + + = increase the SQL size If e.Control And e.KeyCode = Keys.Add Then Using f As Font = TextBox1.Font TextBox1.Font = New Font(f.FontFamily, f.Size + 1, f.Style) End Using Exit Sub End If ‘ Ctrl + – = decrease the SQL size [...]

Print Friendly

Capture when Ctrl+Enter keys are pressed at the same time (VB.NET)

Make sure your Form’s KeyPreview property is set to True. Private Sub frm_Main_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.Control And e.KeyCode = Keys.Enter Then ‘ Do something End If End Sub You can also capture when the Alt+Enter keys are pressed at the same time with the following: Private Sub frm_Main_KeyDown(sender As [...]

Print Friendly

Populate a DataGridView with SqlDataReader

In order to display the data in a SqlDataReader object in a DataGridView control, you first need to load the data into a DataTable object. The code below is in C# and the Connection String is for a SQL Server database connection. using System.Data.SqlClient; SqlConnection con = new SqlConnection(); SqlCommand cmd = new SqlCommand(); SqlDataReader [...]

Print Friendly

iTunes Sync Error (-50)

About 3 months ago I began receiving the following error in iTunes when trying to sync a Smart Album in Aperture 3 to my iPad and iPhone 4. “The iPad “Tom Gee’s iPad” cannot be synced. An unknown error occurred (-50).” Narrowing down the picture(s) that were causing the issue was not a fast process [...]

Print Friendly

Ian McKellen Impression–Fresh Prince Of Bel-Air

[viddler id=9db9a6f0&w=437&h=288]

Print Friendly

Create a File Picker That Defaults to The Desktop (C#)

OpenFileDialog fd = new OpenFileDialog(); fd.InitialDirectory = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); fd.ShowDialog(); MessageBox.Show(fd.FileName); // show the selected File path

Print Friendly

How to fetch data from using a BackgroundWorker (VB.NET)

BackgroundWorkers (which I will refer to as bgWorker) are great for doing background processing in your application, thus preventing your program from going into a “Not Responding” status.  One downfall, however, is that you cannot pass or reference data in a separate thread from the bgWorker.  The following code shows how to get around this [...]

Print Friendly

How to check/uncheck “child” nodes in a TreeView (C# & VB.NET)

Call this method from within your TreeView’s “AfterCheck” event. Pass it the AfterCheck event’s “sender” and “e” parameters. C# private void CheckChildren(object sender, TreeViewEventArgs e) { bool boolChecked = e.Node.Checked; if (e.Node.Parent == null) // parent node { foreach (TreeNode node in e.Node.Nodes) node.Checked = boolChecked; } } VB.NET: Private Sub CheckChildren(sender As Object, e [...]

Print Friendly

Chef Boy-R-Gee’s Mac & Cheese

Ingredients:
  • 1 1/2 pounds (or so) of cooked elbow macaroni
  • 8-10 ounces (total) of Sharp Cheese and Extra Sharp Cheese
  • 4 Eggs beaten in 1.5 cups milk

Cooking:

  • Mix all ingredients in a large casserole dish and cover almost all the noodles with the egg/milk mixture
  • Add salt and pepper
  • Bake at 350 for 45 minutes (give or take)

Topping (optional):

  • 2 tablespoons unsalted butter
  • 2 cups Panko bread crumbs
  • 1 cups extra sharp cheese

Melt butter and stir together with bread crumbs and cheese until combined well.

Print Friendly

Enable/Disable Integrated Windows Authentication (VBScript)

Option Explicit

'-----------------------------------------------------------------------
'	Enable/Disable Windows Integrated Authentication setting in IE8
'	Developer:	Tom Gee
'	Date:		12.16.2011
'-----------------------------------------------------------------------

Dim WSHShell, RegKey
Dim strInput, strCurrValue, strEnabled, strDisabled, strNewValue

strEnabled = "enabled"
strDisabled = "disabled"

set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\EnableNegotiate"

ReadRegistry

strInput = MsgBox("Integrated Windows Authentication is currently " & strCurrValue & "." & vbcrlf & vbcrlf & "Do you want to change this value?",vbYesNo,"Change Current Value?")

If strInput = vbYes Then
	If strCurrValue = strEnabled Then
		strNewValue = "0"
	Else
		strNewValue = "1"
	End If

	WSHShell.RegWrite RegKey, strNewValue, "REG_DWORD"

	ReadRegistry

	strInput = MsgBox("Integrated Windows Authentication has now been set to " & strCurrValue & ".")
End If

Sub ReadRegistry()
	strCurrValue = WSHShell.RegRead(RegKey)

	If strCurrValue = "1" Then
		strCurrValue = strEnabled
	Else
		strCurrValue = strDisabled
	End If
End Sub
Print Friendly

Increase/Decrease Textbox Font Size Programatically (VB.NET)

Private Sub frm_Main_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        ' Ctrl + + = increase the SQL size
        If e.Control And e.KeyCode = Keys.Add Then
            Using f As Font = TextBox1.Font
                TextBox1.Font = New Font(f.FontFamily, f.Size + 1, f.Style)
            End Using
            Exit Sub
        End If

        ' Ctrl + - = decrease the SQL size
        If e.Control And e.KeyCode = Keys.Subtract Then
            Using f As Font = TextBox1.Font
                TextBox1.Font = New Font(f.FontFamily, f.Size - 1, f.Style)
            End Using
            Exit Sub
        End If
End Sub
Print Friendly

Capture when Ctrl+Enter keys are pressed at the same time (VB.NET)

Make sure your Form’s KeyPreview property is set to True.

    Private Sub frm_Main_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.Control And e.KeyCode = Keys.Enter Then
            ' Do something
        End If
    End Sub

You can also capture when the Alt+Enter keys are pressed at the same time with the following:

    Private Sub frm_Main_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.Alt And e.KeyCode = Keys.Enter Then
            ' Do something
        End If
    End Sub
Print Friendly

Populate a DataGridView with SqlDataReader

In order to display the data in a SqlDataReader object in a DataGridView control, you first need to load the data into a DataTable object. The code below is in C# and the Connection String is for a SQL Server database connection.

using System.Data.SqlClient;

SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;

// set the connection string
con.ConnectionString = "Data Source=SqlServerName;Initial Catalog=DbName;Integrated Security=True"
con.Open();

string SQL = "SELECT * FROM tbl_Users";

// create the SQL command
cmd = new SqlCommand(SQL, con);

// execute the SQL
dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

DataTable table = new DataTable();
table.Load(dr);

reader.Close();
reader.Dispose();
con.Close();
con.Dispose();
cmd.Dispose();
cmd = null;

// Display the data in the DataGridView control...
DataGridView1.DataSource = table;
Print Friendly

iTunes Sync Error (-50)

About 3 months ago I began receiving the following error in iTunes when trying to sync a Smart Album in Aperture 3 to my iPad and iPhone 4.

“The iPad “Tom Gee’s iPad” cannot be synced. An unknown error occurred (-50).”

iTunes Error (-50)

iTunes Error (-50)

Narrowing down the picture(s) that were causing the issue was not a fast process because the Smart Album in question had 1,500+ images in it.  I began my troubleshooting process by adding a Date filter to the Smart Album and then syncing the updated album to my iPad via iTunes.  After about an hour, I identified the date that contained the photos which were causing the issue.

I then switched my Aperture Browser view to List View (see 1 below) and then scrolled through the data to see if anything looked odd to me.  Immediately, I saw that there a bunch of photos that had a Project Path of “Facebook” (see 2 below).  I right-clicked some of the photos and selected Show in Project, but there was no project found; simply an empty browser window.

Instead of deleting the photos from my Aperture library, I updated my Smart Album properties to exclude any items that contained the text “Facebook.”

Updated Smart Album Properties

Updated Smart Album Properties

After doing this, I tried syncing the Smart Album to my iPad via iTunes and all the photos/videos copied over without error!

I hope this helps others who may be having the same problem that I was! =D

Print Friendly

Ian McKellen Impression–Fresh Prince Of Bel-Air

[viddler id=9db9a6f0&w=437&h=288]

Print Friendly

Create a File Picker That Defaults to The Desktop (C#)

OpenFileDialog fd = new OpenFileDialog();

fd.InitialDirectory = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));

fd.ShowDialog();

MessageBox.Show(fd.FileName); // show the selected File path
Print Friendly

How to fetch data from using a BackgroundWorker (VB.NET)

BackgroundWorkers (which I will refer to as bgWorker) are great for doing background processing in your application, thus preventing your program from going into a “Not Responding” status.  One downfall, however, is that you cannot pass or reference data in a separate thread from the bgWorker.  The following code shows how to get around this by utilizing Global/Public variables because they are referenced between all threads of the application.


Global/Public Variables

 ' public variables
Public dr As OdbcDataReader
Public conn As OdbcConnection

Dim miliSecond As Long = 1000
Dim timerSeconds As Long
Dim startDttm As Date
Dim endDttm As Date
Dim sqlComm As String
Dim dt As New DataTable
Dim da As New OdbcDataAdapter
Dim strConnString As String
Dim comm As OdbcCommand

How to call the BackgroundWorker

bgWorker = New BackgroundWorker
bgWorker.WorkerReportsProgress = True
bgWorker.WorkerSupportsCancellation = True
bgWorker.RunWorkerAsync() ' run the background worker

Run the BackgroundWorker and fetch the data

Private Sub FetchData(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles bgWorker.DoWork
Try
Dim conn As New OdbcConnection(strConnString)
startDttm = Now()

comm = New OdbcCommand(sqlComm)
comm.Connection = conn
comm.Connection.Open()

dt = New DataTable
da = New OdbcDataAdapter
da.SelectCommand = comm ' Utilize the SELECT statement
da.Fill(dt) ' Fill the Data Table

Catch ex As Exception
MsgBox("ERROR: " & ex.Message, MsgBoxStyle.Critical, "Error running SQL")
dbClose()
End Try
End Sub

What to do when the BackgroundWorker is finished

Private Sub bgWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles bgWorker.RunWorkerCompleted
Try
UpdateDataGrid()

Catch ex As Exception
bgWorker.CancelAsync()
End Try
End Sub

Update the DataGridView (dg)

Private Sub UpdateDataGrid()
Try
Dim intCount As Integer
intCount = dt.Rows.Count ' number of rows returned by SQL

Select Case intCount
Case Is < 1000 ' fill if less than 1000 rows
Me.dg.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
dg.DataSource = dt ' Populate the Data Grid with the Data Table values
dr = comm.ExecuteReader
Case Else
If MsgBox("This will display " & Format(dt.Rows.Count, "###,###,##0") & " rows. Would you like to continue?", MsgBoxStyle.YesNo, "Continue?") = MsgBoxResult.Yes Then
Me.dg.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
dg.DataSource = dt ' Populate the Data Grid with the Data Table values
dr = comm.ExecuteReader
End If
End Select

dbClose()

dg.AutoResizeColumns()

If comm.ExecuteNonQuery >= 0 Then
intCount = comm.ExecuteNonQuery
End If

AddToSummary(Format(intCount, "###,###,##0") & IIf(intCount = 1, " record found", " records found"), False)

Dim dur As Global.System.TimeSpan = Now.Subtract(startDttm)
AddToSummary(" - " & dur.Seconds & "." & dur.Milliseconds & " seconds", True)

Catch ex As Exception
MessageBox.Show("Error updating data grid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

Close the Database Connection

Private Sub dbClose()
Try ' Close the Data Reader
dr.Close()
dr = Nothing
Catch ex As Exception
'MsgBox("Error closing the data reader" & vbCrLf & ex.Message, MsgBoxStyle.Critical, "Data Reader Close Issue")
End Try

Try ' Close the Connection
conn.Dispose()
conn = Nothing
Catch ex As Exception
MsgBox("Error closing the connection" & vbCrLf & ex.Message, MsgBoxStyle.Critical, "ODBC Connection Close Issue")
End Try
End Sub

Add to Summary method - I use a TextBox (txt_Status) on my Form for displaying application status to the user

Private Sub AddToSummary(ByVal strText As String, ByVal Append As Boolean)
If Append Then
Me.txt_Status.Text += strText
Else
Me.txt_Status.Text = strText
End If
End Sub
Print Friendly

How to check/uncheck “child” nodes in a TreeView (C# & VB.NET)

Call this method from within your TreeView’s “AfterCheck” event. Pass it the AfterCheck event’s “sender” and “e” parameters.

C#

        private void CheckChildren(object sender, TreeViewEventArgs e)
        {
            bool boolChecked = e.Node.Checked;

            if (e.Node.Parent == null) // parent node
            {
                foreach (TreeNode node in e.Node.Nodes)
                    node.Checked = boolChecked;
            }
        }

VB.NET:

    Private Sub CheckChildren(sender As Object, e As TreeViewEventArgs)
        Dim boolChecked As Boolean = e.Node.Checked

        If (e.Node.Parent Is Nothing) Then ' parent node
            For Each tn As TreeNode In e.Node.Nodes
                tn.Checked = boolChecked
            Next
        End If
    End Sub
Print Friendly