Edit (18/01/2013)
I have edited this post on the above date. However, the only change that I have made is that I am now hosting the source code (found at the end of this post) on GitHub. This means, that if I need to make a change to the code, I do not have to edit this post again – as it will pull the latest version of it from the relevant page on GitHub whenever it is accessed by a reader.
So, I was looking through some of my old hobby code today and happened on an old quote generator. It’s a neat little (the executable weighs in at 24Kb) C# program that provides the user with a random quote from some of my favourite TV shows.

A screen-grab of my Random Quote generator showing a picture of Professor Ueda Jiro and a quote from the TV show Firefly
The Algorithm
- Find a text file called “Quotes.txt”
- Load each line in the text file into an element in an array
- Display a standard Windows form with a picture and a text box.
- When the user pressed the “Generate Quote” button, ‘randomly’ pick one and display it in the text box.
The Code
For those wanting to compile this code, you’ll need to provide Visual Studio with a JPEG image. In the original solution, I called this image “Dontokoi!” (as this is the catchphrase of the character in the image). Without this image, I doubt that the program will execute correctly.
Post Mortem
Aside from the above comment about the image being required for compilation, I did notice another potential problem with the program.
For some reason, apostrophes (‘) aren’t rendered correctly when the accompanying text file is encoded in anything but UTF-8. Since I know very little about text file encoding and the default way that the .NET libraries import text into a string array and the way that .NET draws this text into a text box, I can only assume that the problem is related to the formatting of the text file (saved, using Notepad++).
Either that, or it’s related to one of the settings within the Visual Studio IDE itself. I do remember that, around this time, I was attempting to compile all of my code with direct support for Unicode, so maybe that’s it.
I’m not sure, to be honest. But I am planning on opening the solution file (at some point) and having a good look around. The reason I haven’t opened the solution file at the minute is because I don’t own a copy of Visual Studio; which makes opening a Visual Studio file quite difficult.
Here’s a link to a zip of the entire solution, in case you wanted to take a look (The executable is in Bin/Release along with an old Quotes text file) [LINK]
Until next time,
J