Wednesday, August 27, 2008

How to Uninstall Symantec Antivirus If we Forget the Password.

I have faced this problem with a workstation inside my Network. Then I follow these steps to remove uninstall Symantec Antivirus.

1) Go to Registry (Regedit).

2) HKEY_LOCAL_MACHINE\SOFTWARE\INTEL\LANDESK\VIRUS PROTECTION\CURRENT VERSION\ADMINISTRATOR ONLY\USEVPUNINSTALLPASSWORD.

3) MODIFY/CHANGE VALUE FROM "1" to "0".

Refresh the registry and then Uninstall Symantec Antivirus. You will get what you want.

Tuesday, August 19, 2008

HOW TO CREATE AND WRITE A FILE IN VB.NET

Dim FILE_NAME As String = "C:\file2.txt"

If System.IO.File.Exists(FILE_NAME) = True Then

Dim fs As New FileStream(FILE_NAME, FileMode.Create, FileAccess.Write)
Dim s As New StreamWriter(fs)
s.WriteLine("Congrates you have created a new file")
s.Close()

ElseIf System.IO.File.Exists(FILE_NAME) = False Then

Dim fs As New System.IO.FileStream(FILE_NAME, FileMode.Create, FileAccess.Write)
Dim s As New System.IO.StreamWriter(fs)
s.WriteLine("Congrates you have created a new file")
s.Close()

End If

Saturday, August 9, 2008

POLYMORPHISM, COMPILATION POLYMORPHISM AND RUNTIME POLYMORPHISM

Polymorphism is the core concept of OOP's. Polymorphism means one name many forms.



Types of polymorphism



  1. Compile Time Polymorphism

  2. Run Time Polymorphism



Compile Time Polymorphism


The compile time polymorphism, here the polymorphism is implemented during compile time, that means at the time of compilation the compiler knows where to bind the method. The compile time polymorphism can be implemented through:



  • Method Overloading

  • Operator Overloading



Method Overloading:


In complex applications written in C#, we may need many methods which do essentially similar functions but are just different enough to be considered unique. So, we can define method overloading as if two or three method in a class has same name but they differ by number of arguments or type of argument.



Operator Overloading:


This provides a meaningful understanding of the operation by using operator overloading. Here what we did is we overload an operator and change its meaning, so that a valuable information is send to the programmer and this help in reducing the complexity.


E.g.


If we need to add two matrix of 3X3


Matrix result = Matrix.Add(mat1, mat2); // this doesn't give any relevant information



Run Time Polymorphism


The run time polymorphism, here the compiler doesn't know which method to call at runtime. Here we can call the derived method through base class pointer at runtime. The run time polymorphism can be implemented through: Virtual – Override Keyword.



Vitual function:


The virtual function is used to implement runtime polymorphism; here we have same name method in the base class as well as in the derived class. We can access the derived method using the base pointer. The virtual keyword should be write in front of the base class method and in the derived class we have to write override in front of the method. For Example:-



Class BaseClass {


Virtual void display () {//statements}


}


Class DerivedClass {


Override void display () {//statements}


}



Example: Demonstrate Polymorphism






BaseClass8.cs



using System;


using System.Collections.Generic;


using System.Text;



namespace cSHARPEXAMPLES


{


class BaseClass8


{


String str = "Base" ;


public BaseClass8() { }


public String display() {


return str + ": BaseClass Display" ;


}


public virtual String show() {


return str + ": BaseClass Show" ;


}


}


}


DerivedClass8.cs



using System;


using System.Collections.Generic;


using System.Text;



namespace cSHARPEXAMPLES


{


class DerivedClass8 : BaseClass8


{


String str = "Derived" ;


public DerivedClass8() { }


public new String display() { //NEW KEYWORD is USE TO HIDE THE


//SAME METHOD IN TH BASE CLASS


return str + ": Display Derived" ;


}


public override String show() { //OVERRIDE KEYWORD IS USED IF


//THE METHOD IN THE BASE CLASS IS VIRTUAL


return str + ": SHOW Derived:" ;


}


}


}



Form8.cs




using System;


using System.Collections.Generic;


using System.ComponentModel;


using System.Data;


using System.Drawing;


using System.Text;


using System.Windows.Forms;



namespace cSHARPEXAMPLES


{


public partial class Form8 : Form


{


public Form8()


{


InitializeComponent();


}


private void button1_Click( object sender, EventArgs e)


{ //Virtual: Polymorphism at RunTime


BaseClass8 objBase = new DerivedClass8 ();


label5.Text = objBase.display();


label6.Text = objBase.show();


}


private void button2_Click( object sender, EventArgs e)


{


BaseClass8 objBase = new BaseClass8 ();


label1.Text = objBase.display();


label2.Text = objBase.show();


}


private void button3_Click( object sender, EventArgs e)


{


DerivedClass8 objDer = new DerivedClass8 ();


label3.Text = objDer.display();


label4.Text = objDer.show();


}


}


}



Output



DATE COMPARISIONS

We can compare dates by the following way.

if CDate(#1/11/2004#) > CDate(#28/ 10/2004#) then
' do stuff
end if

KEYCODEV2.DLL NOT FOUND

This problem is occurred when you are using Crystal Reports in any of your project and have not installed VS.NET 1.x . As you install the full software of Visual Studio 1.x (2003) , it also install DLL's for Crystal Report. So, to solve this problem you have two solutions.

1) Install Visual Studio 2003.

2) Go to References in your project solutions and Follow these options:

a) Right Click on Add Reference.
b) Choose Projects tab in the windows of Add Reference.
c) Click on Browse Button and Select KeyCodeV2.Dll file from "C:\Program Files\Common Files\Crystal Decisions\1.0\Bin\keycodeV2.dll".

Add the file in your references and be happy because now the project will not give the KeyCodeV2 file error.

Happy Programming.

Hope my solution will help you in this regards. I have also solved it in this way.

Wednesday, August 6, 2008

Boxing and Unboxing in C# .Net

Introduction

In this article I will explain the concepts of Boxing and UnBoxing. C# provides us with Value types and Reference Types. Value Types are stored on the stack and Reference types are stored on the heap. The conversion of value type to reference type is known as boxing and converting reference type back to the value type is known as unboxing.

Let me explain you little more about Value and Reference Types.

Value Types

Value types are primitive types that are mapped directly to the FCL. Like Int32 maps to System.Int32, double maps to System.double. All value types are stored on stack and all the value types are derived from System.ValueType. All structures and enumerated types that are derived from System.ValueType are created on stack, hence known as ValueType.

Reference Types

Reference Types are different from value types in such a way that memory is allocated to them from the heap. All the classes are of reference type. C# new operator returns the memory address of the object.

Examples

Lets see some examples to have a better understanding of Value Types and Reference Types. Since we know that all ValueTypes are derived from System.Value we can write something like this:

 System.ValueType r = 5;       

So what do you think about the above line of code. Will it compile ? Yes it will compile. But wait what type is it cause I don't remember any type which is called System.ValueType since its a base class from which all value types inherit. So is it Int32, Int64,double, decimal etc. It turns out that the type for variable 'r' is System.Int32. The Question arrises why Int32 and why not Int16. Well its because it is mapped to Int32 by default depending upon the Initial value of the variable.

You cannot write something like this since System.ValueType is not a primitive type its a base class for primitive value types and these mathematical operations can be performed on primitive types.

System.ValueType r = 10;
r++;

In the above example I told you that variable 'r' will be a System.Int32 variable but if you don't believe me than you can find out yourself using the GetType() method:

 System.ValueType r = 5;
Console.WriteLine(r.GetType()) // returns System.Int32;

Here are few samples you can try on your own:


System.ValueType r = 23.45;
Console.WriteLine(r.GetType()); // what does this print
//-------------------------------------------------------
System.ValueType r = 23.45F;
Console.WriteLine(r.GetType()); // What does this print
//-------------------------------------------------------
System.ValueType r = 2U;
Console.WriteLine(r.GetType()); // What does this print
//-------------------------------------------------------
System.ValueType r = 'c';
Console.WriteLine(r.GetType()); // What does this print
//-------------------------------------------------------
System.ValueType r = 'ac';
Console.WriteLine(r.GetType()); // tricky
//-------------------------------------------------------
System.ValueType r = "Hello World";
Console.WriteLine(r.GetType()); // tricky

Boxing

Lets now jump to Boxing. Sometimes we need to convert ValueTypes to Reference Types also known as boxing. Lets see a small example below. You see in the example I wrote "implicit boxing" which means you don't need to tell the compiler that you are boxing Int32 to object because it takes care of this itself although you can always make explicit boxing as seen below right after implicit boxing.


Int32 x = 10;
object o = x ; // Implicit boxing
Console.WriteLine("The Object o = {0}",o); // prints out 10
//-----------------------------------------------------------
Int32 x = 10;
object o = (object) x; // Explicit Boxing
Console.WriteLine("The object o = {0}",o); // prints out 10


Unboxing

Lets now see UnBoxing an object type back to value type. Here is a simple code that unbox an object back to Int32 variable. First we need to box it so that we can unbox.

Int32 x = 5;
object o = x; // Implicit Boxing
x = o; // Implicit UnBoxing

So, you see how easy it is to box and how easy it is to unbox. The above example first boxs Int32 variable to an object type and than simply unbox it to x again. All the conversions are taking place implicitly. Everything seems right in this example there is just one small problem which is that the above code is will not compile. You cannot Implicitly convert a reference type to a value type. You must explicitly specify that you are unboxing as shown in the code below.

Int32 x = 5;
object o = x; // Implicit Boxing
x = (Int32)o; // Explicit UnBoxing

Lets see another small example of unboxing.

Int32 x = 5; // declaring Int32
Int64 y = 0; // declaring Int64 double
object o = x; // Implicit Boxing
y = (Int64)o; // Explicit boxing to double
Console.WriteLine("y={0}",y);

This example will not work. It will compile successfully but at runtime It will generate an exception of System.InvalidCastException. The reason is variable x is boxed as Int32 variable so it must be unboxed to Int32 variable. So, the type the variable uses to box will remain the same when unboxing the same variable. Of course you can cast it to Int64 after unboxing it as Int32 as follows:

Int32 x = 5; // declaring Int32
Int64 y = 0; // declaring Int64 double
object o = x; // Implicit Boxing
y = (Int64)(Int32)o; // Unboxing and than casting to double
Console.WriteLine("y={0}",y);

I am sure that you all have grasp the basic understanding of Boxing and Unboxing. Happy Coding and practice a lot !