January 2007 Entries

System Icons in C++ and BCB

I am just going through some of my old code looking for useful snippets. I found one snippet that was pretty cool (at least it was at the time!) where I used a grid control to display items for the user to configure. The grid had folders and so I wanted to use the system folder icon that are used in Windows Explorer. After a little searching on the Internet and MSDN, I came up with the following: #include <shellapi.h> // ... SHFILEINFO shfi; HIMAGELIST hImageList = NULL; HICON hIconClosed = NULL; HICON hIconOpen = NULL; UINT flags; // Closed folder ZeroMemory(&shfi, sizeof(shfi)); flags = SHGFI_ICON | SHGFI_SYSICONINDEX | SHGFI_SMALLICON; hImageList...

posted @ Friday, January 26, 2007 1:05 PM | Feedback (0)

Custom Skins in SubText

I emailed Phil Haack trying to figure out how to use dp.SyntaxHighlighter in SubText, and he pointed out the custom skins. I'm still working on the highlighting, but I seem to be running into a problem. When I restart IIS, it seems SubText is trying to add the custom skin styles more than once and crashing with a duplicate key: An item with the same key has already been added. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where...

posted @ Wednesday, January 24, 2007 9:50 PM | Feedback (0)

Convert date to UTC format in JavaScript

A couple of years ago I had to print dates in JavaScript in UTC (ISO-8601) format. Here is the function that I developed. It assumes the date object has the correct time zone offset and uses the time zone offset from the object. I also developed server-side C# code for formatting dates in ASP.NET pages which I'll post soon. function pad(value, digits, padtext) { if (!padtext) padtext = "00000000"; if ((digits == null) || (typeof(digits) == "undefined")) return value; if ((value == null) || (typeof(value) == "undefined")) return value; var length = value.toString().length; if ((length < digits) && (digits < padtext.length)) return padtext.substr(0, digits - length) + value.toString(); else return value; } function...

posted @ Tuesday, January 23, 2007 10:45 AM | Feedback (0)

Still trying to syntax highlight in Blog

Well I'm still trying to figure out how to enable syntax highlighting with dp.SyntaxHighlighter in Subtext. I wrote a simple syntax highlighter in VB a long time ago that output HTML with CSS styles for operators, keywords, strings, and numbers but it was a static application. The dp.SyntaxHighlighter component is able to dynamic parse the syntax and highlight the code. In comparison, the static parser output plain HTML that could easily be pasted into a blog. There are advantages to each method, but the highlighting in dp.SyntaxHighlighter is pretty cool.

posted @ Monday, January 22, 2007 10:47 AM | Feedback (1)

C# Utility to export Excel Worksheet As ADO Recordset XML

I wrote a little VBA the other day to save an Excel Worksheet as an ADODB.Recordset XML file. I decided to see how hard it would be to do the exact same thing in C#. The idea is that I might start using C# Script instead of JavaScript for little utilities in the future. using System; using System.Collections.Generic; using System.Data; using System.Reflection; using System.Runtime.InteropServices; using ADODB; using Excel; namespace ExcelUtility { class ExcelExport { public const string EXCEL_PROG_ID = "Excel.Application"; public static Excel.Application ExcelApplication { get { Excel.Application app = null; try { // http://msmvps.com/blogs/pauldomag/archive/2006/03/15/86417.aspx app = Marshal.GetActiveObject(EXCEL_PROG_ID) as Excel.Application; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); } if (app == null) { try { app = new Excel.ApplicationClass(); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); } } return app; } } public static System.Data.DataTable SaveWorksheetAsDataTable() { Excel.Application app = ExcelApplication; Excel.Workbook book = app.ActiveWorkbook as...

posted @ Friday, January 19, 2007 7:52 AM | Feedback (0)

Export Excel Worksheet to ADO Recordset

This weekend I was working on a spreadsheet and I needed to save the data as a recordset. Unfortunately there didn't seem to be a way to do it easily without VBA macros. So I wrote this macro to save the current worksheet as an ADODB.Recordset XML file. Remember to add a reference to Microsoft.ActiveX Data Object 2.8 Library in the Excel Visual Basic Editor. Public Sub CreateAdoRecordsetXml() Dim rst As New ADODB.Recordset Dim sheet As Worksheet Dim col As Long, colcount As Long Dim row As...

posted @ Monday, January 15, 2007 12:22 PM | Feedback (0)

Welcome

Welcome to my blog. I will be writing about a variety of programming languages and adventures in C#, ASP.NET, Python, JavaScript, C/C++, and anything else I can think of.

posted @ Saturday, January 13, 2007 12:19 PM | Feedback (0)