Monday, April 25, 2011

How to convert number into words in C Sharp.Net

Ram Ram Friends

Well there are many different great algos (easy & small) to achieve this.
Below is the one of them.

Following is the sample code in C#.Net to convert number into words
Since, I am Indian, so as per Indian requirement, I made this program to suit our basic needs,
But as this algo is very clear & easy to understand, you can convert it very easily by making very few changes to suit your culture/needs.
This algo basically more focus on using strings (very less Mathematical formulas/tricks) to achieve the goal, this make it more simpler & easy to convert it into any programming language.


  • using System;

  • namespace ArunKakkarConsoleApp1
  • {
  •     public class AK_NumberToWords
  •     {
  •         public string GetDigitInWords(int i)
  •         {
  •             if (i < 1)
  •                 return "";//"zero";
  •             string s="";
  •             if (i.ToString().Length > 2)
  •             {
  •                 i = Convert.ToInt32(i.ToString().Substring(i.ToString().Length - 2, 2));
  •             }
  •             string[] s1 = new string[] { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
  •             string[] s2 = new string[] { "","", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
  •             string s3, s4;
  •             if (i < 20)
  •                 s = s1[i];
  •             else
  •             {
  •                 s3 = i.ToString().Substring(0, 1);
  •                 s = s2[Convert.ToInt32(s3)];
  •                 s4 = i.ToString().Substring(1, 1);
  •                 s = s + " " + s1[Convert.ToInt32(s4)];            
  •             }
  •             /*switch (i)   //you can use this switch statement if u don't like to use array
  •             { 
  •                 case 1:
  •                     s = "one";
  •                     break;
  •                 case 2:
  •                     s = "two";
  •                     break;
  •                 case 3:
  •                     s = "three";
  •                     break;
  •                 case 4:
  •                     s = "four";
  •                     break;
  •                 case 5:
  •                     s = "five";
  •                     break;
  •                 case 6:
  •                     s = "six";
  •                     break;
  •                 case 7:
  •                     s = "seven";
  •                     break;
  •                 case 8:
  •                     s = "eight";
  •                     break;
  •                 case 9:
  •                     s = "nine";
  •                     break;
  •                 case 10:
  •                     s = "ten";
  •                     break;
  •                 case 11:
  •                     s = "eleven";
  •                     break;
  •                 case 12:
  •                     s = "twelve";
  •                     break;
  •                 case 13:
  •                     s = "thirteen";
  •                     break;
  •                 case 14:
  •                     s = "fourteen";
  •                     break;
  •                 case 15:
  •                     s = "fifteen";
  •                     break;
  •                 case 16:
  •                     s = "sixteen";
  •                     break;
  •                 case 17:
  •                     s = "seventeen";
  •                     break;
  •                 case 18:
  •                     s = "eighteen";
  •                     break;
  •                 case 19:
  •                     s = "nineteen";
  •                     break;
  •                 default: 
  •                     string s2;
  •                     s2 = i.ToString().Substring(0, 1);
  •                     switch (Convert.ToInt32(s2))
  •                     {
  •                         case 2:
  •                             s = "twenty";
  •                             break;
  •                         case 3:
  •                             s = "thirty";
  •                             break;
  •                         case 4:
  •                             s = "fourty";
  •                             break;
  •                         case 5:
  •                             s = "fifty";
  •                             break;
  •                         case 6:
  •                             s = "sixty";
  •                             break;
  •                         case 7:
  •                             s = "seventy";
  •                             break;
  •                         case 8:
  •                             s = "eighty";
  •                             break;
  •                         case 9:
  •                             s = "ninety";
  •                             break;
  •                     }
  •                     s2 = i.ToString().Substring(1, 1);
  •                     s = s  + " " + this.GetDigitInWords(Convert.ToInt32(s2));
  •                     break;
  •             }*/
  •             return s;
  •         }

  •         public string GetNoInWords(double d)
  •         {
  •             string s="";
  •             //19,23,45,67,89,12,34,56,789.87
  •             //Rs  ....., 67 Kharab,89 Arab,12 crore, 34 lacs, 56 thousands,7 hundred, 89 and 87 paise only

  •             //67,89,12,34,56,789.87
  •             //Rs 67 Kharab,89 Arab,12 crore, 34 lacsh, 56 thousands,7 hundred, 89 and 87 paise only
  •             string sPaise,sTens, sHundred, sThousand, sLacs, sCrore, sArab, sKharab, sLong;
  •             int i;
  •             
  •             sLong = ((long)d).ToString();
  •             if (sLong.Length > 13)
  •             {
  •                 //s = "Out of range value and maximum value is= ";
  •                 sLong = sLong.Substring(sLong.Length - 13, 13);
  •             }
  •             if(sLong.Length <13)
  •                 sLong =sLong.PadLeft(13,'0');

  •             //Console.WriteLine("\nslong=" + sLong);

  •             sKharab = sLong.Substring(0, 2); //Kharab
  •             sArab = sLong.Substring(2, 2);  //arab
  •             sCrore = sLong.Substring(4, 2);  //Crore
  •             sLacs = sLong.Substring(6, 2);  //Lacs
  •             sThousand = sLong.Substring(8, 2); //thousands
  •             sHundred = sLong.Substring(10, 1); //Hundred
  •             sTens = sLong.Substring(11, 2); //Tens                        

  •             if (d.ToString().Contains("."))
  •                 sPaise = d.ToString().Substring(d.ToString().IndexOf('.')+1);
  •             else
  •                 sPaise = "0";
  •             
  •             if (sPaise.Length>2)
  •                 sPaise = sPaise.Substring(0, 2);

  •             i = Convert.ToInt16(sKharab);
  •             if (i > 0)
  •                 s = this.GetDigitInWords(i) + ((i>1)? " Kharabs " : " Kharab ");

  •             i = Convert.ToInt16(sArab);
  •             if (i > 0)
  •                 s += this.GetDigitInWords(i) + ((i>1)?" Arabs " : " Arab ");

  •             i = Convert.ToInt16(sCrore);
  •             if (i > 0)
  •                 s += this.GetDigitInWords(i) + ((i>1)?" Crores " : " Crore ");

  •             i = Convert.ToInt16(sLacs);
  •             if (i > 0)
  •                 s += this.GetDigitInWords(i) + ((i>1)? " Lacs ": " Lac ");

  •             i = Convert.ToInt16(sThousand);
  •             if (i > 0)
  •                 s += this.GetDigitInWords(i) + ((i>1)? " Thousands " : " Thousand ");

  •             i = Convert.ToInt16(sHundred);
  •             if (i > 0)
  •                 s += this.GetDigitInWords(i) +((i>1)?  " Hundreds ": " Hundred ");

  •             i=Convert.ToInt16(sTens);
  •             if (i > 0)
  •                 s += this.GetDigitInWords(i) + " ";

  •             i = Convert.ToInt16(sPaise);
  •             if (i > 0)
  •                 s += " and " + this.GetDigitInWords(i) + ((i>0)? " Paises ": " Paise ");

  •             s += "only";

  •             return s;
  •         }//public string GetNoInWords(double d)
//Below is using Math logic 
//I tried to give example at almost each step to understand logic
  •         public String GetDigitInWordsByMath(int i)
  •         {
  •             string s="";
  •             int j, k;
  •             string[] s1 = new string[] { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "tweleve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
  •             string[] s2 = new string[] { "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
  •             if (i < 20)
  •                 s = s1[i];
  •             else
  •             {
  •                 j = i / 10; //tens digit
  •                 k = i % 10; //unit digit
  •                 s = s2[j] + " " + s1[k];
  •             }
  •             return s;
  •         }

  •         public string GetNumInWordsByMath(double d)
  •         {
  •             //19,23,45,67,89,12,34,56,789.87
  •             //Rs  ....., 67 Kharab,89 Arab,12 crore, 34 lacs, 56 thousands,7 hundred, 89 and 87 paise only

  •             //67,89,12,34,56,789.87
  •             //Rs 67 Kharab,89 Arab,12 crore, 34 lacs, 56 thousands,7 hundred, 89 and 87 paise only

  •             string s="";
  •             long myNum;
  •             int iPaise, iDigit, iHundred, iThousand, iLac, iCrore, iArab, iKharab;

  •             //let d=1234567898765.43
  •             // 25%10=5 (return Remainder) applicable in Integer only
  •             // 25/10=2 (return Quotient) applicable in Integer only

  •             myNum = (long)(d*100); //myNum=1234567898765.43*100 =123456789876543

  •             iPaise = (int)(myNum % 100);  //iPaise=123456789876543%100 =43
  •             myNum = myNum / 100;       //myNum=123456789876543/100  =1234567898765
  •             
  •             iDigit = (int)(myNum % 100);  //iDigit=1234567898765 %100  =65
  •             myNum  = myNum / 100; //myNum =1234567898765 /100   =12345678987

  •             iHundred =(int)( myNum % 10); //iHundred=12345678987 %10   =7
  •             myNum = myNum / 10;    //myNum =12345678987/10      =1234567898

  •             iThousand = (int)(myNum % 100); //iThousand=1234567898%100 =98
  •             myNum = myNum / 100;    //myNum=1234567898/100      =12345678

  •             iLac = (int)(myNum % 100);    //iLac=12345678%100          =78
  •             myNum = myNum / 100;   //myNum=12345678/100         =123456

  •             iCrore = (int)(myNum % 100);  //iCrore=123456%100          =56
  •             myNum = myNum / 100;   //myNum=123456/100           =1234

  •             iArab = (int)(myNum % 100);   //iArab=1234%100             =34
  •             myNum = myNum / 100;   //myNum=1234/100             =12

  •             iKharab = (int)(myNum % 100); //iKharab=12%100             =12
  •             myNum = myNum / 100;   //myNum=12/100               =0

  •             if (iKharab > 0)
  •                 s = this.GetDigitInWordsByMath(iKharab) + ((iKharab > 1) ? " Kharabs " : " Kharab ");

  •             if (iArab > 0)
  •                 s += this.GetDigitInWordsByMath(iArab) + ((iArab > 1) ? " Arabs " : " Arab ");

  •             if (iCrore > 0)
  •                 s += this.GetDigitInWordsByMath(iCrore) + ((iCrore > 1) ? " Crores " : " Crore ");

  •             if (iLac > 0)
  •                 s += this.GetDigitInWordsByMath(iLac) + ((iLac > 1) ? " Lacs " : " Lac ");

  •             if (iThousand > 0)
  •                 s += this.GetDigitInWordsByMath(iThousand) + ((iThousand > 1) ? " Thousands " : " Thousand ");

  •             if (iHundred > 0)
  •                 s += this.GetDigitInWordsByMath(iHundred) + ((iHundred > 1) ? " Hundreds " : " Hundred "); 

  •             if (iDigit > 0)
  •                 s += this.GetDigitInWordsByMath(iDigit) + " ";

  •             if (iPaise > 0)
  •                 s +=  "and " + this.GetDigitInWordsByMath(iPaise) + ((iPaise > 1) ? " Paises " : " Paise ");

  •             s= "Rs " + s + "only";
  •             return s;
  •         }
  •     } //class

  • class Program
  •     {
  •         static void Main(string[] args)
  •         {            
  •            AK_NumberToWords nw1 = new AK_NumberToWords();
  •             string myAns,myVal;
  •             do
  •             {
  •                 Console.WriteLine("Please enter 2 digit no to get its value in words");
  •                 myVal = Console.ReadLine();
  •                 Console.WriteLine("{0} in words is={1}", myVal, nw1.GetDigitInWords(Convert.ToInt32(myVal)));

  •                 Console.WriteLine("\nPlease enter any number to get its value in words:");
  •                 myVal = Console.ReadLine();
  •                 Console.WriteLine("{0} in words is=\n {1}", myVal, nw1.GetNoInWords(Convert.ToDouble(myVal)));

  • Console.WriteLine("\nPlease enter any number to get its value in words using math logic:");
  •                 myVal = Console.ReadLine();
  •                 Console.WriteLine("{0} in words is=\n {1}", myVal, nw1.GetNumInWordsByMath(Convert.ToDouble(myVal)));

  •                 Console.WriteLine("Do u want to try more?(Y/N)");
  •                 myAns = Console.ReadLine();
  •             } while (myAns == "Y" || myAns == "y");
  •   }//class program

  • }//namespace

Friends, as I already told, it is just one of many different algo used to convert number into words.
Of course, there are lot of ways to minimize/modify it to get more accuracy, speed, & less memory consumption etc.
I hope it would help you.
Wish you a very happy programming.

Thursday, April 21, 2011

How to make TRIAL version( Date based) section in Window Application Software


RAM RAM Friends
How to make TRIAL version (Date based) section in Window Application Software

Hi Friends, when I used to learn how to make complete software during my MCA, I face lot of problem to find a way to provide Trial version option in my projects so that they would run in trial mode for some time/days & after that they need registration to continue.

Now I am providing here a way to resolve such problem by one way out of many possible ways & this is
Trial Version (Date based). 
  1. First I had mentioned the algo to explain its working then
  2. I gave code to implement it in VB6.0 &
  3. Then code in VB.NET

 Here it goes

1. ALGO

({[EVALUATION/DEMO/TRIAL version Management Plan]})

  • Return “AK_Expired” key from registry
  • If AK_Expired=false or 1 (or any other value indicating evaluation expired)
    • Disable evaluation button
    • Show message “Evatuation period expired etc”
  • Else //if AK_Expired=true or 0 (or any other value indicating evaluation not expired)
    •  Search AK_StartDt.akk (or any other name you like) present in computer “Windows” Directory (or any other place in computer you like)
    • If AK_StartDt.akk file not present in computer “Windows” directory
      • Create new file AK_StartDt.akk in computer “Windows” Directory & write current date in this file.
      • Create another file AK_EndDt.akk in computer “Window” directory & write new date which is equal to (current date + 31 days).
      • Enter current date in “AK_LastUsedDt” key in registry
      • Display label “Demo Version........ Just for 31 Days.”
      • Enable evaluation button.
    • Else if AK_StartDt.akk file present in computer “Windows” Directory
      • Return FirstDate from AK_StartDt.akk file
      • Return LastDate from AK_EndDt.akk file
      • Return LastUseDate from “AK_LastUsedDt” key in registry

      • //first level of security for evaluation
      • If LastUseDate=” ”
        • enter current date in “AK_LastUsedDt” key in registry
      • Else if LastUseDate is a date
        • if LastUseDate>current date
          • display message “Evaluation Expired …. Contact ABC”
          • disable “Evaluation” button
          • enter False or 1 in “AK_Expired” key in registry
        • else  //if LastUseDate<=current date
          • enter current date in “AK_LastUsedDt” key in registry
        • end if
      • Else // if LastUseDate is other than date or “ ”
        • display message “Evaluation Expired …. Contact ABC”
        • disable “Evaluation” button
        • enter False or 1 in “AK_Expired” key in registry
      • End if  // If LastUseDate=” ”

      •  //Second Level of security for evaluation
      • If currend date < FirstDate  or current date >LastDate
        • display message “Evaluation Expired …. Contact ABC”
        • disable “Evaluation” button
        • enter False or 1 in “AK_Expired” key in registry
      • Else
        • Show message “only (31-(current date-FirstDate)) days are remaining”
      • End if  // If current date < FirstDate  or current date >LastDate
    • End if   // If AK_StartDt.akk file not present in computer “Windows” directory
  •  End if  // If AK_Expired=false or 1

 Note:
  • 1. I have used following keys to store information in Registry
    • 1. AK_Expired   2. AK_LastUsedDt
  • 2. I have used following files to store information in Windows directory
    • 1. AK_StartDt.akk          2. AK_EndDt.akk
  • 3        To provide more security, you can use any other location or any other keyname/file name & write encrypted information there.
DRAWBACKS
  • As almost all things in universe have few or more drawbacks, this algo also has one drawbacks
    • If after installing & using your software at least one time, user changes his/her system date & then open your software then your software shows 
      • "Trial version expired..............."
  • SOLUTION ---------
    • Since there is no proper solutions, but you can make a small exe which would erase all/few of the evaluation securities or correct them to activate your software in evaluation mode.
      • since one can use the same exe more than one time, so to protect it, you can use either pwd (hard coded or dynamic(based on current date,time,etc), or do some coding so that this file execute only once in its life cycle etc.
    • since sometime after using your evaluation version, user can ask you after some time(days/months/yrs) that he want to use it again or there may be some other porblem, the above solution would be useful in such cases also.


VB6.0 Code to implement the above algo


  • ‘ Below is the api function must write in module1 or somewhere else
    • Public Declare Function GetWindowsDirectory Lib "kernel32.dll" _
    • Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Integer) As Long 
  • Note:-----Below procedure must be put in either startup procedure of project or in load event of evaluation form 
  • ‘get the Window directory path
  •  
  • strTemp = String$(255, Chr(0))
  • lngRetVal = GetWindowsDirectory(strTemp, Len(strTemp))
  • strTemp = Replace(strTemp, Chr(0), "")
  •  
  • ‘Get Hard drive serial no to act as Project password. You can encrypt it to make software more secure
  •  '--Begin-------how to get Hard drive serial no via vb6------------------
  • Dim FS As FileSystemObject
  • Set FS = New FileSystemObject
  • Dim d As Drive
  • Set d = FS.GetDrive("C:")
  • GValidNo = Abs(d.SerialNumber)
  •  '--End-------how to get Hard drive serial no via vb6------------------ 
  • ‘Get Project password (here Hard drive Serial No) from registry
  • mactno = GetSetting("ArunKakkarCompany ", " AK_Proj1", "AK_MacPwd")
  •  
  • ‘Check if software is registered or not
  • If mactno = GValidNo Then
    • ‘below are the various controls on the evaluation form
    • Me.Frame1.Visible = False
    • Me. lblMsg.Visible = True
  • Else 
    • If GetSetting("ArunKakkarCompany ", " AK_Proj1", " AK_Expired ") <> "1" Then
      • If FS.FileExists(strTemp & "\ AK_StartDt.akk ") Then
        • Fl = FreeFile 
        • ‘here reading date from file which(date) is stored as day in 1st line, ‘month in 2nd line & year in 3rd line of file to make a small kind of encryption & converting it into d/m/yyyy format          
        • ‘open file in read only mode  
        • Open strTemp & "\ AK_StartDt.akk " For Input As #Fl
          • S1 = ""
          • Do While Not EOF(Fl)                  
            • ‘read one line from file & store value in s
            • Input #Fl, S
            • If S1 = "" Then
              • S1 = S
            • Else
              • S1 = S1 & "/" & S
            • End If
          • Loop
        • Close #Fl
        • S1 = Format(S1, "D/M/YYYY")
        • Fl = FreeFile
        • Open strTemp & "\ AK_EndDt.akk " For Input As #Fl
          • S2 = ""
          • Do While Not EOF(Fl)
            • Input #Fl, S
            • If S2 = "" Then
              • S2 = S
            • Else
              • S2 = S2 & "/" & S
            • End If
          • Loop
        • Close #Fl
        • S2 = Format(S2, "D/M/YYYY")
        • LastUsedDate = GetSetting("ArunKakkarCompany ", "AK_Proj1", "AK_LastUsedDt")
        • If LastUsedDate = "" Then
          • SaveSetting " ArunKakkarCompany ", "AK_Proj1", "AK_LastUsedDt", Date
        • ElseIf CDate(LastUsedDate) Then
          • If (Date - CDate(LastUsedDate)) < 0 Then
            • Me. lblMsg.Visible = True
            • Me. lblMsg.Caption = "EVALUATION EXPIRED...., contact ArunKakkarCompany "
            • Me.Frame1.Visible = True
            • Me.lblUseEavl.Enabled = False
            • Timer1.Enabled = False
            • SaveSetting " ArunKakkarCompany ", "AK_Proj1", "AK_Expired", "1"
            • Me.lblUseEavl.Enabled = False
            • Exit Sub
          • End If
          • SaveSetting " ArunKakkarCompany ", "AK_Proj1", "AK_LastUsedDt", Date
        • Else     //If LastUsedDate = "" Then
          • Me. lblMsg.Visible = True
          • Me. lblMsg.Caption = "Evaluation Expired...., contact ArunKakkarCompany "
          • Me.Frame1.Visible = True
          • Me.lblUseEavl.Enabled = False
          • Timer1.Enabled = False
          • SaveSetting " ArunKakkarCompany ", "AK_Proj1", "AK_Expired", "1"
          • Me.lblUseEavl.Enabled = False
        • End If      //If LastUsedDate = "" Then
        • If DateDiff("d", Date, S1) > 0 Or DateDiff("d", Date, S2) < 0 Then
          • Me. lblMsg.Visible = True
          • Me. lblMsg.Caption = "Evaluation Expired...., contact ArunKakkarCompany "
          • Me.Frame1.Visible = True
          • Me.lblUseEavl.Enabled = False
          • Timer1.Enabled = False
          • SaveSetting " ArunKakkarCompany ", "AK_Proj1", "AK_Expired", "1"
          • Me.lblUseEavl.Enabled = False
        • Else
          • Me. lblMsg.Visible = True    'Change
          • Me. lblMsg.Caption = "Only " & (31 - Val(DateDiff("D", CDate(S1), Date))) & " Days are Remaining"
          • 'Me. lblMsg.Caption = "Only " & 31 & " Days are Remaining"
          • 'Me.lblUseEavl.Enabled = True
        • End If
      • Else  //If FS.FileExists(strTemp & "\ AK_StartDt.akk ") Then
        • Fl = FreeFile
        • Open strTemp & "\AK_StartDt.akk" For Output As #Fl
          • Print #Fl, Format(Day(Date), "0#")
          • Print #Fl, Format(Month(Date), "#")
          • Print #Fl, Year(Date)
        • Close #Fl
        • EndDt = CDate(DateAdd("D", 31, Date))
        • Fl = FreeFile
        • Open strTemp & "\AK_EndDt.akk" For Output As #Fl
          • Print #Fl, Format(Day(EndDt), "0#")
          • Print #Fl, Format(Month(EndDt), "#")
          • Print #Fl, Year(EndDt)
        • Close #Fl
        • Me. lblMsg.Visible = True
        • SaveSetting "ArunKakkarCompany ", "AK_Proj1", "AK_LastUsedDt", Date
        • Me. lblMsg.Caption = "Demo Version........ Just for 31 Days."
        • Me.lblUseEavl.Enabled = True
      • End If   //If FS.FileExists(strTemp & "\ AK_StartDt.akk ") Then
    • Else     //If GetSetting("ArunKakkarCompany ", " AK_Proj1", " AK_Expired ") <> "1" Then
      • Me. lblMsg.Visible = True
      • Me. lblMsg.Caption = "Evaluation Expired...., Contact ArunKakkarCompany "
      • Me.Frame1.Visible = True
      • Me.lblUseEavl.Enabled = False
      • Timer1.Enabled = False
    • End If     //If GetSetting("ArunKakkarCompany ", " AK_Proj1", " AK_Expired ") <> "1" Then
  • End If         //If mactno = GValidNo Then

  
Below is the VB.NET Code
  • Here along with date/time based trial version procedure, I also put a small/low quality startup sequence of starting any application software.
  • of course, there are lot of great ways to make software startup/security much more powerful & secure.
  • Below code is the small portion of my small project "Cure"

========================================================
  • Private Sub frmCure_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    • lblContactUs.Text = GDvlprCompanyName & vbNewLine & GDvlprCompanyAddress & vbNewLine & GDvlprCompanyPhoneNo & vbNewLine & GDvlprCompanyEmailId & vbNewLine & GDvlprCompanyWebsite
    • lblActivate.Visible = False
    • txtActivate.Visible = False
    • btnActivate.Visible = False
    • Main(Me)
    • CheckEvaluationPeriod(Me)
  • End Sub
  • ----------------
  • 'Begin---Start point of Cure Project------------------------
  • Public Sub Main(ByVal frm As Form)
    • 'Planning+++++++++++++++++++++++++++++++++++++++++++++
      • '1 Change computer/system date format to dd/mm/yyyy
      • '2 return registration key (rk) from registry
      • '3 if rk =” “or rk not found/exists
        • ' Show “Start up” form
      • ' Else
        • ' Return activation key (ak) by calling appropriate function(say createAK) using os drive serial no 
        • ' If ak != rk
          • ' Show “Start Up” form
        • ' Else    //if ak=rk
          • ' Call function to start s/w (say StartSoftware) 
        • ' End If
      • ' End If
    • '+++++++++++++++++++++++++++++++++++++++++++++++++ 
    • 'ChangeDateFormat()
    • Try
      • CureSecurity(enCureSecurity.ChangeDateFormat)
      • Dim rk As String
      • rk = My.Computer.Registry.GetValue(GKeyPath, GRegistrationKey, "")
      • If rk = "" Then
        • frm.Show()
      • Else
        • Dim ak As String
        • 'ak = retUsrNo(OS_Drive_SNo)
        • ak = CureSecurity(enCureSecurity.SoftwareActivationKey) 
        • If ak = rk Then
          • 'frm.Close()
          • OpenRegisteredCure(frm)
        • Else
          • frm.Show()
        • End If
      • End If
    • Catch ex As Exception
      • CureErrorMsg(ex, "frmModuleFunction-Main")
    • End Try
  • End Sub
  • ---------------
  • Public Function CureSecurity(ByVal Work As enCureSecurity, Optional ByVal UserMachineCode As String = "A") As String
    • Dim s As String = ""
    • Try
      • Dim temp As String = ""
      • Dim ak As New ArunKakkarSoft.ArunKakkarSWReg
      • temp = My.Computer.FileSystem.SpecialDirectories.Desktop
      • 'retrieve the os drive name & then os drive Windows directory path
      • temp = temp.Substring(0, 1) 
      • Select Case Work
        • Case enCureSecurity.ChangeDateFormat
          • ak.ChangeDateFormat()
          • s = ""
        • Case enCureSecurity.SoftwareActivationKey
          • s = ak.GetActivateCodeForSoftware(ak.GetDriveSerialNo(temp))
        • Case enCureSecurity.UserActivationKey
          • s = ak.GetActivateCodeForUser(UserMachineCode)
        • Case enCureSecurity.UserMachineCode
          • s = ak.GetUserMachineCode(ak.GetDriveSerialNo(temp))
      • End Select
      • ak = Nothing 
    • Catch ex As Exception
      • CureErrorMsg(ex, "frmModuleFunction-CureSecurity")
    • End Try
    • Return s
  • End Function
  • --------------
  • Public Sub CheckEvaluationPeriod(ByVal frm As frmCureEvaluation)
    • 'Return “AK_Expired” key from registry
    • 'If AK_Expired = False Or 1 Then
      • 'Disable evaluation button
      • 'Show message “Evatuation period expired etc”
    • 'Else //if AK_Expired=true or 0
      • 'Search AK_StartDt.akk or another name (like AK_StartDt.akk) present in computer “Windows” Directory()
      • 'If AK_StartDt.akk file not present in computer “Windows” directory
        • '1Create new file AK_StartDt.akk in computer “Windows” Directory & write current date in this file
        • '2 Create another file AK_EndDt.akk in computer “Window” directory & write new date which is equal to (current date + 31 days) 
        • '3 enter current date in “AK_LastUsedDt” key in registry
        • '4  display label Demo Version........ Just for 31 Days.
        • '5  enable evaluation button 
      • 'Else if AK_StartDt.akk file present in computer “Windows” Directory
        • 'Return FirstDate from AK_StartDt.akk file
        • 'Return LastDate from AK_EndDt.akk file
        • 'Return LastUseDate from “AK_LastUsedDt” key in registry 

        • //first level of security for evaluation
        • 'If LastUseDate = " " Then
          • 'enter current date in “AK_LastUsedDt” key in registry
        • 'Else if LastUseDate is a date
          • 'if LastUseDate>current date
            • 'display message “Evaluation Expired …. Contact ABC”
            • 'disable “Evaluation” button
            • 'enter False or 1 in “AK_Expired” key in registry
          • 'else  //if LastUseDate<=current date
            • 'enter current date in “AK_LastUsedDt” key in registry
          • 'End If
        • 'Else // if LastUseDate is other than date or “ ”
          • 'display message “Evaluation Expired …. Contact ABC”
          • 'disable “Evaluation” button
          • 'enter False or 1 in “AK_Expired” key in registry
        • 'End if  // If LastUseDate=” ”  

        • '//Second Level of security for evaluation
        • 'If currend date < FirstDate  or current date >LastDate
          • 'display message “Evaluation Expired …. Contact ABC”
          • 'disable “Evaluation” button
          • 'enter False or 1 in “AK_Expired” key in registry
        • 'Else
          • 'Show message “only (31-(current date-FirstDate)) days are remaining”
        • 'End if  // If currend date < FirstDate  or current date >LastDate
      • 'End if   // If AK_StartDt.akk file not present in computer “Windows” directory
    • 'End if  // If AK_Expired=false or 1  
    • 'Dim f1 As New frmCureEvaluation 
    • Try
      • Dim ActiveKey As String
      • Dim FirstDate, LastDate, LastUseDate, temp2 As String
      • Dim i As Integer 
      • 'if activekey=1 then evaluation expired
      • ActiveKey = My.Computer.Registry.GetValue(GKeyPath, GIsActive, "0")
      • If ActiveKey = "1" Then
        • ExpireEvaluation(frm, False)
      • Else    'activekey=0   'active key<>1 
        • If Not My.Computer.FileSystem.FileExists(GetCureFilePath(CureFiles.Cure_dll)) Then  'if Cure.dll file not found
          • 'write to Cure.dll
          • WriteToFile(CureFiles.Cure_dll, Format(Now.Day, "0#"), False)
          • WriteToFile(CureFiles.Cure_dll, Format(Now.Month, "#"), True)
          • WriteToFile(CureFiles.Cure_dll, Now.Year, True) 
          • 'write to Cure1.dll 
          • Dim LastDt As Date
          • LastDt = DateAdd(DateInterval.Day, 31, Now.Date)
          • WriteToFile(CureFiles.Cure1_dll, Format(LastDt.Day, "0#"), False)
          • WriteToFile(CureFiles.Cure1_dll, Format(LastDt.Month, "#"), True)
          • WriteToFile(CureFiles.Cure1_dll, LastDt.Year, True) 
          • 'write to registry
          • My.Computer.Registry.SetValue(GKeyPath, GLastUsed, Now.Date.ToShortDateString)
          • frm.lblEvaluationMsg.Text = "Demo Version........ Just for 31 Days."
          • frm.btnEvaluation.Enabled = True
        • Else 'if Cure.dll file found 
          • 'read from Cure.dll
          • FirstDate = ""
          • For i = 1 To 3
            • temp2 = ReadFromFile(CureFiles.Cure_dll, i)
            • If FirstDate = "" Then
              • FirstDate = temp2
            • Else
              • FirstDate = FirstDate & "/" & temp2
            • End If
          • Next
          • If IsDate(FirstDate) Then
            • FirstDate = Format(CDate(FirstDate), "d/M/yyyy")
          • Else 'if someone make changes in file data
            • ExpireEvaluation(frm, True)
            • Exit Sub
          • End If 
          • 'read from Cure1.dll
          • LastDate = ""
          • If My.Computer.FileSystem.FileExists(GetCureFilePath(CureFiles.Cure1_dll)) Then
            • For i = 1 To 3
              • temp2 = ReadFromFile(CureFiles.Cure1_dll, i)
              • If LastDate = "" Then
                • LastDate = temp2
              • Else
                • LastDate = LastDate & "/" & temp2
              • End If
            • Next
            • If IsDate(LastDate) Then
              • LastDate = Format(CDate(LastDate), "d/M/yyyy")
            • Else 'if someone make changes in file data
              • ExpireEvaluation(frm, True)
              • Exit Sub
            • End If 
          • Else  'if Cure1.dll file not found
            • ExpireEvaluation(frm, True)
            • Exit Sub
          • End If 
          • 'verify again that FirstDate & LastDate are valid date else evaluation expire
          • If Not (IsDate(FirstDate) And IsDate(LastDate)) Then
            • ExpireEvaluation(frm, True)
            • Exit Sub
          • End If 
          • 'get LastUseDate from registry
          • LastUseDate = My.Computer.Registry.GetValue(GKeyPath, GLastUsed, "") 
          • 'first level of security for evaluation
          • If LastUseDate = "" Then
            • My.Computer.Registry.SetValue(GKeyPath, GLastUsed, Now.Date.ToShortDateString)
          • ElseIf IsDate(LastUseDate) Then
            • If (CDate(LastUseDate) > Now.Date) Then
              • ExpireEvaluation(frm, True)
            • Else  'if LastUseDate<=CurrentDate
              • My.Computer.Registry.SetValue(GKeyPath, GLastUsed, Now.Date.ToShortDateString)
            • End If
          • Else 'if LastUseDate is not a date & not empty
            • ExpireEvaluation(frm, True)
          • End If 
          • 'Second Level of Security for evaluation
          • If (Now.Date < CDate(FirstDate)) Or (Now.Date > CDate(LastDate)) Then
            • ExpireEvaluation(frm, True)
          • Else
            • frm.lblEvaluationMsg.Text = "EVALUATION VERSION------->>>Only " & (31 - (Now.Date - CDate(FirstDate)).Days) & " days are remaining!!!!!"
          • End If
        • End If  'If Not My.Computer.FileSystem.FileExists(filePath) Then  'if Cure.dll file not found
      • End If 'If ActiveKey <> "0" Then
    • Catch ex As Exception
      • CureErrorMsg(ex, "frmModuleFunction-CheckEvaluationPeriod")
    • End Try
  • End Sub
  • --------------
  • Public Sub ExpireEvaluation(ByVal frm As frmCureEvaluation, Optional ByVal ModifyActiveKey As Boolean = True)
    • Try
      • Dim ExpireMsg As String
      • ExpireMsg = "EVALUATION EXPIRED...., contact ARUNKAKKARCOMPANY "
      • If ModifyActiveKey Then
        • My.Computer.Registry.SetValue(GKeyPath, GIsActive, "1")
      • End If
      • frm.lblEvaluationMsg.Text = ExpireMsg
      • frm.btnEvaluation.Enabled = False
    • Catch ex As Exception
      • CureErrorMsg(ex, "frmModuleFunction-ExpireEvaluation")
    • End Try
  • End Sub
  • ---------------------
  • 'Begin-----File Handling in VB.NET ---------------------------------------------------------
  • Public Function GetCureFilePath(ByVal file As CureFiles) As String
    • Dim path As String = ""
    • Try
      • Dim temp As String
      • temp = My.Computer.FileSystem.SpecialDirectories.Desktop
      • 'retrieve the os drive name & then os drive Windows directory path
      • temp = temp.Substring(0, 1) & ":\Windows\"  'Cure.dll"
      • path = ""
      • Select Case file
        • Case CureFiles.Cure_dll
          • path = temp & "Cure.dll"
        • Case CureFiles.Cure1_dll
          • path = temp & "Cure1.dll"
        • Case CureFiles.CurePurchaseOrder_txt
          • path = My.Computer.FileSystem.SpecialDirectories.Desktop & "\CurePurchaseOrder.txt"
        • Case CureFiles.CureServer_ini
          • path = My.Application.Info.DirectoryPath & "\CureServer.ini"
        • Case CureFiles.CureDataBaseFile
          • path = My.Application.Info.DirectoryPath & "\CureData\Cure.mdf"
        • Case CureFiles.CureDataBaseLogFile
          • path = My.Application.Info.DirectoryPath & "\CureData\Cure_log.ldf"
      • End Select
    • Catch ex As Exception
      • CureErrorMsg(ex, "frmModuleFunction-GetCureFilePath")
    • End Try
    • Return path
  • End Function
  •  
  • Public Sub WriteToFile(ByVal file As CureFiles, ByVal StringData As String, Optional ByVal AppendMode As Boolean = True)
    • Try
      • Dim path As String
      • path = GetCureFilePath(file)
      • Dim fileWrt As System.IO.StreamWriter
      • fileWrt = My.Computer.FileSystem.OpenTextFileWriter(path, AppendMode)
      • fileWrt.WriteLine(StringData)
      • fileWrt.Close()
    • Catch ex As Exception
      • CureErrorMsg(ex, "frmModuleFunction-WriteToFile")
    • End Try
  • End Sub
  •  
  • Public Function ReadFromFile(ByVal file As CureFiles, ByVal lineno As Integer, Optional ByVal IsFullFile As Boolean = False) As String
    • Dim line As String = ""
    • Try
      • Dim i As Integer
      • Dim path As String
      • path = GetCureFilePath(file)
      • Using sr As StreamReader = New StreamReader(path)
        • 'Read and display the lines from the file until the end of the file is reached.
        • If IsFullFile Then
          • Dim s As String = ""
          • i = 0
          • Do
            • i = i + 1
            • s = sr.ReadLine()
            • If Not (s Is Nothing) Then
              • line = line & vbNewLine & i & " " & s
            • End If
          • Loop Until s Is Nothing
          • line = Trim(line)
        • Else
          • For i = 1 To lineno - 1
            • line = sr.ReadLine()
          • Next
          • line = Trim(sr.ReadLine())
        • End If
        • sr.Close()
      • End Using 
    • Catch ex As Exception
      • CureErrorMsg(ex, "frmModuleFunction-ReadFromFile")
    • End Try
    • Return line  'ReadFromFile = line
  • End Function
  • 'End-----File Handling in VB.NET ---------------------------------------------------------

I hope this would be helpful.
Best of luck for good programming.