January 2007 Entries
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...
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...
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...
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.
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...
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...
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.