Author Archive

TFS in Excel: Exporting Charts Using VBA

Problem You want to automate the exporting of a chart within an Excel worksheet to a PNG image file using a VBA macro. Solution Private Sub ExportChartToFile(Worksheet as String, ChartNumber As Integer, Filename As String) Dim objChrt As ChartObject Dim myChart As Chart Dim FilePath As String Set objChrt = Sheets(“Worksheet”).ChartObjects(n) Set myChart = objChrt.Chart […]

TFS in Excel: Refreshing a TFS Query Using VBA Macro in Excel

Problem You have a Team Foundation Server connected worksheet in Excel 2010, and want to automate the clicking of the Refresh button on the Team ribbon. Solution Add these two procedures to your VBA macro: Private Sub RefreshTeamQueryOnWorksheet(worksheetName As String) Dim activeSheet As Worksheet Dim teamQueryRange As Range Dim refreshControl As CommandBarControl Set refreshControl = […]

iOS: UIAlertView as an Input Dialog

Problem: You want a simple input dialog to have the user enter a text in iOS. Solution: You can use an UIAlertView: UIAlertView * inputAlert = [[UIAlertView alloc] initWithTitle:@”New Event” message:@”Enter a title for the event” delegate:self cancelButtonTitle:@”Cancel” otherButtonTitles:@”OK”, nil]; inputAlert.alertViewStyle = UIAlertViewStylePlainTextInput; [inputAlert show]; You also need to add the UIAlertViewDelegate protocol to the […]

iOS: Running Code on the Main Thread

Problem: In iOS, updating the user interface should be done in the main thread. However, many asynchronous methods invoke the callback on an arbitrary thread. How can I make sure a particular piece of code is run in the main thread? Solution: You need to use the grand central dispatch: dispatch_async(dispatch_get_main_queue(),^{ // The code to […]

Setting Up A Navigation-based Application Programmatically

Problem: To avoid using singleton models in your iPhone/iPad apps, it’s necessary to create the root view programmatically. This way you’re able to inject the model at creation time instead of in the viewDidLoad method. Solution: Here’s how to set up a navigation-based application in code in XCode 4.2 (with automatic memory management enabled). In […]

UNC Paths in Windows Command Shell

Problem: Copy and other command shell commands don’t work with UNC paths, i.e. \\server\dir. Solution: Use pushd <path> to temporarily assign a drive letter and map it to the path. pushd \\server\rootfolder\subfolder When done, use popd to unmap the letter.

Extracting date and time from text using Ruby

Problem: We want to extract a date and time of the format YYYY-MM-DD MM:SS from a body of text using Ruby. Solution: This is extremely easy in ruby, and other languages that features regular expressions. require “Date” text = “Some text containing a date and a time, for instance 2010-03-19 17:25.” if text =~ /(\d{4})-(\d{2})-(\d{2}) […]

Upgrading a Customized WordPress Theme

Problem: You’re using a third party wordpress theme but have made changes to customize it for your own needs (changed a picture, added advertising, etc.). When the third party releases an upgrade to the theme you’d like to upgrade but don’t want to lose your changes. Solution: Let your version management system move your changes […]

Adding Linebreaks in C#

Problem: We want to insert linebreak character sequences into a string in C#.  Solution: The platform safe way of doing this is by using the Environment.NewLine property. msg = “An error occurred: ” + Environment.NewLine + e.Message; Composing a string with more than one line break can become really messy, so using string.Format might be a […]

Dynamic Updating of Action Visibilities

Problem: You want to change an action’s visible property and does so in its OnUpdate event handler, but it doesn’t seem to work. Once an action is hidden it can’t seem to become visible again.  Solution: By design Delphi won’t invoke OnUpdate event handlers for actions that have their Visible property set to false. Instead, […]