Monday, September 21, 2009

Using Dropbox to Sync files online and across different computers

I recently lost a couple of hard drives in a storm and lost a lot of data. So, I went looking for an easy online backup solution. I looked at a few options and started using Dropbox recently.

From Dropbox's website:
  • You can sync up to 100GB of your files online and across different computers. 
  • Sync files of any size or type
  • Share large files and photos easily
  • Automatic online backup
  • Track and undo changes to files
They give you 2GB storage for free so why not give it a try?

Click the Dropbox link on the right hand side of this blog to go straight to their site.


Thursday, July 10, 2008

C# version of VB6/VBA's Val function

Here is some code to emulate VB6/VBA's Val function in C#. I found the original but it needed some changes to work correctly.

using System.Text.RegularExpressions;

using System;

namespace ValinCS


class Program


static void Main(string[] args)




Console.WriteLine(Val(" 345"));


Console.WriteLine(Val(" 1 2"));




private static int Val(string value)


string returnVal = string.Empty;

int tryInt = 0;

//^ specifies that the match has to start at the start of the string

//Trim() trims both ends of the string before matching

MatchCollection collection = Regex.Matches(value.Trim(), "^\\d+");

foreach (Match match in collection)


returnVal += match.ToString();


//attempt conversion to int

int.TryParse(returnVal,out tryInt);

return tryInt;




Wednesday, July 02, 2008

Cloning using Serialization

I found some great C# code the other day which allows deep copying of objects, rather than shallow copies which object.Clone() does. Saved heaps of time mucking around with the ICloneable interface, and basically rewriting heaps of code.

You need to decorate the class(es) that you want to clone with the [Serializable] attribute. If you are trying to clone a object of a type which has members of some other class, those classes need to be serializable too.

public static object Clone(object obj)
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, obj);
ms.Seek(0, SeekOrigin.Begin);
return bf.Deserialize(ms);

Labels: , ,