Tuesday, 5 August 2008

 

Change Default for Show Markup in MS-Word 2003

An annoying feature in Microsoft Word 2003 is that the default setting for the Reviewing toolbar is Final Showing Markup, so that all changes in your documents are highlighted when you open it, even after you accept all changes and saved the document previously. The solution is to unset your Security option Make hidden markup visible when opening or saving.. See How to turn off annoying MS Word Features, 'Change Default for "Show Markup" Box' for this and other solutions to Word annoyances.

Labels: ,


Wednesday, 18 June 2008

 

Creating UML Composite States in Sparx Enterprise Architect

How to create a UML composite state element using Sparx Systems' Enterprise Architect application:

  1. In a state machine diagram, create a new state element.
  2. Select the state element's context menu item Advanced / Composite Element.

The selected state element is converted into a composite state element (the image has a infinity symbol) with its own state machine diagram (check the Project Browser). Now you can draw a transition line to and from this composite state and include it in state transition tables.

Annoyingly, Enterprise Architect's on-line help describes a composite element but doesn't show to make one!

Labels: ,


Tuesday, 10 June 2008

 

Visio 2003 Cannot Resize Shape Directly with Keyboard

Microsoft Visio 2003 doesn't provide keyboard shortcut for the user to resize a shape instance. You have to use the mouse pointer or (shudder) enter the required height and width of the shape in the Size & Position window.

Labels: ,


Saturday, 24 May 2008

 

Fix Incorrectly Encoded Unicode Files with Python

The Problem

We had a lot of text files committed into our CVS repository as Unicode format. When these files were checked out later, we found that they weren't really text files nor Unicode files because CVS had only prepended two bytes to the start of these files, FF FE, but left only one byte for encoding each character. Some text editors such as Vim could open these files but other applications such as Notepad and Excel showed only gibberish.

Unicode Encoded Text in Files

Unicode is an encoding standard … for processing, storage and interchange of text data in any language. For the purpose of fixing this problem, we just have to know how to identify and write valid Unicode files.

We use two tools to experiment and visualize the effect of different encoding methods:

  1. Microsoft Notepad editor, because it can save text files using different encoding methods.
  2. GnuWin32 od utility to output the data in a file as byte values.

Open Notepad and enter this text: Hello World. Select the File / Save As menu item. In the Save As dialog, there are four encoding methods in the Encoding drop down list: ANSI, Unicode, Unicode big endian and UTF-8. Save the same text using each of the encoding methods into four files, say TestANSI.txt, TestUnicode.txt, TestUnicodeBigEndian.txt and TestUTF8.txt, respectively.

Examine the contents of each file using od:

>od -A x -t x1 HelloANSI.txt
000000 48 65 6c 6c 6f 20 57 6f 72 6c 64
00000b

>od -A x -t x1 HelloUnicode.txt
000000 ff fe 48 00 65 00 6c 00 6c 00 6f 00 20 00 57 00
000010 6f 00 72 00 6c 00 64 00
000018

>od -A x -t x1 HelloUnicodeBigEndian.txt
000000 fe ff 00 48 00 65 00 6c 00 6c 00 6f 00 20 00 57
000010 00 6f 00 72 00 6c 00 64
000018

>od -A x -t x1 HelloUTF8.txt
000000 ef bb bf 48 65 6c 6c 6f 20 57 6f 72 6c 64
00000e

The ANSI encoded file contains 11 bytes representing the characters you typed. The Unicode encoded files contain 24 bytes, starting with a two-byte BOM and using two bytes to represent each character. If the first two bytes are FF FE, then the two bytes are stored in low-byte, high-byte order. Conversely, if the first two bytes are FE FF, then the two bytes are stored in high-byte, low-byte order. Finally, when a file starts with byte EF BB BF, only one byte is used to encode each ANSI character and two or more bytes are used to encode non-ANSI characters (not demonstrated).

Fixing Incorrectly Encoded Files in Python

Now we know the format of a Unicode encoded file: it starts with FF FE and stores each character in low-byte, high-byte order. Our text files in CVS just have ANSI characters, so we just have to insert a 0 byte between each character, starting from the third byte. Julian W. wrote a short Python script that to do this. I don't have his code right now, so here's my version for correcting the Unicode encoding for a file:

import codecs
raw = map(ord, file(r'HelloBadUnicode.txt').read())
if raw[0] == 255 and raw[1] == 254 and raw[3] != 0:
  output = codecs.open(r'HelloFixedUnicode.txt', 'w', 'UTF-16')
  for i in raw[2:]:
    output.write(chr(i))
  output.close()

References

Postscript

I started with a more complicated piece of Python code using lists and generators:

from itertools import repeat
from operator import concat

raw = map(ord, file(r'HelloBadUnicode.txt').read())
if raw[0] == 255 and raw[1] == 254 and raw[3] != 0:
  output = file(r'HelloFixedUnicode.txt','w')
  output.write(chr(255))
  output.write(chr(254))
  for i in reduce(concat, zip(raw[2:], repeat(0, len(raw)-2))):
    output.write(chr(i))
  output.close()

But then I realised I just had to write a 0 byte after each ANSI character, so here's a simpler version:

raw = map(ord, file(r'HelloBadUnicode.txt').read())
if raw[0] == 255 and raw[1] == 254 and raw[3] != 0:
  output = file(r'HelloFixedUnicode.txt','w')
  output.write(chr(255))
  output.write(chr(254))
  for i in raw[2:]:
    output.write(chr(i))
    output.write(chr(0))
  output.close()

2008-05-25. I remembered that Python had no problems with writing Unicode files, resulting in the even simpler code in the body of this article.

Labels: , , ,


Tuesday, 13 May 2008

 

Outlook 2003 Save HTML Limitation

If want to save an e-mail message in HTML format in Microsoft Outlook 2003, you may find that Outlook, unlike MSIE or Firefox browsers, only saves the text in the message but not any of the embedded images or attachments. Worse, Outlook doesn't warn you that it is not saving the entire message.

Another annoyance is that if you try to save an image in the message using the context menu item Save Picture As, then you can only save using BMP format.

Labels: ,


Sunday, 11 May 2008

 

Assign USB Drives to Folder

Each time you plug in a USB device to your Windows computer, Windows can assign a different drive letter to your device. If you have programs that rely on a fixed drive letter (e.g. portable applications on a USB drive or backups) or if you use more than one computer regularly, then it gets annoying to reset the programs' configuration after plugging in your drive or remember to plug in devices in a particular sequence. Assign USB Drives to Folder describes how to use Window's Disk Management to assign a fixed path to each device.

I wonder if it's possible to refer to a device using its volume name, which would make this method redundant?

Labels: ,


Friday, 29 February 2008

 

Microsoft Access Export Truncates Numbers

Introduction

I wanted to export all tables from an Access database into a folder of CSV formatted text files. For most data types, such as Text or Integer, all data was exported without any loss. However, floating point numbers (Float or Double) were exported with only two decimal places.

Approach

You can export a Microsoft Access table to a text file using either the menu item File / Export or this Access SQL statement from KB208408

SELECT * INTO [Text;FMT=Delimited;HDR=Yes;Database=<Path>].[<Table>.csv] FROM <Table>

Solutions

Here's three solutions with varying advantages:

About Schema.ini File

A slight digression: schema.ini is a file used by the Text Driver to determine the characteristics of tables and columns of a database. You can find the syntax and properties of the schema.ini file in Schema.ini File (Text File Driver).

When exporting tables, Access creates a schema.ini file in the export folder if that file does not exist. If there is an existing schema.ini file and the section for the output CSV file does not exist, Access will add a new section for the output CSV file. Otherwise, Access does not change the schema.ini file.

Conclusion

None of the solutions are very satisfactory for writing a general program to export tables from an Access database into a folder of text files. The simplest solution is to define the required number of decimal places in the database connection string (the part between the square brackets in the SQL statement). However, I couldn't find any formal specification of this string on the Web.

Labels: ,


Tuesday, 26 February 2008

 

Edit Base Calendar in Project 2000

How to edit a base calendar in Microsoft Project 2000:

  1. Ensure that no or all rows in the Resource Sheet are selected.
  2. Select menu item Tools / Change Working Time.
  3. In Change Working Time dialog, select the required calendar from the drop down list, then edit the calendar.

Note that if some rows are selected in the Resource Sheet is selected, you can only change the calendar for the first resource in the selection, not a base calendar.

Labels: ,


Wednesday, 13 February 2008

 

Microsoft Excel Remove Empty Lines

If you get an Excel document that has empty rows, you can remove those empty rows by using the sort function (Data / Sort). Of course, you lose the original row order.

Another method is to use the "Go To" (F5) dialog to select all blank cells, then delete them (found in Joseph Rubin's Excel Tips).

Labels: ,


Tuesday, 12 February 2008

 

Copy-Paste Image from CHM to Microsoft Word

If you copy-paste an image from a CHM file to Microsoft Word, you end up with a blank rectangle in your Word document. The workaround is to paste the image to a drawing program (e.g. MSPaint), then copy-paste from the drawing program into Word. Why you need to do this two-step process?

Labels: , ,


Monday, 11 February 2008

 

Microsoft Outlook Rules and Duplicated E-mail

If you use Microsoft Outlook's rules to move incoming messages into folders, you could end up with duplicate e-mail messages if two or more rules can be applied.

Recently, I made new rules to move bug reports for some products into special product folders and I also had a "catch-all" rule to move all remaining bug reports into a general bug report folder. In other words, I had the following rules:

From bugsystem, Subject "product_1", move to "product_1" folder.
From bugsystem, Subject "product_2", move to "product_2" folder.
From bugsystem, move to "general" folder.

I thought once a rule was "fired" for a message, Outlook would process the next message. However when new bug reports arrived, Outlook created two copies of each message, one in the product's folder and one in the general bug report folder. It appears that Outlook processes all rules for a message before proceeding to the next message. Select the stop processing more rules action for each rule to make Outlook stop processing further rules for that message:

From bugsystem, Subject "product_1", move to "product_1" folder and "stop processing more rules".
From bugsystem, Subject "product_2", move to "product_2" folder and "stop processing more rules".
From bugsystem, move to "general" folder.

In Outlook 2003, Rules and Alerts dialog, you can see a hammer and spanner icon for each rule containing the stop processing more rules action.

Labels: ,


Friday, 8 February 2008

 

AutoIt Include Directory

Note to myself to remember to set the local Include directory value for AutoIt when I use another computer. The registry key is HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt.

Labels: ,


Wednesday, 6 February 2008

 

Excel Print Preview Cannot Repeat Row or Column

Quirk in MS-Excel: You can't select rows or columns to repeat if you open the Page Setup dialog in Print Preview (see knowledge base article 912069). The work around is simple: close Print Preview and select the menu item File / Page Setup.

Labels: ,


Thursday, 31 January 2008

 

SciTE Customization

Note for myself: global customization of the SciTE (Scintilla Text Editor) is stored in install\SciTEGlobal.properties file:

font.base=font:Courier New,size:9
indent.size=2
position.height=640
position.width=800
use.tabs=false

Labels:


Saturday, 1 December 2007

 

Making Paragraphs With Vim

E-books from Project Gutenberg are broken into 70-character lines. Fixed length lines can be hard to read on a mobile phone, so I wanted to let the phone's viewer break the lines and use only a blank line between paragraphs. Here's some text from Arthur Conan Doyle's A Scandal in Bohemia originally fro Project Gutenberg:

"Wedlock suits you," he remarked. "I think, Watson, that you have
put on seven and a half pounds since I saw you."

"Seven!" I answered.

"Indeed, I should have thought a little more. Just a trifle more,
I fancy, Watson. And in practice again, I observe. You did not
tell me that you intended to go into harness."

Below is how this text should become (paste the before and after text into your text editor to see the difference):

"Wedlock suits you," he remarked. "I think, Watson, that you have put on seven and a half pounds since I saw you."

"Seven!" I answered.

"Indeed, I should have thought a little more. Just a trifle more, I fancy, Watson. And in practice again, I observe. You did not tell me that you intended to go into harness."

The following command in Vim did the required conversion: %s/\(.\)\n\(.\)/\1 \2/. Basically, for every line, replace any new line character between any two characters with a whitespace.

Labels: ,


Tuesday, 15 May 2007

 

WinCVS Tcl Shell

Just noticed that I can enter Tcl commands in the WinCVS Output pane (see View / Output menu item). For instance …

info commands
tell socket subst open eof pwd glob list exec pid dir time eval lrange fblocked
lsearch gets case lappend proc break cvsentries variable llength …
info nameofexecutable
C:/Program Files/GNU/WinCvs 2.0/wincvs.exe
info tclversion
8.2

Useful commands for me, right now, are ls and pwd, so that I can open files or change the working directory in cmd shell.

Labels:


Tuesday, 17 April 2007

 

Pasting MS-Word Heading Numbers

When I cut a heading and its heading number from a Microsoft Word document and paste them into an Outlook 2003 HTML message or Wordpad, the heading numbers are always reset. For example, 4.1.1.1 My Heading is pasted as 1.1.1.1 My Heading. When you copy text into the clipboard, it can be copied using multiple formats (text, RTF, metafile, etc.). In this case, the plain text version has the correct heading number but the RTF version does not. Note that you can check the contents of the clipboard using clipbrd.exe.

Following on, I found that Outlook 2003 only allows the user to choose the paste format (Edit / Paste Special menu item) when the message is RTF, not HTML or plain text.

Labels: ,


Sunday, 1 April 2007

 

OpenOffice 2.2 Database Connection

OpenOffice.org has released version 2.2 of their office suite. Seems to be just a bug-fix release. Having installed the latest version, I thought I'd connect the Base product to my test MySQL database. It should have been painless but I kept getting a JDBC driver could not be loaded error. After some head-scratching, it turns out that the MySQL JDBC driver had to be copied into the Java Runtime (JRE) ext folder. Here's how I set up a connection between OpenOffice and MySQL.

  1. Download and extract mysql-connector-java-5.0.4-bin.jar.
  2. Copy mysql-connector-java-5.0.4-bin.jar to C:\Program Files\Java\jre1.5.0_11\lib\ext\ folder.
  3. Start OpenOffice and select Tools / Options menu item, then select Java from the tree pane.
  4. In Java Options pane, select the appropriate JRE and select the OK button.
  5. In OpenOffice, select File / New / Database menu item.
  6. In Select Database step, select Connect to an existing database radio button, select MySQL from the drop down list, then press the Next button.
  7. In Set up MySQL connection step, select Connect using JDBC (Java Database Connectivity) radio button, then press the Next button.
  8. In Set up JDBC connection step, press Test class button. If your connector is copied in the JRE's ext, then the JDBC Driver Test dialog should report The JDBC driver was loaded successfully. If the test fails, it will report The JDBC driver could not be loaded. Close the test dialog and continue configuring your database connection.
  9. Enter the Name of the database (e.g. test), Server URL (e.g. localhost) then press the Next button.
  10. In Set up user authentication step, enter User name (e.g. root) then press Test Connection button. If the connection was unsuccessful, the Connection Test dialog should report Access denied for user 'X' to database 'Y'. Close the test dialog and press the Next button.
  11. In Save and proceed step, use the default options then press the Finish button. OpenOffice will prompt you to save the database connection as an .odb file.

Notes: OpenOffice doesn't find the MySQL driver class after setting the CLASSPATH in the Options dialog. Another bug is that I can't remove a wrong JAR entry from the Options dialog.

Labels: ,


 

Virtual CDs with MagicDisc

Tired of inserting a key disk whenever you want to play a game? Worried that your kids might destroy your CD drive? Or just annoyed with Windows' Autoplay spinning up your CD drive each time you insert a new CD*. One solution: install a virtual CD drive. There's plenty available; I chose MagicDisc because the instructions were straightforward.

*Of course, you can also disable Autoplay. Here's one way:

  1. Run gpedit.msc.
  2. In Group Policy dialog, select Computer Configuration / Administrative Templates / System / Turn off Autoplay.
  3. In Turn off Autoplay dialog, select Enabled radio button.

Labels: , ,


Saturday, 24 February 2007

 

SyncBack Website Synchronization

It's getting hard to manually keep files on my computer and web server for my little hobby web site in sync. For instance, I wanted to show someone a new page but forgot to upload the latest version of the index page so he couldn't find it; that's at least one reason to use a content management system.

After the usual trawl through download sites, I found SyncBack which provides the synchronization feature that I want. Like backup tools, you configure a profile, test the profile by doing a simulated run all the right files are copied, then execute or schedule a date to execute that profile. SyncBack's profile dialog has Easy and Expert modes. To synchronize my local files and FTP server, I had to use the Expert mode so that I can enter my FTP server's details. The profile dialog in this mode becomes too busy with a lot of tabs and options. It's also confusing to have two tabs called Simple and Advanced. These are just quibbles because I got a synchronization profile working fairly quickly.

Labels:


Friday, 23 February 2007

 

WinMerge 2.6 and 7-Zip 4.42

Noticed that WinMerge 2.6 was released in Jan 07. The toolbar icons are prettier than version 2.4 and the directory comparison no longer has the annoying popup dialog each time you change directories.

While looking at WinMerge, I found a free archive library and GUI called 7-Zip which seems to work as well as Winzip. I'm not too fussed with having better compression but the two-pane feature seems interesting.

Labels:


Saturday, 27 January 2007

 

2xExplorer DOS Command

You can start a DOS command in 2xExplorer by hitting the F10 key. However, if you simply hit Enter instead of typing a DOS command, a Cmd window opens in the folder currently displayed in 2xExplorer. Now I can avoid the annoying problem with the Windows cd command.

Labels: ,


Friday, 3 November 2006

 

Misc: Vim No Backup

I got a new workstation at work and reinstalled Vim. Then vim started creating backup files with the tilde (~) and .bak extensions. Right-O, no problem. I edited my _vimrc file and added set nobackup and set nowritebackup but that didn't work. Puzzled about this problem off-and-on for a couple of weeks. It turns out that I added my settings before source $VIMRUNTIME/vimrc_example.vim and source $VIMRUNTIME/mswin.vim. Duh! My configuration settings were being overrode by the default settings. I moved my configuration settings below those two lines and vim behaved as expected.

Labels:


Sunday, 8 October 2006

 

Article: Blender for Windows Users

After struggling for an hour trying to use Blender, a 3D modelling, animation and rendering tool, I wrote a short article describing its GUI to get a better understanding. Maybe it will be useful to other beginners as well.

Labels:


Thursday, 16 March 2006

 

Software: 2xExplorer Remove Search Results

Nikos Bozinis' 2xExplorer (a Windows Explorer replacement) has a neat but not so obvious feature. When you search for all files or folders with a certain pattern, 2xEplorer will display the search results window. Selecting an item in that window will cause the main window to jump to that item in your filesystem. The not-so-obvious feature is that when you delete items in the search results window, those items are deleted in your filesystem! This feature came in handy when I wanted to delete all CVS folders (to set up a new module) or all obj folders (to work around a Visual Studio bug).

Labels:


Thursday, 2 March 2006

 

Software: WinCVS Compare Versions in Graph

In WinCVS, I can select two versions of a file in the Graph view, then find their differences using the Diff menu item. Upon hindsight, it seems obvious but I hadn't thought I could select multiple versions in the Graph view. Should've read the manual!

Labels:


Thursday, 23 February 2006

 

Software: Excel Copy Chart as Picture

We were trying to copy some charts as pictures or images from one Excel workbook to another but Excel would not paste a chart as an image. One workaround was to paste the chart in a drawing tool, then copy and paste that image into the workbook. While this workaround was OK, it was rather cumbersome since there were many charts to copy. With a little bit of searching, I found that this was #9 in the Top 10 Excel Annoyances. To copy a chart as a picture, select the chart, hold down the Shift key, then select Copy Picture in the Edit menu (not available in the context menu).

Another Excel quirk I've just noticed but don't have time to chase down is why I get the Paste Special menu item after copying a chart while my colleague does not.

Labels: