Top Banner

of 18

VB Notes for Internal

Apr 05, 2018

Download

Documents

Abhishek Kumar
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 7/31/2019 VB Notes for Internal

    1/18

  • 7/31/2019 VB Notes for Internal

    2/18

    Programs that use ODBC databases will have at least a CDatabase object and a CRecordset object.

    CDatabaseEncapsulates a connection to a data source, through which you can operate on the data source.

    CRecordset

    Encapsulates a set of records selected from a data source. Recordsets enable scrolling from record to recor

    updating records (adding, editing, and deleting records), qualifying the selection with a filter, sorting the selectioand parameterizing the selection with information obtained or calculated at run time.

    CRecordView

    Provides a form view directly connected to a recordset object. The dialog data exchange (DDX) mechanisexchanges data between the recordset and the controls of the record view. Like all form views, a record view

    based on a dialog template resource. Record views also support moving from record to record in the records

    updating records, and closing the associated recordset when the record view closes.CDBException

    An exception resulting from failures in data access processing. This class serves the same purpose as oth

    exception classes in the exception-handling mechanism of the class library.

    CFieldExchangeSupplies context information to support record field exchange (RFX), which exchanges data between the field da

    members and parameter data members of a recordset object and the corresponding table columns on the da

    source. Analogous to class CDataExchange, which is used similarly for dialog data exchange (DDX).

    ActiveXActiveX is an open integration platform that provides developers, users, and Web producers a faand easy way to create integrated programs and content for the Internet and Intranets. UsinActiveX, you can easily insert multimedia effects, interactive objects, and sophisticated programinto a Web page, creating a user experience comparable to that of high quality multimedia CD-ROtitles.ActiveX is a standard that enables software components to interact with one another in a networkeenvironment, regardless of the language(s) used to create them. Most World Wide Web (WWWusers will experience ActiveX technology in the form of ActiveX controls, ActiveX documents, anActiveX scripts.

    ActiveX ControlsActiveX controls, formerly known as OLE controls or OCX controls, are components (or objects) that you can insert

    into a Web page or other program so that you can reuse packaged functionality that someone else programmed. Forexample, the ActiveX controls that are included with Internet Explorer enable you to enhance your Web pages with

    sophisticated formatting features and animation.

    A key advantage of ActiveX controls over Java programs and Netscape plug-ins is that ActiveX controls can also be used

    in programs written in many programming languages, including all of the Microsoft programming and database language

    Creating an ActiveX ControlSimply follow these steps in order to create an ActiveX control.

    A)Using the AppWizard to create an ActiveX Control project

    1. SelectNew fromFile menu

    2. Click the Projects tab and select the type of project as MFC ActiveX Control Wizard from the list.3. Name of new project Plot and then click the OKbutton.

    4. Take all the defaults values of the next dialog (titled MFC ActiveX Control Wizard - Step 1 of 2) and clicktheNextbutton5. From the next dialog (titled MFC ActiveX Control Wizard - Step 2 of 2), locate the combo box with the

    prompt Which window class, if any, should this control subclass?. Drop down the list and select the entry STATIC

    from that list. We're using a static control in this example since we'll just be displaying data (and not acceptinginput).

    6. Click onAdvancedbutton and check theFlicker free activation checkbox.

    7. Now click theFinish button. At this point, the AppWizard will generate the following three classes on you

    behalf.B) Adding "Stock" properties

    The termstock properties means that its one of a set of common properties that MFC code stores and initializes fo

    you. The MFC code also performs appropriate action when the value of a stock property is changed. TheClassWizard provides code for changing nine (9) such properties. Since these properties are built-in, they are

    http://msdn.microsoft.com/en-us/library/2dhc1abk.aspxhttp://msdn.microsoft.com/en-us/library/92bcy0kw.aspxhttp://msdn.microsoft.com/en-us/library/133zc1xb.aspxhttp://msdn.microsoft.com/en-us/library/y1te2ehx.aspxhttp://msdn.microsoft.com/en-us/library/cbk638tb.aspxhttp://msdn.microsoft.com/en-us/library/hbdyk609.aspxhttp://msdn.microsoft.com/en-us/library/hbdyk609.aspxhttp://msdn.microsoft.com/en-us/library/92bcy0kw.aspxhttp://msdn.microsoft.com/en-us/library/133zc1xb.aspxhttp://msdn.microsoft.com/en-us/library/y1te2ehx.aspxhttp://msdn.microsoft.com/en-us/library/cbk638tb.aspxhttp://msdn.microsoft.com/en-us/library/hbdyk609.aspxhttp://msdn.microsoft.com/en-us/library/2dhc1abk.aspx
  • 7/31/2019 VB Notes for Internal

    3/18

    obviously the easiest to deal with in terms of the work required by the developer. As you'll see shortly, you literal

    don't add a single line of code to add stock property to your control!

    The ClassWizard provides code for the following stock properties:

    Appearance BackColor ForeColor BorderStyle Font Caption Enable Text hWnd

    From these, we will work with the Appearance, BackColor, ForeColor and BorderStyle properties.

    C) Adding Custom PropertiesCustom properties are properties you devise yourself for your control. For the plot control I have added only four customproperties "Grid On/Off" and "X-Log". The grid properties will control the visibility of the control grid. The "x-log"

    property will be used to plot the horizontal axis in the logarithmic scale.

    DLL

    Dynamic-link library (also written without the hyphen), or DLL, is Microsoft's implementation of the shar

    library concept in the Microsoft Windows and OS/2 operating systems. These libraries usually have the fextensionDLL, OCX (for libraries containing ActiveX controls), orDRV (for legacy system drivers). The file forma

    for DLLs are the same as for Windows EXE files that is, Portable Executable (PE) for32-bit and 64-b

    Windows, and New Executable (NE) for 16-bit Windows. As with EXEs, DLLs can contain code, data, aresources, in any combination.

    In the broader sense of the term, any datafilewith the same file format can be called a resource DLL. Examples such DLLs includeicon libraries, sometimes having the extension ICL, andfont files, having the extensions F

    and FOT.

    Features:

    Since DLLs are essentially the same as EXEs, the choice of which to produce as part of the linking process is fclarity, since it is possible to export functions and data from either.

    It is not possible to directly execute a DLL, since it requires an EXE for the operating system to load it through a

    entry point, hence the existence of utilities of rundll which provide the entry point and minimal framework f

    DLLs that contain enough functionality to execute without much support.DLLs provide a mechanism for shared code and data, allowing a developer of shared code/data to upgra

    functionality without requiring applications to be re-linked or re-compiled. From the application development poi

    of view Windows and OS/2 can be thought of as a collection of DLLs that are upgraded, allowing applications fone version of the OS to work in a later one, provided that the OS vendor has ensured that the interfaces an

    functionality are compatible.

    DLLs execute in the memory space of the calling process and with the same access permissions which means theis little overhead in their use but also that there is no protection for the calling EXE if the DLL has any sort of bug

    Dynamic linking has the following advantages:

    Saves memory and reduces swapping. Many processes can use a single DLL simultaneously, sharin

    a single copy of the DLL in memory. In contrast, Windows must load a copy of the library code into memory feach application that is built with a static link library.

    Saves disk space. Many applications can share a single copy of the DLL on disk. In contrast, ea

    application built with a static link library has the library code linked into its executable image as a separate copy.

    Upgrades to the DLL are easier. When the functions in a DLL change, the applications that use thedo not need to be recompiled or relinked as long as the function arguments and return values do not change.

    contrast, statically linked object code requires that the application be relinked when the functions change.

    Provides after-market support. For example, a display driver DLL can be modified to support

    display that was not available when the application was shipped.

    Supports multilanguage programs. Programs written in different programming languages can call thsame DLL function as long as the programs follow the function's calling convention. The programs and the DL

    function must be compatible in the following ways: the order in which the function expects its arguments to b

    pushed onto the stack, whether the function or the application is responsible for cleaning up the stack, and wheth

    any arguments are passed in registers.

    Provides a mechanism to extend the MFC library classes. You can derive classes from the existin

    MFC classes and place them in an MFC extension DLL for use by MFC applications.

    http://en.wikipedia.org/wiki/Microsofthttp://en.wikipedia.org/wiki/Microsofthttp://en.wikipedia.org/wiki/Shared_libraryhttp://en.wikipedia.org/wiki/Shared_libraryhttp://en.wikipedia.org/wiki/Microsoft_Windowshttp://en.wikipedia.org/wiki/OS/2http://en.wikipedia.org/wiki/OS/2http://en.wikipedia.org/wiki/Operating_systemhttp://en.wikipedia.org/wiki/File_extensionhttp://en.wikipedia.org/wiki/File_extensionhttp://en.wikipedia.org/wiki/ActiveXhttp://en.wikipedia.org/wiki/Device_driverhttp://en.wikipedia.org/wiki/EXEhttp://en.wikipedia.org/wiki/EXEhttp://en.wikipedia.org/wiki/Portable_Executablehttp://en.wikipedia.org/wiki/32-bithttp://en.wikipedia.org/wiki/32-bithttp://en.wikipedia.org/wiki/64-bithttp://en.wikipedia.org/wiki/New_Executablehttp://en.wikipedia.org/wiki/16-bithttp://en.wikipedia.org/wiki/Machine_codehttp://en.wikipedia.org/wiki/Data_(computing)http://en.wikipedia.org/wiki/Resource_(Windows)http://en.wikipedia.org/wiki/Computer_filehttp://en.wikipedia.org/wiki/Computer_filehttp://en.wikipedia.org/wiki/Computer_filehttp://en.wikipedia.org/wiki/File_formathttp://en.wikipedia.org/wiki/Icon_(computing)http://en.wikipedia.org/wiki/Icon_(computing)http://en.wikipedia.org/wiki/Typefacehttp://en.wikipedia.org/wiki/Typefacehttp://en.wikipedia.org/wiki/Microsofthttp://en.wikipedia.org/wiki/Shared_libraryhttp://en.wikipedia.org/wiki/Shared_libraryhttp://en.wikipedia.org/wiki/Microsoft_Windowshttp://en.wikipedia.org/wiki/OS/2http://en.wikipedia.org/wiki/Operating_systemhttp://en.wikipedia.org/wiki/File_extensionhttp://en.wikipedia.org/wiki/File_extensionhttp://en.wikipedia.org/wiki/ActiveXhttp://en.wikipedia.org/wiki/Device_driverhttp://en.wikipedia.org/wiki/EXEhttp://en.wikipedia.org/wiki/Portable_Executablehttp://en.wikipedia.org/wiki/32-bithttp://en.wikipedia.org/wiki/64-bithttp://en.wikipedia.org/wiki/New_Executablehttp://en.wikipedia.org/wiki/16-bithttp://en.wikipedia.org/wiki/Machine_codehttp://en.wikipedia.org/wiki/Data_(computing)http://en.wikipedia.org/wiki/Resource_(Windows)http://en.wikipedia.org/wiki/Computer_filehttp://en.wikipedia.org/wiki/File_formathttp://en.wikipedia.org/wiki/Icon_(computing)http://en.wikipedia.org/wiki/Typeface
  • 7/31/2019 VB Notes for Internal

    4/18

    Eases the creation of international versions. By placing resources in a DLL, it is much easier

    create international versions of an application. You can place the strings for each language version of yoapplication in a separate resource DLL and have the different language versions load the appropriate resources.

    A potential disadvantage to using DLLs is that the application is not self-contained; it depends on the existence of

    separate DLL module.

    Diff Between ActivxEXE and ActivexDLL

    Activex DLL

    It runs within the main program address space. So calling method is fast. It is easy to test.Activex EXE

    This runs in a in a separate process. this is useful for creating components that can run as stand-alone, that is they

    can be run by clicking on the icon. This is similar to Excel: you can click on the Excel icon and launch Excel oryou can create an Excel object from VB.Dlls are in-process components. They run in the same memory as the calling application and hance are faster. Dlls apreferred if they exist on the same machine.

    Exes are out-process components. They run in a separate memory location.When a method/function is called from an ex

    the parameters and also the result of the method/function have to cross the network boundries through marshalling a

    hence are slower.For remote access Exes are the choice.active dll is fast

    active exe is slow

    ActivexDLL is executes in in process

    ActivexExe executes in outprocess

    Windows Form Properties

    EventAn event procedure is an independent group of commands that is executed whenever an event occurs during

    program execution. Typically, an event occurs when the user takes some action, such as clicking on a control

    icon, or dragging an icon to another location. Many (though not all) Visual Basic controls have event procedures

  • 7/31/2019 VB Notes for Internal

    5/18

    associated with them.

    Each event procedure begins with a Sub statement, such as Private Sub Command1_Click(), and

    ends with an End Sub statement. Between the Sub and End Sub statements is a group of instructions, such as

    those discussed in the last two chapters, that are executed when the user initiates the corresponding event. The

    parentheses in the Sub statement may contain arguments special variables that are used to transfer information

    between the event procedure and the calling routine (see Chap. 7 for more information on this topic).

    Command buttons are often used to execute Visual Basic event procedures. Thus, when the user clicks on

    a command button during program execution, the statements within the corresponding event procedure are carried

    out. The statements within the event procedure may involve the properties of controls other than the command

    button. For example, a command-button event procedure may result in new values being assigned to theproperties of a label or a text box.

    A typical event procedure is shown below:

    Private Sub Command1_Click()

    Label1.Caption = "Hello, " & Text1.Text & "! Welcome to Visual Basic."

    Label1.BorderStyle = 1

    Label1.Visible = True

    End Sub

    From the first line (i.e., the Sub statement), we see that this event procedure is associated with command butt

    Command1, and it is a response to a click-type event. The three assignment statements within the event procedure will

    executed whenever the user clicks the mouse on command button Command1 during program execution.

    ODBC vs OLE DB

    ODBC is Open Data Base Connectivity, which is a connection method to data sources and other things. It requires that y

    set up a data source, or what's called a DSN using an SQL driver or other driver if connecting to other database types. Mo

    database systems support ODBC.

    OLE is Object Linking and Embedding. OLEDB is partly distinguished from OLE itself, now called "automation".

    OLEDB is the successor to ODBC, a set of software components that allow a "front end" such as GUI based on VB, C+

    Access or whatever to connect with a back end such as SQL Server, Oracle, DB2, mySQL etal. In many cases the OLED

    components offer much better performance than the older ODBC.

    OLEDB is a different type of data provider that came about with MS's Universal Data Access in 1996 and does not requ

    that you set up a DSN. It is commonly used when building VB apps and is closely tied to ADO. It works with COM, an

    DCOM as of SQL 7.0.

  • 7/31/2019 VB Notes for Internal

    6/18

  • 7/31/2019 VB Notes for Internal

    7/18

    Procedures

  • 7/31/2019 VB Notes for Internal

    8/18

  • 7/31/2019 VB Notes for Internal

    9/18

  • 7/31/2019 VB Notes for Internal

    10/18

  • 7/31/2019 VB Notes for Internal

    11/18

  • 7/31/2019 VB Notes for Internal

    12/18

  • 7/31/2019 VB Notes for Internal

    13/18

  • 7/31/2019 VB Notes for Internal

    14/18

  • 7/31/2019 VB Notes for Internal

    15/18

  • 7/31/2019 VB Notes for Internal

    16/18

  • 7/31/2019 VB Notes for Internal

    17/18

  • 7/31/2019 VB Notes for Internal

    18/18