Friday, October 22, 2010

Piano + Guitar = Harpejji

Are you interested in musical instruments? If so have you seen an instrument which combines the Piano and the Guitar? It is manufactured by a company named Marcodi and is named as Harpejji. The sounds from it is truly fascinating, experience the sounds for you self by visiting their site. For people who would like to buy it the pricing and ordering details are also there in the site.

Click this link to see the event of presenting Harpejji first time to the great musician A. R. Rahman.

Saturday, October 02, 2010

MaxLength property not Working in TextBox

If you are involved in coding using .Net sooner or later you will notice that when the TextMode of a TextBox is changed to MultiLine the MaxLength property will stop working. What this means is in the textbox users will be able to type as many character as they want.

When searching the web for a fix for this I found several ideas to solve this. Following is the code which I modified for my requirement. Hope this helps.

ASPX





  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head runat="server">
  3. <script type="text/javascript">
  4.     function RestrictLength(textBox) {
  5.         /* Get the Max Length attribute's value. */
  6.         var allowedLength = textBox.getAttribute('MaximumLength');
  7.         /* Check for the number of characters typed in by the user. */
  8.         if (textBox.value.length > allowedLength) {
  9.             /* If it is more than the allowed limit remove the additional text. */
  10.             textBox.value = textBox.value.substring(0, allowedLength);
  11.             /*  Show a message to user with the tooltip used for the textbox. */
  12.             alert("Maximum characters allowed for '" + textBox.title +"' is " + allowedLength + ".");
  13.         }
  14.     }
  15. </script>
  16.     <title></title>
  17. </head>
  18. <body>
  19.     <form id="form1" runat="server" style="vertical-align:top;">
  20.     <!-- I am binding my java script to the onkeyup event of the textbox. So each time a key
  21.     is pressed it will fire my javascript. -->
  22.     Address <asp:TextBox ID="TextBox1" runat="server" MaxLength="10"
  23.         onkeyup="RestrictLength(this);" Height="58px" TextMode="MultiLine"></asp:TextBox>
  24.     </form>
  25.     </body>
  26. </html>




 

ASPX.CS





  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.     // Adding the attribute to the TextBox1.
  4.     // Note that this is different to the MaxLength property.
  5.     // Also this is not case sensitive.
  6.     TextBox1.Attributes.Add("maximumlength", "10");
  7.     // Adding a tooltip which is used in the message.
  8.     TextBox1.ToolTip = "User Address";
  9. }




The output will me something similar to the following.

Saturday, September 18, 2010

Repairing a Corrupted Database

When we are regularly using databases, sometimes those will get corrupted. This happened to one of my applications, it was a Windows Mobile application with SQL Server CE database. Since it is running in a mobile it is bit difficult for us to fix the database using the desktop machine. I used the following .Net Compact framework code to fix the corrupted database while the database is in the mobile.





  1. private void btnRepair_Click(object sender, EventArgs e)
  2. {
  3.     Cursor.Current = Cursors.WaitCursor;
  4.     Cursor.Show();
  5.     // txtDBPath will contain the path to the database.
  6.     engine = new SqlCeEngine(@"Data Source=" + txtDBPath.Text + ";Password=DBPassword");
  7.     try
  8.     {
  9.         if (!engine.Verify())
  10.         {
  11.             Cursor.Current = Cursors.Default;
  12.             Cursor.Hide();
  13.             DialogResult result = MessageBox.Show("Database is corrupted. Do you want to repair?", "My App", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
  14.             if (result == DialogResult.Yes)
  15.             {
  16.                 Cursor.Current = Cursors.WaitCursor;
  17.                 Cursor.Show();
  18.                 // You can also use RepairOption.DeleteCorruptedRows.
  19.                 engine.Repair(null, RepairOption.RecoverCorruptedRows);
  20.                 Cursor.Current = Cursors.Default;
  21.                 Cursor.Hide();
  22.                 MessageBox.Show("Database repaired successfully.", "My App");
  23.             }
  24.         }
  25.         else
  26.         {
  27.             Cursor.Current = Cursors.Default;
  28.             Cursor.Hide();
  29.             MessageBox.Show("Database is not corrupted.", "My App");
  30.         }
  31.     }
  32.     catch (Exception ex)
  33.     {
  34.         Cursor.Current = Cursors.Default;
  35.         Cursor.Hide();
  36.         MessageBox.Show(ex.Message, "Error!");
  37.     }
  38. }




Next time you get a corrupted SQL CE database try it out.

Friday, August 13, 2010

Cannot connect to YouTube using iPhone

Do you guys also get the ”Cannot connect to YouTube” error on your iPhone when using the provided YouTube application?

If yes follow the steps below to get it fixed.

1. Open Cydia from your spring board.

2. Press on the Manage tab in the bottom.

3. Press on Sources, then on Edit and press again on Add to add a new source.

4. Type the URL http://apt.iphonemodding.com and press on Add Source button.

5. Now find the iPhoneModding item and press on the triangle ‘>’.

6. Scroll down and find the “Push Fix” item and press on it.

7. Press Install to get Push Fix installed on your iPhone.

8. After pressing confirm on the confirmation screen the application will get installed on your iPhone.

 

9. After a complete restart you will be able to use YouTube application within your iPhone.

Monday, August 09, 2010

Comparing SharePoint 2010 vs 2007

It is some time since the SharePoint 2010 is released and now is a good time for you to migrate to the new improved version of it. When searching the net I found some good sites which compares the 2 versions.

Read through the following sites if you are interested.

http://www.rharbridge.com/?page_id=103

http://www.khamis.net/blog/Lists/Posts/Post.aspx?ID=4

Sunday, August 08, 2010

Installing and Uninstalling Internet Explorer 8

Since Internet Explorer (IE) 8 is a built-in feature of Windows Server 2008 R2 there is no way to install or uninstall it using the user interfaces. Instead you need to run the following commands in a command prompt window which has administrative privileges.

If you are only having IE in your machine as an internet browser be sure to install another internet browser before uninstalling IE, otherwise you will not be able to browse internet.

  1. Click the start button and type Cmd in the search box.
  2. Right click on the Cmd icon and click on Run as Administrator.
  3. Choose the appropriate command from below for your need and copy it.

To Install -

dism /online /Enable-Feature /FeatureName:Internet-Explorer-Optional-amd64

To Uninstall -

dism /online /Disable-Feature /FeatureName:Internet-Explorer-Optional-amd64

or

FORFILES /P %WINDIR%\servicing\Packages /M Microsoft-Windows-InternetExplorer-8*.mum /c "cmd /c echo Uninstalling package @fname && start /w pkgmgr /up:@fname /norestart"

  1. Paste the command into the command prompt windows you just opened by right clicking and clicking on Paste.
  2. Press enter to run the command, when the command is successful you need to restart your machine to complete the action.

Tuesday, August 03, 2010

Rounding a value Down

If you did work with .Net Math classes you may have noted that you can quite easily round value upwards. But what about rounding values down?

For example if you tried to round the value 1.23501 into 2 decimal places using the Round method provided by the Math class as below, the result you will get is 1.24. Meaning .Net had rounded the value up.





  1. double dbl = Math.Round(1.23501, 2);




If the value is rounded down it should be 1.23, but in .Net I couldn’t find an easy way to get this done. So I did create a small code to get it done. It is very simple only a method with one statement as shown below.





  1. double RoundDown(double Number, int Digits)
  2. {
  3.     try
  4.     {
  5.         return Math.Truncate(Number) +
  6.             (Math.Floor(Math.Round((Number % 1), Digits) * Math.Pow(10, (Math.Round((Number % 1), Digits).ToString().Length - 3)))) *
  7.             (1 / Math.Pow(10, Math.Round((Number % 1), Digits).ToString().Length - 3));
  8.     }
  9.     catch (Exception)
  10.     {
  11.         MessageBox.Show("Error ! Please check values.");
  12.         return 0.0;
  13.     }
  14. }




Ohh, I think this is complicated right? Please find a bit of self explanatory code below.





  1. double RoundDownExplained(double Number, int Digits)
  2. {
  3.     try
  4.     {
  5.         // Get the whole number from the double value.
  6.         // For example we'll take Number = 788.34567 and Digits = 3.
  7.         // WholeNumberPart = 788.
  8.         double WholeNumberPart = Math.Truncate(Number);
  9.         // Getting the decimal part from the doouble value.
  10.         // DecimalNumberPart = 0.3457.
  11.         double DecimalNumberPart = Math.Round((Number % 1), Digits);
  12.         // Finding the number of decimal places so we can multiply by 10 to make it suitable for Floor().
  13.         // MultiplicationValue = 3.
  14.         int MultiplicationValue = Math.Round((Number % 1), Digits).ToString().Length - 3;
  15.         // Create the double value to round down.
  16.         // RoundedDownValue = 345.
  17.         double RoundedDownValue = Math.Floor(DecimalNumberPart * Math.Pow(10, MultiplicationValue));
  18.         // Finding the value to devide the result to make it decimal again.      
  19.         // DivisionValue = 0.001.            
  20.         double DivisionValue = 1 / Math.Pow(10, MultiplicationValue);
  21.         // Creating the decimal part with rounded down value.
  22.         // RoundedDownValue_Float = 0.345.
  23.         double RoundedDownValue_Float = RoundedDownValue * DivisionValue;
  24.         // Creating the full rounded down value.
  25.         // return = 788.345.
  26.         return WholeNumberPart + RoundedDownValue_Float;
  27.     }
  28.     catch (Exception)
  29.     {
  30.         MessageBox.Show("Error ! Please check values.");
  31.         return 0.0;
  32.     }
  33. }




The complete code of the application I created is below with a screenshot of the application running. Hope this helps to you.





  1. using System;
  2. using System.Text;
  3. using System.Windows.Forms;
  4. namespace WindowsFormsApplication1
  5. {
  6.     public partial class Form1 : Form
  7.     {
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.         }
  12.         double RoundDown(double Number, int Digits)
  13.         {
  14.             try
  15.             {
  16.                 return Math.Truncate(Number) +
  17.                     (Math.Floor(Math.Round((Number % 1), Digits) * Math.Pow(10, (Math.Round((Number % 1), Digits).ToString().Length - 3)))) *
  18.                     (1 / Math.Pow(10, Math.Round((Number % 1), Digits).ToString().Length - 3));
  19.             }
  20.             catch (Exception)
  21.             {
  22.                 MessageBox.Show("Error ! Please check values.");
  23.                 return 0.0;
  24.             }
  25.         }
  26.         double RoundDownExplained(double Number, int Digits)
  27.         {
  28.             try
  29.             {
  30.                 // Get the whole number from the double value.
  31.                 // For example we'll take Number = 788.34567 and Digits = 3.
  32.                 // WholeNumberPart = 788.
  33.                 double WholeNumberPart = Math.Truncate(Number);
  34.                 // Getting the decimal part from the doouble value.
  35.                 // DecimalNumberPart = 0.3457.
  36.                 double DecimalNumberPart = Math.Round((Number % 1), Digits);
  37.                 // Finding the number of decimal places so we can multiply by 10 to make it suitable for Floor().
  38.                 // MultiplicationValue = 3.
  39.                 int MultiplicationValue = Math.Round((Number % 1), Digits).ToString().Length - 3;
  40.                 // Create the double value to round down.
  41.                 // RoundedDownValue = 345.
  42.                 double RoundedDownValue = Math.Floor(DecimalNumberPart * Math.Pow(10, MultiplicationValue));
  43.                 // Finding the value to devide the result to make it decimal again.      
  44.                 // DivisionValue = 0.001.            
  45.                 double DivisionValue = 1 / Math.Pow(10, MultiplicationValue);
  46.                 // Creating the decimal part with rounded down value.
  47.                 // RoundedDownValue_Float = 0.345.
  48.                 double RoundedDownValue_Float = RoundedDownValue * DivisionValue;
  49.                 // Creating the full rounded down value.
  50.                 // return = 788.345.
  51.                 return WholeNumberPart + RoundedDownValue_Float;
  52.             }
  53.             catch (Exception)
  54.             {
  55.                 MessageBox.Show("Error ! Please check values.");
  56.                 return 0.0;
  57.             }
  58.         }
  59.         private void button1_Click(object sender, EventArgs e)
  60.         {
  61.             try
  62.             {
  63.                 label1.Text = RoundDown(double.Parse(textBox1.Text), int.Parse(textBox2.Text) + 1).ToString();
  64.             }
  65.             catch (Exception)
  66.             {
  67.                 MessageBox.Show("Error ! Please check values.");
  68.             }
  69.         }
  70.         private void button2_Click(object sender, EventArgs e)
  71.         {
  72.             try
  73.             {
  74.                 label2.Text = RoundDownExplained(double.Parse(textBox1.Text), int.Parse(textBox2.Text) + 1).ToString();
  75.             }
  76.             catch (Exception)
  77.             {
  78.                 MessageBox.Show("Error ! Please check values.");
  79.             }
  80.         }
  81.     }
  82. }