Cannot select text with mouse in Microsoft Word, fix. 11

Posted by ben on August 21, 2008

A friend had the following problem with their laptop the other day. When they open Microsoft Word they cannot select any text with the mouse, they couldn’t even place the cursor into the text by clicking the mouse on the text.

She said that the situation seemed to have occured when Norton Antivirus requested an update at the same time she was doing something in Word.

I suspected that it was that Word had somehow got corrupted, so I ran a repair, by inserting her Microsoft Office DVD and bring up the installer, and selecting Repair.

This made no difference, I then reinstalled Office, still the problem persisted. This made me think that the problem was related to the Registry, so I did a Google search.

Fixing Word text selection

I found these articles:

To summarise the fix:

  • Backup the Word\Data part of the Registry first
  • delete the the Word\Data section
  • restart Word
  • if it works then its completed, else restore the backup and keep Google searching.

Warning about Word registry changes

This fix involves removing the Word/Data registry key. By deleting this key you will loose some options you have set, this just means that you will need to reset them again. Additionally you will loose the list of files in your recently used files list at the bottom of the file menu.

Additionally be really careful about deleting anything out of the registry, because it can cause serious problems. All the main Windows programs use it, and you could end up reinstalling everything including your copy of Windows.

Backup the offending part of your computer’s registry:

  1. Exit all Office programs, Word, Excel, Outlook etc if they are running.
  2. Open regedit by: Clicking Start/Run, then type regedit, and select OK.
  3. Navigate the registry and select the appropriate Word registry subkey:

    • Word 2002:
      HKEY_CURRENT_USER\Software\Microsoft Office\10.0\Word\Data
    • Word 2003:
      HKEY_CURRENT_USER\Software\Microsoft Office\11.0\Word\Data
    • Word 2007:
      HKEY_CURRENT_USER\Software\Microsoft Office\12.0\Word\Data
  4. Select the Data node, then from the File menu choose Export.

  5. Name this backup file something like word_data.reg, and save it your desktop.

Delete the Word\Data registry node

  1. Select the appropriate Word\Data node mentioned in part 3.
  2. From the Edit menu select Delete, and then click Yes.
  3. Exit regedit.

Restart Word

  1. Restart Word. This will cause Word to recreate this registry node, but you may have to re-enter some of your Word options. If everything is working as expected you can finish. If you still have a problem follow the next section.

Restore the backed up registry node

If the problem still persists then restore your registry back, and keep looking for a solution. To restore the registry back to normal simply:

  • Double-click the word_data.reg file on your desktop.
  • and select Yes, and then OK.

An Almost Fix for Creating RubyGems on Windows

Posted by ben on June 25, 2008

Introduction

I wrote this article originally so that I could write command-line apps using Ruby, as I got further and further down the line I realised that what I really wanted to do was create a command-line app using RubyGems. I use both Windows and an Apple Mac and I quickly found myself having problems trying to create RubyGems on Windows.

In this article I try to explain my thought process and the problems I encountered. Unfortunately I had to employ a manual process when trying to package up my project into a tar file, as there isn’t a simple way to do this in Windows (let me know if you have a solution), however everything else seems to work.

What’s a RubyGem?

One of the joys of Ruby is the RubyGems packaging system. It is essentially a tool written in Ruby, for packaging up source code for deployment.

The RubyGems site describes it as follows:

RubyGems is the premier ruby packaging system. It provides:

  • A standard format for destributing Ruby programs and libraries.
  • An easy to use tool for managing the installation of gem packages.
  • A gem server utility for serving gems from any machine where RubyGems is installed.

Why should I create a RubyGem?

Maybe a better question should be when should I package my code up into a RubyGem. Obviously there are no hard and fast rules but if you are going to share your code libraries with others or even with other applications of yours, you should think about using a gem.

Now you might think that you don’t want to make all your code public on RubyForge, and there are very good reason not to publish every gem, so you don’t have to. RubyGems comes with its own local gem server so you can create your own gem library and share it amoung your other Ruby applications.

This is really quite useful, you get the power of RubyGems without the commitment and maintenance work of making your code OpenSource. Plus at any point in time you can then make it OpenSource, and live off the joy of the Ruby community :).

The reason I wrote this article is because I wanted to create a simple command-line application using Ruby. I went through a number of steps before realising that the best way was to use RubyGems.

I started by creating my own command-line structure and then found this great article by Todd Werth. He has a single Ruby file that you just replace various sections and viola you have a very simple command-line app. But it wasn’t quite what I wanted. I didn’t want to have to type:

./my_super_app 'some params'

I wanted to type:

my_super_app 'some params'

I also wanted the structure of the application to follow a standard structure and I didn’t want to put ‘.’ into my path, for security reasons. Dr Nic came to the rescue with a couple of excellent articles describing how to create gems using newgem and specifically command-line apps as gems.

Installing newgem on Windows

To install newgem on Windows use the RubyGems install method.

gem install newgem

This will install the gem and its dependencies. However one of its dependencies is the Hoe gem, and there is a slight issue using it on Windows.

What is hoe?

Hoe is a compliment to rake, it was created by Ryan Davis and provides rake tasks for testing, packaging, and releasing RubyGems. Geoffrey Grosenbach has a nice tutorial for using hoe and also describes how to create a project structure using the sow task.

Hoe uses a .hoerc file for configuration, and this file should reside in the user’s home directory, something like:

C:\Documents and Settings\MyUserName

An example .hoerc file should look like the one below. Please note that this is a YAML file and if you copy it from here remember to follow the indentation convention:

---
publish_on_announce: false
exclude: !ruby/regexp/tmp$|CVS|\.svn|_darcs|\.git|log$|local/.*\.rb$|Makefile|.*\.o$|.*\.bundle$|.*\.so$|.*\.dll$/ 
str: ""
"@taguri": tag:ruby.yaml.org,2002:regexp/tmp$|CVS|\.svn|_darcs|\.git|log$|local/.*\.rb$|Makefile|.*\.o$|.*\.bundle$|.*\.so$|.*\.dll$/
blogs:
- user: user
  url: url
  extra_headers:
    mt_convert_breaks: markdown
  blog_id: blog_id
  password: password

On Unix systems there is a shortcut to the user’s home directory which is ‘~’ and on Windows this isn’t a shortcut. Windows however does have an environment variable HOMEPATH which will point to the user’s home directory. The problem is that the Hoe gem code uses ‘~’ in its hoe.rb file and this causes problems for Windows users.

Patching the hoe.rb file

OK, be brave, lets tweak the hoe.rb file so that it will work on the Windows platform. The Hoe gem hoe.rb file can be found in the following directory (assuming you installed Ruby to the standard location):

C:\ruby\lib\ruby\gems\1.8\gems\hoe-1.6.0\lib

To make it work for Windows PCs you will need to modify this file with the following changes.

Locate the define_tasks method:

def define_tasks # :nodoc:
  def with_config # :nodoc:
    rc = File.expand_path("~/.hoerc")
    exists = File.exist? rc
    config = exists ? YAML.load_file(rc) : {}
    yield(config, rc)
  end

And add a new method above it such as this, and modify the line rc = File.expand_path(”~/.hoerc”) as below:

def get_home_dir
  home_file_path = "~/"
  home_file_path = "#{ENV['HOMEPATH']}\\” if WINDOZE
  home_file_path
end

def define_tasks # :nodoc:
 def with_config # :nodoc:
   rc = File.expand_path(get_home_dir + ‘.hoerc’)
   exists = File.exist? rc
   config = exists ? YAML.load_file(rc) : {}
   yield(config, rc)
 end

Finally you will need to locate and change the task :config_hoe so that it reads:

"signing_key_file" => "#{get_home_dir}.gem/gem-private_key.pem",
"signing_cert_file" => "#{get_home_dir}.gem/gem-public_cert.pem",

If all has gone correctly save this file and you are now ready to create a RubyGem.

Creating a basic RubyGem

Using the newgem RubyGem enter the following command at the command prompt:

newgem my_app -b greetings -T rspec -W

This will create a my_app subdirectory, with a command-line command app called greetings located in the bin directory. It will use the testing framework RSpec and finally will not generate the RubyForge web site code. This is assuming you don’t want to relese your code as OpenSource. The output will be something like this:

     create
     create  config
     create  doc
     create  lib
     create  script
     ... blah ...
     create  script/console
     create  script/console.cmd
     create  Manifest.txt
     readme  readme
Important
=========

* Open config/hoe.rb
* Update missing details (gem description, dependent gems, etc.)

If you want to add RSpec Stories to this project there is a useful command-line generator to do this. First navigate into the root of you new project app directory, in this case my_app. Now execute the generate script:

ruby script/generate install_rspec_stories

You should then get the following output:

  create  stories/steps
  create  stories/steps/my_app_steps.rb
  create  stories/sell_my_app.story
  create  stories/all.rb

Modify your greetings command so that it does something. Do this by editing the file located here:

my_app/bin/greetings

Open up this file and at the very end, add some code such as this, and save the file:

# do stuff
puts 'Greetings the world is my oyster!'

Packaging caveat

As mentioned in the begining of this article I couldn’t use rake to tar this project up for deployment to RubyForge. The reason is that rake makes a Unix platform dependent call to tar the package using a Ruby task file packagetask.rb located:

C:\ruby\lib\ruby\gems\1.8\gems\rake-0.8.1\lib\rake 

This means that on Windows you will have to manually tar this file.

However you can still create the gem using the rake task, and a gem file my_app-0.0.1.gem, will appear in the pkg directory:

rake gem

This new RubyGem can now be installed by using the gem install commands:

gem install pkg/my_app-0.0.1.gem

You should get the following output:

For more information on my_app, see http://my_app.rubyforge.org

NOTE: Change this information in PostInstall.txt
You can also delete it if you don't want it.


Successfully installed my_app, version 0.0.1
Installing ri documentation for my_app-0.0.1...
Installing RDoc documentation for my_app-0.0.1...

Finally you should now be able to execute your command-line command in the command prompt, simply by typing:

greetings

I hope this is useful and helps with your understanding of how RubyGems work, specifically on Windows, also please jot down some comments if you have any ideas or suggestions.

Links

Here is a list of useful RubyGems links:

How to determine whether a column exists on SQLServer

Posted by ben on June 10, 2008

I run some SQL scripts against Microsoft’s SQLServer in a number of environments, test, staging and production.

One of my problems is that these scripts alter the database schema and I only want them to execute if the change hasn’t already been made.

One of these changes was to remove a column from the database, so my question is ‘how can I ask SQLServer whether a particular column exists’.

Well the SQL query to check if a column exists and execute a query if it does is as follows:

IF EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS
                 WHERE TABLE_NAME='my_table_name' AND
                 COLUMN_NAME='my_column_name' )
BEGIN
  PRINT 'Execute some query here'
END

Hope it is useful. Ben…

Installing Sqlite3 on Windows for Rails 3

Posted by ben on June 04, 2008

The Windows version of Ruby on Rails does not ship with the Sqlite3 database, even though the database.yaml configuration file is preconfigured to use Sqlite.

This is a how to guide on how to install Sqlite3 on your Windows PC. This article assumes that you already have Ruby and Ruby on Rails installed on your PC.

First you will need to download two files from the Sqlite web site http://www.sqlite.org/download.html:

    sqlite-3_5_9.zip (214.32 KiB)
    A command-line program for accessing and modifing SQLite databases. 
    See the documentation for additional information.

    sqlitedll-3_5_9.zip (213.17 KiB)
    This is a DLL of the SQLite library without the TCL bindings. 
    The only external dependency is MSVCRT.DLL.

The first file is the Sqlite command line program used for modifing the Sqlite database. You may or may not use this.

The second file is the Windows DLL library file and Ruby uses this when Rails makes Sqlite database calls.

When both these ZIP files have been extracted you should have the following files:

  • sqlite3.exe
  • sqlite3.def
  • sqlite3.dll

Copy these file to the bin directory of your Ruby installation, if you followed the default Ruby installation it will be located here:

    C:\ruby\bin

Now that you have the Sqlite3 files installed you need to tell Ruby how to use them. To do this you need to download the Ruby bindings for Sqlite3.
Fortunately this is easy to do, using Ruby gems. Simply at the command prompt type the following command:

    gem install sqlite3-ruby

You will now need to tell Gems which version you need as you will be presented with the following output:

    Bulk updating Gem source index for: http://gems.rubyforge.org
    Select which gem to install for your platform (i386-mswin32)
     1. sqlite3-ruby 1.2.2 (mswin32)
     2. sqlite3-ruby 1.2.2 (ruby)
     3. sqlite3-ruby 1.2.1 (mswin32)
     4. sqlite3-ruby 1.2.1 (ruby)
     5. Skip this gem
     6. Cancel installation
    >_

Please select option 1, sqlite3-ruby 1.2.2 (mswin32). All being successful you will get some output like this:

    Successfully installed sqlite3-ruby-1.2.2-mswin32
    Installing ri documentation for sqlite3-ruby-1.2.2-mswin32...
    Installing RDoc documentation for sqlite3-ruby-1.2.2-mswin32...

If you are using Rails 2+ you should be able to run the following rake tasks from your Rails application directory. For example say you created a Rails application located here: C:\MyApp you should be able to execute:

    C:\MyApp>rake db:create
    or
    C:\MyApp>rake db:migrate

Hope this is useful.

Named Pipes and TCP/IP Connection Strings

Posted by ben on May 28, 2008

Manually Creating a SQL Connection String

There are many different connection strings for connecting to a SQLServer database for C#. Have a look at this web site http://www.connectionstrings.com/?carrier=sqlserver for examples.

I needed to create a connection to a SQLServer and started using this as my connection string:

server=myServer;database=myDatabase;uid=someUser;pwd=somePassword

However I got the following error:

An error has occurred while establishing a connection to the server. 
When connecting to SQL Server 2005, this failure may be caused by
the fact that under the default settings SQL Server does not allow 
remote connections. (provider: Named Pipes Provider, error: 40 - 
Could not open a connection to SQL Server)

Pipes are actually quite an old technology, but what are they?

Continue reading…

IManage error - The semaphore is set and cannot be closed 1

Posted by ben on May 28, 2008

Using the Interwoven IManage API, I was trying to create a connection to the IManage server and kept getting this error message:

The semaphore is set and cannot be closed.

It turns out that this error message is misleading and can hide a multitude of symptoms. In this case it was returned because the system cannot create a connection to the server, as I had accidentally put in an incorrect server name into my connection method.

I did however do some research into what a semaphore actually is. The choice of word comes from a time when flags were used to signal telegraph messages.

However the Dictionary computer definition of a semaphore is:

semaphores are a software mechanism to regulate process synchronization, proposed by Edsger W. Dijkstra.

Wikipedia gives a more detailed explaination of a semaphore, see below:

A semaphore, in computer science, is a protected variable (an entity storing a value) or abstract data type (an entity grouping several variables that may or may not be numerical) which constitutes the classic method for restricting access to shared resources, such as shared memory, in a multiprogramming environment (a system where several programs may be executing, or taking turns to execute, at once). Semaphores exist in many variants, though usually the term refers to a counting semaphore, since a binary semaphore is better known as a mutex. A counting semaphore is a counter for a set of available resources, rather than a locked/unlocked flag of a single resource. It was invented by Edsger Dijkstra. Semaphores are the classic solution to preventing race conditions in the dining philosophers problem, although they do not prevent resource deadlocks.

.Net not recognising regional settings 3

Posted by ben on May 23, 2008

The other day I had the following problem. One of my test servers had been setup with US regional settings and should have been setup with UK settings.

The problem had been unnoticed for a while until our C# .Net application tried to call a stored procedure on a database on another server. This database server had UK regional settings. The stored procedure expected to get a date in UK ‘Long format’. The error message was a database error saying something like:

convertion error can't convert from NVarChar to DateTime

As the application was already compiled and being used on a live server I could not modify the code, I therefore had to run SQL Profiler and see what values were being passed into the stored procedure. This is where I saw the US ‘Long Date’ format being passed in.

Continue reading…