Monday, 22 April 2013

Creating Directories Inside Outlook

Create A Directories And Sub Directories In Outlook-

Here I create the directories in outlook through the Outlook Addins in VS 2010, follow this steps-
1.Open the VS2010  choose the selected option show in the image.
2.After the open a new window double click on 'ThisAddIn.vb',open code space.
3.In code space put the code-
   a) Let us create  function CreateOutlookDirectories().
    b)Here i create a 'flag' variable for check existing of folder ,if require folder name is already exist
      then it is not create same name folder.
   c)We create 'Valuehire' name folder in outlook inbox and sub_folder named 'Failed'.
   d))Just follow the code-

 Public Sub CreateOutlookDirectories()
        Dim objOutlook As New Outlook.Application
        Dim objNS As Outlook.NameSpace = objOutlook.GetNamespace("MAPI")
        Dim objInboxFolder As Outlook.MAPIFolder = Nothing
        Dim objXYZFolder As Outlook.MAPIFolder = Nothing
        Dim objTransferredFolder As Outlook.MAPIFolder = Nothing
        Dim objFailedFolder As Outlook.MAPIFolder = Nothing
        Dim xyzExistsFlag As Boolean = False
        Dim FailedExistsFlag As Boolean = False

        objInboxFolder = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)

        If objInboxFolder.Folders.Count > 0 Then

            For i = 1 To objInboxFolder.Folders.Count
                If objInboxFolder.Folders.Item(i).Name = "Valuehire" Then
                    xyzExistsFlag = True
                    objXYZFolder = objInboxFolder.Folders("Valuehire")
                End If
            Next
            If xyzExistsFlag = True Then
                If objXYZFolder.Folders.Count > 0 Then

                    For j = 1 To objXYZFolder.Folders.Count
                        If objXYZFolder.Folders.Item(j).Name = "Failed" Then
                            FailedExistsFlag = True
                        End If
                    Next
                    If FailedExistsFlag = False Then
                        objFailedFolder = objXYZFolder.Folders.Add("Failed", Outlook.OlDefaultFolders.olFolderInbox)
                    End If

                Else
                    objFailedFolder = objXYZFolder.Folders.Add("Failed", Outlook.OlDefaultFolders.olFolderInbox)
                End If

            Else
                objXYZFolder = objInboxFolder.Folders.Add("Valuehire", Outlook.OlDefaultFolders.olFolderInbox)
                objFailedFolder = objXYZFolder.Folders.Add("Failed", Outlook.OlDefaultFolders.olFolderInbox)
            End If
        Else
            objXYZFolder = objInboxFolder.Folders.Add("Valuehire", Outlook.OlDefaultFolders.olFolderInbox)
            objFailedFolder = objXYZFolder.Folders.Add("Failed", Outlook.OlDefaultFolders.olFolderInbox)
        End If

    End Sub 

4.Call the function in 'ThisAddIn_Startup()' 
     
   Private Sub ThisAddIn_Startup() Handles Me.Startup
          CreateOutlookDirectories()
   End Sub

and run the program and see the result-


Create And Delete A Direcotry From Local System

Programmatically  Create And Delete A Directory From Local System -

Here i describe about how to create and delete a folder/directory to your computer, there is
many way to do this,but i share only one way-

I take a wpf programming for this,you can make this also in different window form -
1.we take two buttons for one is create and second is for delete.
2.write the code in respected buttons ,shown as in image.

3.After run the  program ,you see the massage box ans also check the directory  which you give in program as path for verification of  the code,run or not!!!!
                  

Friday, 19 April 2013

Input Output In VB.Net

                            Work With Input Output In VB.Net Application

When we are work with input output console during the programming, then we decide that what 
kind of input and output to be use.There is two main statement,firstly input is given order or 
command to system to do and output is result to user of given the input statement. Here both 
software and hardware input/output is present which we in our program.
                                                          In application sometime it need to store data and read the
data, according to application we select appropriate Input/Output. Below the image is  show 
different types of input/output. 

Thursday, 18 April 2013

Check Application Expiry Date

                               Check And Set Expiry Date For Application

Every client asking for assigning expiry date for his application because of security policy and
protection scheme,programmer have different way to do this.
        1.Use a two-way hash to store the initial date and compare that to the present date. 
           You can save the hash to disk.
        2.Use the registry key of current user and set the key value at installation time and compare
           to change the value in particular Date. 
        3.Use the created date of your installation files as a reference.
        4.Create a license key that encodes the expiry date into the key and read this when the
           application runs.

Well here i write a small code for checking expire date to the application,with the help of Date and
Registry feature- 
Imports Microsoft.Win32
Imports System.IO.Directory
Imports Microsoft.VisualBasic.DateAndTime
Public Class ThisWorkbook

    Private Function checkExpired()
        Dim RS232RegKey As RegistryKey
        Dim pluginExpired As Boolean = False
         If Year(Now) > 2013 Or Year(Now) < 2013 Then
             pluginExpired = True
         End If
         If Month(Now) > 4 Or Month(Now) < 4 Then
             pluginExpired = True
         End If
        If Day(Now) > 16 Or Day(Now) < 13 Then
             pluginExpired = True
         End If

        RS232RegKey = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Office\Excel\Addins\RS232")
        RS232RegKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Office\Excel\Addins\RS232", True)

         If RS232RegKey.GetValue("PluginExpired") Is Nothing Then
             RS232RegKey.SetValue("PluginExpired", 1, RegistryValueKind.DWord)
         End If
         If pluginExpired = True Then
             RS232RegKey.SetValue("PluginExpired", 0, RegistryValueKind.DWord)
         End If

        Dim PluginExpiredRegVal As Integer = RS232RegKey.GetValue("PluginExpired")
        RS232RegKey.Close()

         If pluginExpired = True Or PluginExpiredRegVal = 0 Then
             MsgBox("Plugin Expired")
             Return True
         End If
         Return False
    End Function

    Private Sub ThisWorkbook_Startup() Handles Me.Startup
        Globals.Sheet2.ButtonStop.Enabled = False
        If (checkExpired()) Then
            Globals.ThisWorkbook.Save()
            Globals.ThisWorkbook.Close()
        End If
    End Sub    

End Class

Accessing The Registry Key With VB.Net.


Introduction Of Registry Key
 Programmer/We have always found the windows registry to be a suitable place for storing
 application specific information and configuration settings. Traditionally, the registry has
 been used for storing configuration information like database connection strings,text, profiles
 etc. The popularity of the registry can be attributed to the fact that registry access is faster
 than file access and also because it is a very secure system-wide data repository.For creating
 a registry key, the 'RegistryKey' key world is used, this registry key is present in Win32 package.

Prerequisites for work with registry-
1.Familiarity with previous versions of Visual Basic.
2.Knowledge of the design and purpose of the registry
3.Understanding of the security implications of accessing the registry.

Use the Vb function for accessing Registry Key-

Create a new registry-
My.Computer.Registry.CurrentUser.CreateSubKey("TestKey")
This line will create a key in the HKEY_CURRENT_USER hive and will be named "Testkey".
For the value we'll need three things: Value path, Value name and value value Visual Basic will try
to assign the value type depending on the object type.
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\TestKey", "TestValue", "This
 is a test value.")

Read the value from registry key-
Dim readValue As String
readValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\TestKey", 
"TestValue", Nothing)
MsgBox("The value is " & readValue)

Delete the registry and registry's value-
My.Computer.Registry.CurrentUser.DeleteSubKey("TestKey")
Delete the Value-
readValue.DeleteValue("Testvalue") {readValue is define just above}

Change the registry value-
readValue.SetValue("TestValue", RegValue, RegistryValueKind.String)
readValue.SetValue("name of key value",give the value,value type)

Count the number of KeysValue and subKey in hive-
My.Computer.Registry.CurrentUser.ValueCount.ToString()
For subKey-
My.Computer.Registry.CurrentUser.SubKeyCount.ToString()

Check if a value exist-
If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\TestKey",
"TestValue", Nothing) Is Nothing Then
MsgBox("Value does not exist.")
Else
MsgBox("Value exist.")
End If

Now Write Here A Small Program for Create Registry-

I create a small application for outlook,here is small part off that module-
Imports Microsoft.Office.Interop.Outlook
Imports Microsoft.Office.Tools.Outlook
Imports System.IO
Imports System.IO.Directory
Imports Microsoft.Win32

Private Sub SettingsForm_Load(ByVal sender As System.Object, 
                                                ByVal e As System.EventArgs) Handles MyBase.Load
        Dim TestRegKey As RegistryKey
        Dim AccountRegVal As String
        Dim EmailRegVal As String
        Dim PasswordRegVal As String
        AccountRegVal = AccountTextBox.Text.ToString
        EmailRegVal = EmailTextBox.Text.ToString
        PasswordRegVal = PasswordTextBox.Text.ToString
        TestRegKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Office\Outlook
                                \Addins\TestValue", True)
       TestRegKey.SetValue("Account", AccountRegVal, RegistryValueKind.String)
       TestRegKey.SetValue("Email", EmailRegVal, RegistryValueKind.String)
       TestRegKey.SetValue("Password", PasswordRegVal, RegistryValueKind.String)
       TestRegKey.Close()
       MsgBox(" Connection Saved")

End Sub




Serial Port In VB.net

                                            Operation On Serial Port 

We use the serial port for communication with the hardware,like parallel port,printer port is the easiest available hardware for communicate with home made hardware devices.Here i explain the how we connect to port in vb.net and illustrate the data transmission.
                                                                Now at this time or new versions laptop,Pc, may have not serial port ,so you can not use this feature with them. Here I also give a small examples for syntax.

Open the serial port present in your computer,it's name was like COM1, COM2, COM3 bydefault .If prot is not present then we have to create a new port-
Dim comPort As SerialPort
       comPort = My.Computer.Ports.OpenSerialPort("COM5", 9600)
Here COM5 is open and 9600 is it's BaudRate, which is present in your system.

Create a  port ,in case if any port not present-
Dim comPort As SerialPort
comPort=New SerialPort("COM##", ...)
This is create a new port with name and other properties.

Write on port with check whether the port is open or not-
    Dim message As String = "hello"
    If comPort.IsOpen Then          
          comPort.WriteLine(message)
          comPort.Close()
     Else
        comPort.Open
        comPort.WriteLine(message)
        comPort.Close()
    End If

Read the data from port-
Dim msg As String = comPort.ReadLine()
            Console.WriteLine(msg) Or
            MsgBox(msg)

Close the serial port-
 comPort.Close()

Here i write the simple program for serial port-
 Imports System.IO.Ports
    Dim name As String 
    Dim message As String 
   
    ' Create a new SerialPort object with default settings.
    comPort = New SerialPort()

    ' Allow the user to set the appropriate properties.
    comPort.PortName = SetPortName(comPort.PortName) Or
    Dim comPort As New SerialPort("COM1")
    comPort.BaudRate = SetPortBaudRate(comPort.BaudRate)
    comPort.Parity = SetPortParity(comPort.Parity)
    comPort.DataBits = SetPortDataBits(comPort.DataBits)
    
    ' Set the read/write timeouts
    comPort.ReadTimeout = 500
    comPort.WriteTimeout = 500

   Dim message As String = "hello"
   Try 
        If comPort.IsOpen Then          
              comPort.WriteLine(message)          
        Else
              comPort.Open
              comPort.WriteLine(message)     
        End If  

       comPort.Close()       
            Catch ex As TimeoutException   
            MsgBox(ex)
            Catch ex1 As IOException       
            MsgBox(ex1)
        End Try 
    
End Sub


Wednesday, 17 April 2013

Difference Between .Net And COM Components

What is COM Component-
Microsoft COM(Component Object Model) this is technology of Microsoft operation system,enables the software to communicate.Microsoft provides COM interfaces for many Windows application programming interfaces such as Direct Show, Media Foundation, Packaging API, Windows Animation Manager, Windows Portable Devices, and Microsoft Active Directory (AD).


What is .Net Component-
This is standards-based framework for creating data-oriented applications shared across multiple applications and platforms. The separation of presentation, data, and business logic used in concert with a single data model will enable developers to spend less time writing plumbing code and more time refining business logic. 
                                                     .Net enable Data Driven development,since ASP.Net takes care of creating the presentation layer, a fully functional Website is output and ready for customization without the developer writing a single line of code.

Some Major Difference Are-
  • Both are compile  dll files.Net DLLs (called Assemblies) are run using the Common Language Runtime, a virtual machine that looks after certain things such as Memory management, threads, garbage collection and security as the code is running.
  • .NET Assemblies do not necessarily need to be 'registered', wheres COM DLL's need to be registered in the computer's registry.
  • .NET comes with a whole framework of objects that can be built on, used, or extended to achieve various tasks. The framework is much more comprehensive than the COM libraries that came with the old Visual Studio packages.
Examples For Both ,Which I Use And Know-

     Microsoft has used COM for tecnologies from the 90's: OLE, ActiveX, DirectX, etc.
     These technologies are still being developed with COM.

     However, new modern technologies are using .NET: Windows Presentation Foundation 
     (WPF), Windows Communitation Foundation (WCF), lots of research projects.