Trimming text using JavaScript

January 14, 2010

The following code snippet can be used to trim the leading and trailing blanks in a textbox using JavaScript. Here the value of the HTML control is trimmed in the trimText function using reg expressing in JavaScript. If the trimText function is called in onblur event of a textbox, then text in the textbox will be trimmed.

function trimText(textBox)
{
    var textValue = textBox.value;
    textValue = textValue.replace(/(\s+$)|(^\s+)/g, '');
    textBox.value = textValue;
}

Call the above function in the following Server side and client side HTML controls

<asp:TextBox ID="txtLoginID" runat="server" Width="147px" onblur="trimText(this)" > </asp:TextBox>
<input id="txtUserName" type="text" maxlength="15" onBlur=" trimText(this)" />

In code behind, add the following statement in page load

txt1.Attributes.Add("onBlur", "trimText()");

I have posted this code snippet in dotnetspider.com. Click here to view it.

Calling .NET Assembly with COM Clients (VB6.0, VFP6.0 and VC++ 6.0)

January 14, 2010

A .NET assembly cannot be directly used in a VB 6.0 application. It needs to be exported into a Type Library.

A type library is a file or part of a file that describes the type of one or more COM objects. Type libraries do not store objects; they store type information. By accessing a type library, applications can determine the characteristics of an object, such as the interfaces supported by the object and the names and addresses of the members of each interface. A member can also be invoked through a type library.

I have written an article in dotnetspider.com which will describe the steps to use a .NET Assembly in COM Clients such as VB 6.0 or VC++ applications. Click this link.

Calling .NET Assembly with COM Clients like VB6.0, VFP6.0 and VC++ 6.0

How to return an Oracle Resultset to a DataTable in .NET

January 14, 2010

A stored Procedure in SQL Server can return a resultset and fill a DataTable simply if we write a SELECT statement within the stored procedure. But how will you return a result set from an Oracle stored procedure.

Cursors in Oracle provide a mechanism by which you can iterate over the records in a database. Using a REF_CURSOR, you can return a resultset from an Oracle stored procedure.

REF CURSOR is a pointer into a result set returned by a PL/SQL query. Unlike a normal cursor, a REF CURSOR is a variable, a reference to a cursor that can be set to point to different result sets at execution time. You can use a REF CURSOR output parameter to pass a result set from an Oracle structured program back to the .NET calling application.

You need to define an output parameter of data type OracleType.Cursor in the calling .NET application to access the result set pointed to by the REF CURSOR. The OracleConnection object in .NET must remain open while the REF CURSOR is being used.

There are two types of ref cursors in Oracle. They are Strong Ref Cursor and Weak Ref Cursor.

For the strong ref cursor, the returning columns with data type and length need to be known at compile time. Example

TYPE STRONG REF_CURSOR IS REF CURSOR RETURN EMP%ROWTYPE

For the weak ref cursor, the structure does not need to be known at compile time. The weak ref cursor is also called a dynamic cursor. Example

TYPE WEAK_REF_CURSOR IS REF CURSOR;

To return a resultset from an oracle stored procedure, first you need to create a package in the Oracle database.

Please visit my article in dotnetspider.com to read more on this.

Finding the number of occurrences of an element in an array in .NET

January 14, 2010

The following code snippets can be used to find the occurence of an element in an integer array.

static void Main(string[] args)
{
//Declare an integer array
int[] integerArray = new int[] { 1, 2, 3, 1, 4, 5, 6, 1, 7, 8, 9, 1, 10, 11 };

/* Find the occurence of the element '1' in the above array. The function 'CheckInteger' iterate through the array and compare each element of the array with '1'.*/
Console.WriteLine("No of occurrences for '1' : {0}", Array.FindAll(integerArray, CheckInteger).Length);

}
//This function loop through the array element when used in the Array.FindAll function
private bool CheckInteger(int n)
{
if (n == 1)
return true;
else
return false;
}

The following code snippets can be used to find the occurence of an element in a string array.

static void Main(string[] args)
{
//Declare a string array
string[] stringArray = new string[] { "Chennai", "Delhi", "Bangalore", "Chennai", "Hydrabad", "Mumbai", "Kolkatta" };

/* Find the occurence of the string ‘Chennai’ in the above array. The function ‘CheckForChennai’ iterate through the array and compare each element of the array with 'Chennai'.*./

Console.WriteLine("No of occurrences for 'Chennai' : {0}", Array.FindAll(stringArray, CheckForChennai).Length);
}

//This function loop through the array element when used in the Array.FindAll function
private bool CheckForChennai(string s)
{

if(s.ToLower() == "chennai")
{
return true;
}
else
{
return false;
}
}

I have posted this code snippet in dotnetspider.com. Click here to view it.

Microsoft Robotics

August 4, 2009

The Microsoft Robotics Developer Studio (Microsoft RDS, MRDS) is a platform for developing robotics application and a Windows-based environment for robot control and simulation. It is aimed at academic, hobbyist, and commercial developers and handles a wide variety of robot hardware.

robotics-1

RDS includes a lightweight REST-style, service-oriented runtime, a set of visual authoring and simulation tools, as well as tutorials and sample code to help get started.

Microsoft Visual Programming Language in RDS enables anyone to create and debug robotics programs very easily. Just drag and drop blocks that represent services, and connect them. It is also possible to take a collection of connected blocks and reuse them as a single block elsewhere in the program.

MRDS is available in three flavors:

Express Edition – Available as free download with limited features targeting hobbyists and casual users.
Standard Edition – Can be used for commercial purpose by professional developers and costs $499.00(US).
Academic Edition – Available for students and educational researchers at no cost through MSDN Academic Alliance program.

The latest version is Robotics Developer Studio 2008 R2 which is released recently.

For more information, visit http://www.microsoft.com/robotics

Silverlight 3 for VS 2008

July 31, 2009

Add-on for Visual Studio 2008 SP1 for developing Silverlight 3 applications has been released. You can download it from here. It can be installed on top of either Visual Studio 2008 SP1 or Visual Web Developer 2008 Express with SP1 and it provides a Silverlight project system for developing Silverlight applications using C# or Visual Basic. This downloads provides project templates, run time, software development kit, WCF Templates, Intellisense and code generators for XAML for Sliverlight 3.

Offline documentation for developing Silverlight 3 applications has also been released and can be downloaded from here. This download is available as a zip file and will have a CHM file within it.

Displaying TIFF Images in ASP.NET

July 30, 2009

TIFF images cannot be displayed in IE as like JPEG, GIF images. Since IE does not support to display TIFF images, we cannot directly display TIFF images in <img> HTML control and Server side Image control. We should convert TIFF images into browser compatible format like GIF, JPG, PNG etc format and then display it in image controls.

I have written an article in dotnetspider.com which will explain about this. Click here to read it.