Monday, May 28, 2007

Thousand Separator function for Java Script

     In my project, I have to display the total of selected item in thousand separated format. I am using java script to find total of selected values. Now I have to display the result in Thousand deperated format (like 12,345.00). Here the function that I have used to do that.   


 <script language = "javascript">
function ThousandSeparator(decimalDigits,Value)

// Separator Length. Here this is thousand separator
var separatorLength = 3;

var OriginalValue=Value;

var TempValue = "" + OriginalValue;

var NewValue = "";

// Store digits after decimal
var pStr;

// store digits before decimal
var dStr;

// Add decimal point if it is not there
if (TempValue.indexOf(".")==-1){TempValue+="."}



// Add "0" for remaining digits after decimal point
while (pStr.length-1< decimalDigits){pStr+="0"}

if(pStr =='.') pStr ='';

if(dStr.length > separatorLength)
// Logic of separation
while( dStr.length > separatorLength)
NewValue = "," + dStr.substr(dStr.length - separatorLength) + NewValue;
dStr = dStr.substr(0,dStr.length - separatorLength);

NewValue = dStr + NewValue;

NewValue = dStr;

// Add decimal part
NewValue = NewValue + pStr;

// Show Final value


 Fig (1) Thousand Separator Function in Java Script

   You just need to  pass 2 parameters. Number of digits require after decimal point and value you want to conver in thousand seperated format.

Happy Programming !!

Saturday, May 26, 2007

An error occured while establishing a connection to server. When connectiing to SQL Server 2005,...SQL Network Interfaces, error:26 - Error Locating Server/Instance Specified.

      I have seen this error so many time so I thought that let me post the solution that work for me. First thing check your connection string that it points correct server. This is the most common mistake. Sometime connection string points to SQL Express, while machine does not have SQL Expressed installed.

      If the connection string is correct, second step is to check congiguration of SQL. Click on Start - All Programms - Sql Server 2005 - Configuration Tool - SQL Server Configuration Manager. 

      Click on SQL Server 2005 Network configuration - Protocols for MS SQL Server. Make sure that TCP/IP and Named Piped are Enable. If not that enable it. Now click on SQL Server 2005 Services. Restart Sql Server Browser Service and then restart SQL Server (MSSQLSERVER) service. Yupiiii !!! its all. Check your application now your error should be resolved.

Happy Programming !!

Thursday, May 24, 2007

Disable right click on page.

       Here is the code to disable right click on page.

<body oncontextmenu="return false;">
     Try right click.

   Happy Programming !!


       Today while surfing, I found a good javascript framework Prototype.js. It is a JavaScript library written by Sam Stephenson. This amazingly well thought and well written piece of standards-compliant code takes a lot of the burden associated with creating rich, highly interactive web pages that characterize the Web 2.0 off your back.

       This framework helps the developers to write a good javascript witout knowing much about syntax of javascript and reduce the overhead of remembering lots of complex function.

      You can download this library from here.

       Here is a really good artilce which explains few methods of prototype.js with examples.

UML Diagrams

      I have to create class and Sequence diagrams in my recent project. I was searching for for some quick and good material for UML diagrams. I found the really cool article here.

Thursday, May 03, 2007

Custom DateTime Format Specifier

      Yesterday during surfing I foud really important material on net. I was feeling sleepy so not addded site in favorite and hence notable to give reference here. However I have copied the content in notepad. Its really very helpfull.


Displays the current day of the month.


Displays the current day of the month, where values < 10 have a leading zero.


Displays the three-letter abbreviation of the name of the day of the week.


Displays the full name of the day of the week represented by the given DateTime value.


Displays the x most significant digits of the seconds value. The more f's in the format specifier, the more significant digits. This is total seconds, not the number of seconds passed since the last minute.


Same as f(+), except trailing zeros are not displayed.


Displays the era for a given DateTime (for example, "A.D.")


Displays the hour, in range 112.


Displays the hour, in range 112, where values < 10 have a leading zero.


Displays the hour in range 023.


Displays the hour in range 023, where values < 10 have a leading zero.


Displays the minute, range 059.


Displays the minute, range 059, where values < 10 have a leading zero.


Displays the month as a value ranging from 112.


Displays the month as a value ranging from 112 where values < 10 have a leading zero.


Displays the three-character abbreviated name of the month.


Displays the full name of the month.


Displays the number of seconds in range 059.


Displays the number of seconds in range 059, where values < 10 have a leading 0.


Displays the first character of the AM/PM indicator for the given time.


Displays the full AM/PM indicator for the given time.


Displays the year for the given time.


Displays the timezone offset for the given time.


       Take a look at the following lines of code, which demonstrate using string format specifiers to create custom-formatted date and time strings:  

DateTime dt = DateTime.Now;
"Default format: {0}", dt.ToString()));
"dddd dd MMMM, yyyy g"));
("Custom Format 1: {0:MM/dd/yy hh:mm:sstt}", dt));
("Custom Format 2: {0:hh:mm:sstt G\\MT zz}", dt));

Here is the output from the preceding code:

Default format: 9/24/2005 12:59:49 PM
Saturday 24 September, 2005 A.D.
Custom Format 1: 09/24/05 12:59:49PM

Custom Format 2: 12:59:49PM GMT -06

Happy Programming!!