Tuesday, 23 April 2013

Setting Intervals Using Timer

                                                Setting Interval Through The Timer

Mostly timer is use for set the time for appropriate action in our application.I am make a 
small application that set the interval for to do something.
1)Open the VS any version, create a new project,or and new form in existing project in
    your computer.
2) Add new window form -
     Right click on project--> Click Add-->New Item-->Open new dialog box-->
     select Window form
3)After add the form  in project 
4)Design the form like that,see only red in circle-
5)Put the code inside the Check Box and Timer.
6)Here I call the function in timer,which is execute within the interval.
      Public Sub ShivFunction()
          MsgBox("file is downloaded")
      End Sub 



Office Ribbon Design Elements

Office Ribbon Design Element With VS 2010-

Here I describe about some feature and properties of ribbon design in office,in project it
can hold project on excel,word,power point,outlook,choose any one of the as you want.
Ribbon is use for add new tab in office,contain different type tools. In this blog i explore
feature with the outlook.So when we open the VS 2010 ,just follow the instruction -

   1)If you don't know how to open the outlook project then follow this  link.
   2)Here i give the  project name as 'SampleOutlookAddIn' .

   3)Right click on the project-->select Add-->New Item-->Open new dialog box.
   4)You have two type ribbon,Ribbon(visual designer) and Ribbon(XML),you can choose
      any one, just like i choose Ribbon(visual designer) here,give the name and click Add.

   5)Go to ribbon property--> ribbon type--> select 'Microsoft.Outlook.Explorer'.

   6)Drag-drop the tools in ribbon as shown in image.
      In image i show the ribbon contain Group,and group contain Box, box hold button and
      checkbox.You can change the name of 'AddIn' from property.
7)If You want to add custom type tab then go to property of tab and change it to 'custom'.


Now,here introduce some tools,used in ribbon
    a)Ribbon- Ribbon is hold the all tools like buttons,groups,checkbox,textbox etc.Used
       for built simple tab and custom tab.
    b)Tab-In ribbon we can add one or more  tab(simple tab and custom tab).
    c)Group- After the ribbon 'group' is an important element for collection of tools,and group is 
       contained by ribbon.
    d)Button-Button is like a simple button as in other application.
    e)Separator-This is use for separate and provide a some space ,give a line between two or
       more tools.
    f)Toggle Button-This is use for one time click,like a work as on/off, active/inactive
      able/enable act.
   g)Split Button- Button is Spite in two part one is for selection/clicking and other is see the list 
      own feature it may be collect a  buttons,checkbox etc.
   h)Button Group- This contain the buttons or it maintain the group of button/checkbox,but here 
      only one button/checkbox work at a time.
   j)Combo/Dropdown/Textbox, Checkbox/Level-Works same as visual basic tools. 

8)After run this project open outlook,  it look like-


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.

  

Monday, 15 April 2013

MultiThreading With Delegate Feature

Use MultiThreading With Delegate Feature :

Defination of Delegate:-

In this post i discuss about Delegate feature in vb.net, You know the function pointer in 
C,C++,Java.The function pointer is refer some other function, it hold a address of function. 
Here i compare delegate to this(function pointer),delegates are object-oriented, type-safe, 
and secured. In short, a delegate is a data structure that refers to a static method or to an
object instance, and an instance method of that object. When the delegate references an
instance method, it stores not only a reference to the method entry point, but also a 
reference to the object instance for which to invoke the method.

Some property of delegate:-

  1. Declaration Delegate is like a normal Procedure/Method in VB.NET which accepts a parameter but doesn’t return Sub in case of a Sub method and type in case of a Function.
  2. Delegate does not return any type value. Technically, a Sub delegate returns a Sub pointer but for now, keep in mind, they do not return any value.
  3. Delegates have only declaration, they do not have any body.

Description:-

  1) Delegate accept only parameter according to your program.such as like i pass the on
      string parameter  see the point 1 in picture how to define(here i create delegate name 
      as myCallBack,myCallBack1 ) and pass the parameter.

  2)Once we assign an address to a delegate, we can use the Invoke method to call the 
     function encapsulated in the delegate,see the point 2,3,firstly system check the program
     that it need Invoke or not, if it require  then write InvokeRequired key world.
  
     Here, in this function mysubsub and mysubsub1, we have pass the integer parameter.
     Now you can pass class, object, multiple parameters and even param Arrays as parameter.
     So, nothing is new here.

  3)In point 4,5 create a thread and start thread, holding address of Mysub,Mysub1 
    respectively, and Mysub call delegate method containing integer parameter.  To create 
    this program and understand more in brief  follow this link.  

 

MultiThreading 2

Here We Discuss About Two Threads Associate With Function:-

Here we take:-
1)open window form in with new project in VS.
1)Take two buttons and two level,See in figure:-

Put this code in place of given events:-

Public Class Form3

    Public Sub setText()
        For i = 0 To 50
            Label1.Text = i.ToString
            Threading.Thread.Sleep(100)
        Next i
    End Sub

    Public Sub Mysub()
        setText()
    End Sub

    Public Sub Mysub1()
        For i = 0 To 50
            Label2.Text = i.ToString
            Threading.Thread.Sleep(100)
        Next i
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Mysub()       
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Mysub1()       
    End Sub

    Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        CheckForIllegalCrossThreadCalls = False
    End Sub

End Class

In this code ,we find at run time :-

a)if you click on button1 ,then you can  able to move window and click on button2.
b)you must be wait for completion of  execution of buttone1's function.
c) we can not able to do anther work parallely.

Then after we add some line of code of thread in our above program:-

        Dim MyThread As New System.Threading.Thread(AddressOf Mysub1)
        MyThread.Start()
And remove/comment out  'Mysub() then See the complete code with additional code:-

Public Class Form3

    Public Sub setText()
        For i = 0 To 50
            Label1.Text = i.ToString
            Threading.Thread.Sleep(100)
        Next i
    End Sub

    Public Sub Mysub()
        setText()
    End Sub

    Public Sub Mysub1()
        For i = 0 To 50
            Label2.Text = i.ToString
            Threading.Thread.Sleep(100)
        Next i
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        'Mysub()
        Dim MyThread As New System.Threading.Thread(AddressOf Mysub)
        MyThread.Start()
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        'Mysub1()
        Dim MyThread As New System.Threading.Thread(AddressOf Mysub1)
        MyThread.Start()
    End Sub

    Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        CheckForIllegalCrossThreadCalls = False
    End Sub
End Class

We find both the buttons work parallely and also we can able drag drop window :-


One Important part of this code,we need to check a cross-thread operation,which is occur due to two or more thread run exclusively.for this we write this line in Form3_Load event
 CheckForIllegalCrossThreadCalls = False

If we not  write this code it generate error shown in figure:-


Conclusion 
Multi-threading is necessary for work with multi task  operation. 

MultiThreading1

MultiThreading Of Functions:-

MultiThreading is very useful feature for program which is secure from, waiting for completion of one program or function to start second function. We can say that it is allow to work parallely with two or more function.

Let us we take a small example, here two buttons in form1 ,contain saperate functions.

In Button1 if we comment this line :-
        'Dim MyThread As New System.Threading.Thread(AddressOf Mysub)
        'MyThread.Start()
After run this project  we are not able to click  on button2 and on window ,for this we have to wait until completion of 'Mysub()' function. 

If We are comment the  'Mysub()' function and comment out this code:-
        'Dim MyThread As New System.Threading.Thread(AddressOf Mysub)
        'MyThread.Start()
See, we can move window ,able two run Button2.

Similarly we can do same we Button2.


Public Class Form1

    Public Sub Mysub()
        MsgBox("Sub")
    End Sub

    Public Sub Mysub1()
        MsgBox("Sub1")
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Mysub()
        'Dim MyThread As New System.Threading.Thread(AddressOf Mysub)
        'MyThread.Start()
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Mysub1()
        'Dim MyThread As New System.Threading.Thread(AddressOf Mysub1)
        'MyThread.Start()
    End Sub

End Class