Free Information Technology Magazines and eBooks

Saturday, April 18, 2009

.NET Debugging Tip: System.Diagnostics.DebuggerStepThrough()

One of the useful diagnostics tool that I often use on shared method or libraries that I don't want the debugger step into is the System.Diagnostics.DebuggerStepThrough(). The attribute tells Visual Studio IDE to skip the method while debugging through code. Below is a sample code the uses the attribute

In C#
[System.Diagnostics.DebuggerStepThrough()]private void InitializeComponent()
{
//Anything
}


In VB.NET


<System.diagnostics.debuggerstepthrough()>
Private Sub InitializeComponent()
'Anything
End Sub


The advantage of it is that you can save lot of time if you want to step
into your code at run time, but don't want to step into some
procedures unless they raise an exception.

DoInk.com, a place to enjoy art and animation

online software to draw and animateAn online software that let you draw and animate like Adobe fireworks and runs on a browser. You can put together a pretty animation in just a few minutes. You can also collaborate with other talented users and share your talent with the world wide web. If your just plain and cant draw, you can re-use the work of thousands of other users. The online service is called DoInk.

DoInk also allows user to embed shared work on their own website. Here a sample works that I grabbed from DoInk.



I Like Horse!


Another Animation


You can also publish your work straight to YouTube. Now be the artist you wanted and show it to the world. Good Luck!

Friday, April 17, 2009

Survey says 7 out of 10 IT Professional inappropriate materials on employee’s laptops

Laptop corporate users surveyThis morning, I stumbled with this interesting article from ComputerWorld. The article says that according to a recent survey by Ponemon Institute, Two-thirds (2/3) of the 3,100 IT pros respondents had found "evidence of inappropriate interactions with other employees" of an adult nature on company-issued laptops. A slightly smaller percentage, 63%, found resumes and other evidence of job searches. Larry Ponemon, chairman of the research group behind the study, said the findings pointed to risky behavior by employees that heightened the potential for data security breaches.

Despite the anonymous nature of the Web survey, Ponemon said the results probably understated the true scope of the problems, as respondents with serious breaches or losses were probably too embarrassed to respond.

The survey was sponsored by Dell Inc.

To read the complete article visit ComputerWorld website

How to Insert Adsense Between Posts on Blogger

If you are a regular blogger, you might already be using Adsense to monetize your blog site. One of the tested adsense ad location is the inline ads. To implement it on you blogger site you just need to perform some easy steps. There is no need for HTML coding.

Steps to Post Inline Adsense your Blogger

1. Sign into your Blogger account.
2. Click on the "Layout" tab.
3. On the section of "Blog Posts" click the Edit link

Edit Blog Posts to activate Inline Adsense

4. On Configure Blog Posts Page, Check the "Show Ads Between Posts"

Check the Show Ads Between Posts

5. Then configure the Adsense format you want to display.

configure adsense format between posts

6. If you are already satisfied on your adsense look, click "Save" button to finish.

Remember the Google Terms and Conditions when displaying Ads. You can only show maximum of three(3) normal ad units, maximum (3) of link units and a maximum of two Google AdSense for search boxes.

How to embed Picasa Album Slideshow on Blogger

Although the available slideshow widget is good, it is too small for me and there is no option to resize the preview. Since I am using PicasaWeb as my primary photo bank, I can use its embed slideshow option.

Here's How to Embed the Picasa SlideShow:

1. Login to your PicasaWeb
2. On the My Photos page, click the album you want to display.
2. Click Link to this album on the right pane.
3. Click Embed Slideshow.
4. Configure the slideshow options according to your preference.

Embed Picasa Slideshow

5. Copy the script generated.
6. Login to you blogger account.
7. Go to Layout and click "Add gadget"
8. Select "HTML/JavaScript" gadget.
9. On content field, Paste the embed script that we Copy earlier.

Copy embed code to Blogger HTML gadget

10. Enter any title you want on the Title field then click Save.

To see a working example of Picasa Slideshow, Visit my Travel Site. It is located on the right side bar.

How to Show your recent post on Blogger

If you haven't noticed I'm using Blogger service on this site and same as other Google services Blogger rocks. So today I feel its time to show some appreciation by sharing blogger tips and tricks to other users. The first How-To topic from How-To series that I will share is "How to Show your recent post"

Its easy just follow these steps:

Trick to Show Recent Post on the Blogger Sidebar

1. Login to your Blogger account then go to "Layout" tab
2. Click on "Add a Gadget" then look for gadget "Feed" and press "+" icon as shown below

Add Feed Gadget

3. On the feed URL, enter your Address Feed "http://your-blog.blogspot.com/feeds/posts/default"

Enter Feed URL

4. You can change the Title and tick some options as shown below

Feed Gadget Options

5. Click Save.
6. The Save again on your layout page.

You can see an example of "recent post" on my travel site. It is located on right side bar.

I hope this tip could help anyone. Happy Blogging!

Thursday, April 16, 2009

How to Catch Divide By Zero Exception in .NET

Today's tutorial for beginners is about the most common runtime error on programs involving mathematical formulas, the Divide By Zero Exception.This DivideByZeroException runtime error can close your software unexpectedly, leaving your end-users hanging on unsaved works. In .NET, we can prevent error like DivideByZeroException by trapping it with try catch control structure. Take a look at the example codes below:

C#

private void button1_Click(object sender, EventArgs e)
{
int Val1 = 0;
int Val2 = 57;
int Result = 0;

try
{
// No error
Result = DivideNum(Val1 , Val2);
MessageBox.Show(Result.ToString());

//With error, this should throw the dividebyzeroexception
Result = DivideNum(Val2, Val1);
MessageBox.Show(Result.ToString());

}
catch (DivideByZeroException ex)
{
MessageBox.Show(ex.Message);
}
}

static public int DivideNum(int num, int denom)
{
return (num / denom);
}



In VB.NET, its a little bit tricky. If we convert the C# code to VB.NET our code should look like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Val1 As Integer = 0
Dim Val2 As Integer = 57
Dim Result As Integer = 0

Try
'No error
Result = DivideNum(Val1, Val2)
MessageBox.Show(Result.ToString())

'With error, this should throw the dividebyzeroexception
Result = DivideNum(Val2, Val1)
MessageBox.Show(Result.ToString())

Catch ex As DivideByZeroException
MessageBox.Show(ex.Message)
End Try

End Sub
Public Function DivideNum(ByVal num As Integer, ByVal denom As Integer) As Integer
Return (num / denom)
End Function


But the problem is the System.DivideByZeroException does not catch the exception and display a different error as shown below.

System.OverflowException

If we use the System.OverflowException it will work. The reason behind this is that the "/" operator performs floating point division, which doesn't throw a DivideByZeroException but instead it returns NaN or Infinity. If you add Option Strict On on your program, the IDE will underline the error like the one below:

DivideByZeroExeception runtime error


To solve it we should replace "/" with "\". The working code for VB.NET will be:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Click
Dim Val1 As Integer = 0
Dim Val2 As Integer = 57
Dim Result As Integer = 0

Try
'No error
Result = DivideNum(Val1, Val2)
MessageBox.Show(Result.ToString())

'With error, this should throw the dividebyzeroexception
Result = DivideNum(Val2, Val1)
MessageBox.Show(Result.ToString())

Catch ex As DivideByZeroException
MessageBox.Show(ex.Message)
End Try

End Sub
Public Function DivideNum(ByVal num As Integer, ByVal denom As Integer) As Integer
Return (num \ denom)
End Function


Now using this "try catch" statement will make your programs DivideByZeroException runtime error free. Good Luck!

Search engine with a twist

This morning I stumbled upon an interesting search engine that let users search using only the keyboard. Although keyboardr.com was launched sometime November last year, I think its worth sharing to you readers. According to Julius Eckert (the mind behind the search engine), Keyboardr is a meta-search. Users will get Google, Wikipedia, Youtube altogether. The instant search and the keyboard navigation are replacing the feeling of “searching” with the feeling of “launching”. For a search geek like me, it can speed up searching. It is as simple as going to the site and start typing... yes no mouse needed. It is like an auto search facility where user just type anything on the textbox and records that matches the string will be automatically displayed.

I tried searching for the words "Fryan Digital World" and it dynamically shows related results as shown below.

keyboardr search engine test

You can navigate from the search results just by using your keyboard's arrow keys and pressing "enter" key will open the selected result on a new window (popup blocker must be disabled). On his blog, Eckert mentioned several enhancements that he envision to incorporate to Keyboardr. Overall the site was pretty good, it spices up my today's search experience.

Wednesday, April 15, 2009

Firefox Future has No Tabs

Can you imagine your firefox with no Tabs? Apparently it is a possibility according to Mozilla. According to Oliver Reichenstein, head of user experience at Mozilla


Tabs worked well on slow machines on a thin Internet, where ten browser sessions were “many browser sessions”. Today, twenty+ parallel sessions is quite common; the browser is more of an operating system than a data display application; we use it to manage the web as a shared hard drive. If you have more than seven or eight tabs open they become pretty much useless. Also, God said that tabs don’t work if you use them with heterogeneous information. They’re a good solution to keep the screen tidy for the moment. And that’s just what they should continue doing. For the overall organization of your browsing, a cloud file system works much better.


He's vision of a new interface is looks more like iTunes with folders, libraries, and bookmarks in a sidebar. So Mozilla is thinking of redesigning our beloved firefox from moving tabs on the side or removing the tabs completely.

Future Firefox, Tabs on the side

Future Firefox, No Tabs


I think these proposals are good ideas and can provide a different user experience. Although the second screenshot above looks like Google Chrome, Reichenstein argues:



To be clear: It’s not what Safari or Chrome do. The idea is not to show screen shots but to turn the browser into a media system organizer more than a media display application. Instead of structuring a browser to keep the screen tidy for the moment, we thought that it’d be awesome to structure the browser as a (multi media) file system. Like iTunes. With predefined folders. Like OSX. So whenever you open a new tab you see what you last saw in your iTunes, uhm, Firefox library.


As one of a millions of firefox users, I will surely be waiting for these features to be reality.

Early look to Google Android 1.5 SDK is now available for download


Early-look at Android 1.5 SDKStarting April 13, developers can now get an early look to the next version of Google's mobile operating system. The new SDK has several new programming features such as soft keyboards, home screen widgets, live folders, and speech recognition. Google also modified the developers tools structure so that it can support multiple versions of android platform.

The Android 1.5 SDK is based on new Linux kernel, version 2.6.27. While it is still on polishing stage and can still have changes, perhaps its biggest improvement is the on-screen soft keyboard that will work for both portrait and landscape orientations.

Android creators now encouraging developers to start working with this early-look SDK. Although 1.5 has not been finalized, most of its API are already settled but changes are likely before the final release. Developers can download the early-look version of Android 1.5 SDK at android website

Tuesday, April 14, 2009

VB.NET Trick: Clear all textboxes on a form

One of the most common function we need in a VB form is clearing textbox controls. We usually see it on add or cancel button of a maintenance form. Beginners often code it this way:


txtCategoryID.Text = ""
txtCategoryName.Text = ""


This style of coding is good only for less than five (5) textboxes. More than that will make the code longer and less organize. One technique we can apply is to use the Controls collection, so the previous will now look like this:


Private Sub ClearTextboxes()
For Each txt As Control In Me.Controls
If TypeOf txt Is TextBox Then
txt.Text = ""
End If
Next
End Sub


You can also use the same technique on other type of controls and other properties of a control. Below is a sample code to disable or enable all textboxes on a form.


Private Sub EnableTextboxes(ByVal IsEnable As Boolean)
For Each txt As Control In Me.Controls
If TypeOf txt Is TextBox Then
txt.Enabled = IsEnable
End If
Next
End Sub




Sunday, April 12, 2009

SQL Server Error 2147749896

This morning while I was trying to install SQL SERVER 2005 express on my laptop with Microsoft Vista SP1, I encountered the following error:

The SQL Server System Configuration Checker cannot be executed due to WMI
configuration on the machine Error: 2147749896 (0x80041008)



After several minutes of searching for answers online, I found a batch file that worked on my machine. The batch file contains the following scripts:


@echo on
cd /d c:\temp
if not exist %windir%\system32\wbem goto TryInstall
cd /d %windir%\system32\wbem
net stop winmgmt
winmgmt /kill
if exist Rep_bak rd Rep_bak /s /q
rename Repository Rep_bak
for %%i in (*.dll) do RegSvr32 -s %%i
for %%i in (*.exe) do call :FixSrv %%i
for %%i in (*.mof,*.mfl) do Mofcomp %%i
net start winmgmt
goto End

:FixSrv
if /I (%1) == (wbemcntl.exe) goto SkipSrv
if /I (%1) == (wbemtest.exe) goto SkipSrv
if /I (%1) == (mofcomp.exe) goto SkipSrv
%1 /RegServer

:SkipSrv
goto End

:TryInstall
if not exist wmicore.exe goto End
wmicore /s
net start winmgmt
:End


Save the script above as .bat file then run it on the command line. Then after several minutes and you can see the :End statement, try to reinstall the SQL server again and it should already be fixed.

After further reading on some forums, some users claims that the script does not work for them and tried the following steps instead.


- Kill the service winmgmt
- Copy the whole %windir%\system32\wbem folder from another machine where the installation of SQL server is good. (it suppose to fix the config files).


If you have other solutions that works, please share it to us. Good day to all!