Sunday, April 27, 2008

Use DateSerial Function To Avoid Regional Settings Problem In VB.NET

This is based on my experience. I used to construct a date type with from string. The sample code is as follow:


Dim dt As Date = CDate("2/3/2008")
MessageBox.Show(dt.ToLongDateString)

Hell yeah! I realized now that this is not a good way. When you execute the code above by using Regional Options set to English US - which Short date format in this setting is "mm/dd/yyyy" - you'll get a message box with message "Sunday, February 03, 2008". Comparing the result with Regional Options set to English (Australia) - which the format is "dd/mm/yyyy" - we'll get a message box with message "Sunday, 2 March 2008". Whew! So which date do the code means?

Oh, I means February 03, 2008! It's just a date, we can fix it just by changing it, it's not a big deal! Hell yeah! You can just simply change it when we are talking about one or two variable, and a simple program like those "Hello World Style" like above. When we're talking about an enterprise application like e-banking which all reports are based on transaction date, believe me that this style of code will bring you to hell.

The simple way to avoid this Regional Options problem, is just get yourself used to construct the datetime variable value by define its day, month, and year value specifically. In .NET you can use DateSerial function.

According to msdn this function returns a Date value representing a specified year, month, and day, with the time information set to midnight (00:00:00). The format of this function is as follow:


Public Function DateSerial( _
ByVal [Year] As Integer, _
ByVal [Month] As Integer, _
ByVal [Day] As Integer _
) As DateTime

So, when you means February 03, 2008, the code above will be as follow:


Dim dt As Date = DateSerial(2008, 2, 3)
MessageBox.Show(dt.ToLongDateString)

The code above will give you February 03, 2008 in any Regional Options you use!

This is a very simple thing to do, but not all realized it's effectiveness (including me, was). But, just by using this kind of simple code behavior will avoid you from a lot of problem caused by Regional Options different from miscalculating reports to unpredictable error in your application.

Tuesday, April 15, 2008

MozillaCacheView to Sneak Into Your Mozilla Cache Folder

If you are a Mozilla Firefox user, have you ever check the cache directory. Aha... you might asking, why should you check this directory. Well sometimes you might want to get some files (for example a picture) from a website you've visited but you forget the address. You can check the cache folder, because usually the files you've browsed will stay in this folder for a while (as long as you don't delete them).

But, when you look at the folder you might surprised (or maybe get confused), because this folder only contain files, without extension on it. And the file name didn't look like a filename. See the screen shot below.

Well, MozillaCacheView might help you to sneak at this folder. By using this tool you can read files located at this cache folder. It''s really simple. Just open the tool, and it'll work for you. Very exciting. You can also, copy file(s) you want into certain location.

This is the screen shot of this tool.

This tool works for Firefox/Mozilla/Netscape Web browsers. And also the great news is this tools is freeware, so you can download it free. I''m sorry I don't remember the location (and also because this is not an ads), but I believe Uncle Google will tell you better than me! :D

Btw, this is the location of cache folder for several browser.


The cache folder of Mozilla Firefox is located under C:\Documents and Settings\[User Name]\Local Settings\Application Data\Mozilla\Firefox\Profiles\[Profile Name]\Cache

The cache folder of SeaMonkey is located under C:\Documents and Settings\[User Name]\Local Settings\Application Data\Mozilla\Profiles\[Profile Name]\Cache

For other variants of Mozilla, you may find the cache folder under C:\Documents and Settings\[User Name]\Application Data\Mozilla\Profiles\[Profile Name]\Cache

Saturday, April 12, 2008

Spock Beta, The People Search Engine

Nowday, internet growing so fast. People from around the world are now connected in this virtual world. People can share and gather information each other in internet through a huge number of service. From social networking, blogs, and many others services.

Regarding to this situation, there is a need to find people in internet. For this purpose, we need a good people search engine which can give us a valid information about person we would like to search.

Spock is a new unique search engine where you can search people by adding their name, email, or even a tag which related to the people you search. When you use this people search engine, Spock will personalize your results to include information about friends and colleagues. You can also add and modify information that Spock finds about you on the internet.

As I visited this people search engine, it is still in beta version. The layout of the index page is very simple. It only contain a text box which allow you include your search term in it. Spock also give you ability to advance your search. In advance mode you can specify your search by adding Name or Email, Gender, Age, Tags, and even Location. Very Interesting!

So why not visiting this exciting people search engine and try it?

Thursday, April 10, 2008

String Manipulation In .NET

I've just realized a fact about string manipulation in .NET framework after read "MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0 Application Development Foundation" by Tony Northrup, Shawn Wildermuth and Bill Ryan.

For you who are an expert in .NET, this might look a common stuff. But, this is new to me. Well, I believe programming is not just about logic and algorithm, but also about knowing the boundaries. So you need to wide your boundaries if you want to solve various problem.

Back to the topic, the book said that
Strings of type System.String are immutable in .NET. That means any change to a string causes the runtime to create a new string and abandon the old one.
So when you want to construct a string as follows (this source is taken from the book too):


string s;

s = "wombat"; // "wombat"
s += " kangaroo"; // "wombat kangaroo"
s += " wallaby"; // "wombat kangaroo wallaby"
s += " koala"; // "wombat kangaroo wallaby koala"

Console.WriteLine(s);


In the end you'll get "wombat kangaroo wallaby koala" printed in the console, but in fact the compiler will create the "temporary strings" in memory before give the result string to you.

For a application which only a little string manipulation processes this will not give much trouble. But for application which use a bunch of string manipulations in it, this should be a concern because it can affect perfomance.

For the solution, the book suggested us to use StringBuilder. So, the code above will be as follow:


System.Text.StringBuilder sb = new System.Text.StringBuilder(30);

sb.Append("wombat"); // Build string.
sb.Append(" kangaroo");
sb.Append(" wallaby");
sb.Append(" koala");

string s = sb.ToString(); // Copy result to string.
Console.WriteLine(s);

Hmm...

Monday, April 7, 2008

Wordpress.com Engine Updated

Today, I opened my blog at wordpress.com. The blog is my personal blog at wordpress, but I moved it to my personal domain blog. When I logged in, I was very excited with the new look of its dashboard. Very cool design.


According into various news I found on the internet, the version of this engine is 2.5. For now, I have no comments for any functionalities its has, because I just want to check if my blog in Wordpress still have visitors (and fortunately it still have visitors, and there was a comment left to be moderated). Huhuhuhu...

Hmm... now I'm planning to upgrade my WP engine at my primary blog. :D I hope I can review them when I got it updated. Hopefully... :D

Thursday, April 3, 2008

What is This Code Means?

I was trying to update my blogger template and get this kind of error code bX-xxxxxx. the small x is a random alphabets. As I looked for the answer through Google Search there are no specific answer for this code.

Any answer I search only referred me to Google groups discussion which has no answer at all. The discussion only show questions from people who get same problem. And there were no answer at all. I very disappointed.

Hah... Google is a great search engine for me, the greatest thought! But why did it failed to give me the correct answer of what exactly was happening. No Idea...

Wednesday, April 2, 2008

Bookmark this blog at Mister Wong

I've just add this blog to mister-wong.com. It's a social bookmarking website. Some people said that we can increase traffic to our blog by adding our blog/website in a social bookmarking website or blog directory.

I've registered my primary blog into some blog directories. As my experience, this gave the blog a some traffic. Although it wasn't that significant but for me it was enough.

To get your blog registered in blog directory, sometimes they will ask you to give dem a reciprocal link, and usually it's can be done by adding some code which will show small banner in your web. So, if your blog is registered in a lot of this kind of blog directory, your blog will be fulled by these small banners. But, you can hide them in your footer for example. :D

Back to mister-wong. This is a nice social bookmarking site. And because this is a social bookmarking so we don't need to add a reciprocal link in our blog. Just registered yourself and bookmark your blog, and it's all done.

The site have a good layout. I love it. And the cool think is you can share your bookmarks with others in a group. You can join any group you want. Very excited.

Well, I think I'll try another social bookmarking for now. See yaaaa...