Sie sind auf Seite 1von 10

Intro to VB, .NET & VS A.

Introduction to programming Introduction, features and versions of VB

a.

Programming is problem solving: It has following four steps:

1. 2.
algorithm)

Understanding Problem (Problem Identification) Devising a plan to solve that problem (devising, refining and testing the

3. 4. b. i.
dependent)

Carrying out the plan to solve that problem (translating the code into program

using programming language) Evaluating the solution (testing and debugging the program)

History and Generations of PLs: Machine Language (binary code for all instructions and data, machine

ii.
etc).

Assembly Language (English like abbreviations (mnemonics) instead

of binary instructions, machine dependent, needs assemblers like MASM, TASM, EMU, A56,

iii.

High Level Language (assembly langs. require lots of instructions for a

task, which is done by a single statement in HLLs. machine-independent, needs compiler and interpreter. Interpreters are popular in program-development environments, so that developers can change programs frequently as they add new features, see the result and correct errors. Once a program is fully developed, a compiled version can be produced so that the program runs at maximum efficiency.)

iv.

Very High Level Language (easier but specialized, non-procedural,

usually related to manipulation of databases, examples: SQL, LISP (List Programming), ORACLE reports, SPSS, Mathematica, ABAP, etc).

v.

Natural Language (similar to 4GLs but free from a specific syntax or

vocabulary and very close to natural languages, a part of AI, generally related to solve a particular problem, examples are prolog, mercury). Historical Notes about VB Evolved from BASIC which was developed by Thomas Kurtz and John Kemeny in mid 1960s, become Visual in 1991 by Microsoft. Features of VB i. Visual Language Easy Access to Win-32 API (see in separate word file)

ii.

iii. iv. v. vi.


Versions of VB

Event handling, (u will come to know) Object-oriented programming (u will come to know) Exception handling (u will come to know) Visual Basic is the worlds most widely used RAD language.

vii. viii. ix.

Version 3: Support for Database through DAO. Version 5: Multimedia Support for Web through ActiveX Objects (which are basically scripts and are based on the specification Component Object Model. Version 6.0 (A new chain of technologies was introduced including integration of DAO and ActiveX objects i.e. ADO which supports database access through both desktop and web applications, while DAO could only support desktop applications and Active Server pages technology was also introduced).

x. xi.
B.

Visual Basic .NET VB 2005 Introduction to .Net Framework Introduced in 2000, .NET is a new vision for the development, engineering and use of software. It is basically an API (not win API). CLS is the blueprint (specification) of .NET framework. All .NET applications require .NET framework to be executed.

Problems or needs before .NET framework Enhancement and ease of use in library functions. Language interoperability Accessibility of software from almost any type of device. Accessibility from internet.

A new program-development process environment i.e. Visual Studio.NET.

Security, platform independence and memory management. Features of .NET Framework

Class Library (BCL & FCL) .NET framework is in the form of a set of standard class (OOP) libraries (with .dll extension). It is divided into BCL & FCL. BCL is the core set of classes that serve as the basic API like mscorlib.dll and system.dll and system.core.dll. BCL is present in .NET framework and all alternative implementations of .NET framework like Mono and Silverlight.

FCL refers to expanded set of object-oriented libraries including WinForms, ADO.NET, LINQ, Windows Presentation Foundation, etc, is much easier and larger(consisting of more than 20000 classes) than Win-API. It exposes everything that Windows do.

Namespaces: It is made up of hierarchy of namespaces, where a namespace is a logical groping of FCL. System namespace is at the root of this hierarchy. Other namespaces are System.Data and System.Web. A feature that Visual Studio provides is the Object Browser, which lists the Framework Class Library (FCL) classes available in Visual Basic with its namespace and assembly names and all its relations with other elements and its members.

Adding reference of a namespace: If however, you are adding a reference of user-defined namespace or a system namespace (starts with System or Microsoft); add the import statement in the code in addition of adding reference of the assembly (.dll file). Two namespaces can contain same class names. In that case fully qualified class names will be used that is class name with namespace name separated by period. In this way the use of namespaces reduce the chance of name collisions. Again default namespaces are already referenced in the current project like system namespace. Also notice that by default, a Visual Basic .NET project declares a root namespace that has the same name as the project. You can change the name of the root namespace in projects properties. We can also use aliases instead of namespace names. The nested namespace is a member of the enclosing namespace. However, the members of the nested namespace are not members of the enclosing namespace.

Assemblies: FCL is physically arranged in the form of assemblies. There is no one-to-one correspondence between assemblies and namespaces. For example, the System.Data.dll assembly actually implements some routines in both the System. Data and System.Xml namespaces, while other routines in the System.Xml namespace are implemented in the System.Xml.dll assembly. A namespace can be spread across source files and compiled to a single assembly.

Assembly is any executable code. It can be a whole program i.e. .exe or part of an executable program i.e. .dll file; an executable file that cant run on its own, it can only run from inside an executable file that can run itself (like .exe). Advantages of using .dll instead of .exe are that it doesnt consume any memory until it is called or used. Secondly, in this fashion they can be shared with other programs. There are two types of assemblies in .NET: private and shared. Shared assemblies must be loaded in global assembly cache before they can be used. The .NET System classes are all shared assemblies.

In .NET, the structure of an assembly is divided into these components: its manifest (like its name), its metadata (like details of the data types), the CIL and its resources (like images), if

any. These contents of an assembly can be viewed through an external Visual Studio tool ildasm, which can be added through tools-external menu into VS via C:\Program Files\Microsoft Visual Studio8 \ SDK \V2.0 \Bin can be set through Assemblyinfo.vb file. path. Different attributes of an assembly

Adding a reference of an assembly: In VS, you can add a reference of a user-defined class library i.e. an assembly by adding reference to the .dll file, produced by that class library in the current projects properties. And the reference of system class library can be given by import command followed by the namespace in which this class library exists, like this: import system.drawing. Many essential system class libraries are already referenced by default like console class in mscorlib namespace. Writeline is a method of console.

To get an array of Assembly objects representing the assemblies currently loaded into an application domain, use the AppDomain.GetAssemblies method in Namespace System.Reflection

Private and Shared Assemblies: Private assemblies must be in the same directory of the application, while shared assemblies are stored in a special .NET system directory called the Global Assembly Cache (GAC). You can view the contents of your global assembly cache by using Windows Explorer to navigate to the WINNT\assembly folder Because they are available system-wide, the .NET runtime imposes several extra checks on shared assemblies to ensure that they are valid for the program requesting them, such as security and version compatibility. Such an assembly is then called as strong named assembly. In order to create a shared assembly with a strong name, you must generate a public/private key pair that is used to sign an assembly. Public/private key cryptographic systems use a private key known only to the sender of an encoded message, and a public key published to the world. The .NET Framework provides a tool for generating the strong name called sn.exe (sn stands for Strong Name). Unfortunately, this can only be used from the command prompt. The steps are:

1. 2. 3.

Set the environment variables by running SDKVars.bat from command prompt which is located in the C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin directory. Then Use the following command to generate a key, giving a filename (usually with the .snk extension): sn -k superlib.snk This creates the key file superlib.snk in the current directory. To sign the assembly with this key, modify or enter the AssemblyKeyFile attribute in the last part of the AssemblyInfo.vb file for your project: [assembly:AssemblyKeyFile(C:\ProgramFiles\Microsoft VisualStudio8\SDK\v2.0\Bin\SuperLib.snk)]

4. 5.

Now, recompile the superlib.dll assembly. Once you have successfully rebuilt the project, the assembly is now signed. If we examine the manifest of the superlib.dll assembly now with ildasm, we see that a public key has been generated and embedded within.

6.

The final step is to copy the now strongly named assembly into the Global Assembly Cache. This can be done simply by dragging and dropping the file into the GAO folder (Windows\assembly). Alternatively, we can use a NET command-line tool called giacut.,i1 (Global Assembly Cache Utility) like this: gacutil /i superlib.dll.

DLL Hell and Side-by-Side Execution in the GAC: it is not unusual for users to reinstall software either during a system upgrade or to change configurations. In many cases users would install software that included an older version of a dll on a system that already contained a newer version of that dll in its registry. This would cause the more recently installed version to replace the newer version. As soon the user attempted to run the program that required the newer version, problems would occur. This is DLL Hell. But in .NET framework .dll files are fully self-describing; the description is contained within the assembly so the system or calling program does not have to look up information in the Registry or else where about the objects contained within the assembly. In this way the contents of an assembly cant be overwritten in the registry. Furthermore the process of naming of shared assemblies is also very strict. The unique combination of the assembly name, version, and key is called a strong name instead of just its name. The result is that there can be many different assemblies in the GAC that have the same filename. Although they have the same filename, they are different assemblies and coexist perfectly fine together in the GAC. This makes it easy for different applications to use different versions of the same dll at the same time, since they are different assemblies with different identities. This is called side-by-side execution.

Satellite assembly is used in localization process. Its presence in an application is optional and standalone and it does not contain any core functionality of the application. English and Japanese editions of the .NET Framework version share the same core files. The Japanese .NET Framework version adds satellite assemblies with localized resources in a ja subdirectory. we also have satellite assemblies containing no executable codeonly resources that are often used to deploy language-specific resources for an application. For creating and using them, create a folder with a specific culture name (for example, en-US) in the application's bin\debug folder. Then create a .resx file in that folder. Place all translated strings into it. Then use a tool called al.exe (Assembly Linker) from the .NET command prompt to link satellite assemblies. ResGen.exe is a tool that is used to convert resource files in the form of .txt or .resx files to common language runtime binary .resources files that can be compiled into satellite assemblies.

Delayed Signing: In large companies, due to security reasons, the final strong naming of an assembly is often performed at the very end of the development process, by a special group with access to the key pair. But this can cause problems, though, in the development and testing processes, for several reasons. First, since the public key is one of the components of an assemblys identity, it (assembly) cant be set until the public key is supplied. Further, a

weakly-named assembly cannot be deployed to the GAC. Both the developers and testers need to be able to compile and test the code in the way it will be deployed on release, including its identity and location in the GAC. To allow for this, there is a modified form of assigning a strong name, called delayed signing, or partial signing, that overcomes these problems, but without releasing access to the private key. To create a delay-signed assembly, you must do two things. First, create a copy of the key file that has only the public key, rather than the public/private key pair. Next, add an additional attribute called DelaySignAttribute to the assembly scope of the source code and set its value to true. To disables the GACs signature verification on this machine, for this assembly only, and allows it to be installed in the GAC issue the following command from the Visual Studio command prompt: snvr MyAssembly.dll.

Application isolation or domain feature of .NET Framework is the boundary within which an application runs. An application running inside one application domain cannot directly access the code running inside another application domain. AppDomains are usually created by hosts. Examples of hosts are the Windows, Shell, ASP.NET and IE. When you run a .NET application from the command-line, the host is the Shell. The Shell creates a new AppDomain for every application. AppDomains can also be explicitly created by .NET applications.

Second characteristic of .NET framework is its ability to interact with code written in a different language, called as language interoperability. Through Common Language Runtime (CLR), which compiles all the code, written in one or more .NET-compliant languages into an intermediate language called as MSIL, which is then converted into machine code. In order to be a .NET-compliant language, the language has to agree on minimum set of rules specified by .NET framework in Common Language Specification. The components behind CLR are:

i. ii. iii. a.

Common Type System, which ensures defining and usage of common (uniform) data type system. Uniform Metadata System, which ensures common ways for storage and retrieval of data types. It also handles memory management. An execution system which enables safe and secure Multilanguage program compilation and execution, which: First converts all source codes, written in one or more programming languages into an intermediate assembly language, called as MSIL, which is then converted in processorspecific execution format, known as Portable Executable.

b.

Then another compiler translates this Intermediate Language code into machine code. This is also known as JIT-compilation, as the code is translated on-need basis. This double compilation also makes an application portable.

Third characteristic of .NET framework is platform independence.

As far as Operating System is concerned, every OS has different subsystems like Memory system, I/O subsystem, etc. CLS has been submitted to for standardization to make it easier to create .NET framework for other OS. Mono is such example which is for Linux, Solaris and Mac Operating Systems. Mono is an open-source (code freely available at no cost). As far as machine or processor is concerned, .NET applications can be distributed to a number of devices like cell phones and a variety of computers. The technique behind providing this portability is again double compilation. MSIL isnt dependent on any processor, and can be easily converted into any native code. Fourth characteristic of .NET framework is the facility to create web services. These are services that can be used on internet by any other application. Fifth characteristic is to manage memory itself, like to allocate memory space and returning it. Sixth characteristic is enhanced security at different levels. In .NET environment applications are isolated from one another, in a sense that if one application crashes, it has no bad effects on other applications. There is another kind of interoperability, known as COM interoperability, which enables .NET applications to communicate with software components to add functionality, where COM is a specification developed by MS for building s/w components. It is also added that from marketing point of view, .NET vision is to ready its framework for any new platform launched, either in form of OS or device. The technique behind that .NET framework lies between the programming and execution layers, sop that if execution layer changes, programming layer remains same.

Comparison with Java: Javas mantra is one language, many platforms. .NET is many languages, one platform. Java doesnt support completely any thing. Java is slower as double compilation is required. Java has no academic value as no legacy language of its own. Syntax of Java is not familiar.

C.

Introduction to the Visual Studio 2005

VS is IDE for the development of .NET applications. 2003,05,08,10 are its different versions. Professional, standard and Ultimate are its different editions. We are using VS 2005 Professional. VS is based on Microsoft Solution Framework, a set of processes and models that, to some, is the standard for solution delivery in the IT industry.

The Visual Studio .Net IDE organizes programs into projects and solutions. A project is a group of related files, such as the Visual Basic code files, images and binary (compiled code) files that make up a program. A solution contains one or more projects. An application is a type of project like windows application or web application, etc.,

Many types of applications can be developed using VS. Application that we can make with VB 2005, in which the program compiles and runs under MS-visual studio .NET (i.e. under

windows but there is no drag and drop facility here) but the input / output operations are performed through console (which is DOS-based) is called as Console Application. The reason to build a console application is its simplicity. Its purpose is usually to test a specific feature of the language without having to build a user interface. Furthermore, a console application is more focused on the code. So one of its uses is in the learning process. Windows / Visual Program or Application is a program that utilizes Graphical User Interfaces (GUI) to select and drag visual components of a program.

VS has a number of windows. These windows can be arranged through its auto hide (a space-saving feature, when auto-hide is enabled, the pin icon has a horizontal orientation) and dock (moving windows around moving while holding the mouse button down) features. To simplify the management of the code window, the Outlining submenu contains commands that collapse and expand the various procedures. You can also save a particular setting of visual studio by the Import and Export Settings command in the tools menu. The Start Page contains Recent Projects, Visual Studio Developer News and Getting Started. The Solution Explorer window provides access to all the files in the solution. The Toolbox contains controls used to customize forms. The Properties window displays the properties for a form or control.

Some of Rapid application development features are: First is My feature, which provides access to information and default object instances that are related to the application and its run-time environment. For example, you can use the following statement to play back a WAV file from within your code: My.Computer.Audio.Play" ("C: \ Sounds \CountDorn.wav). Second RAD feature is a lot of predefined code snippets for selected actions. Select IntelliSense > Insert Snippet (or right-click somewhere on the code window and select Insert Snippet from the context menu). Third, the intellisence Complete Word feature enables you to complete the current word pressing Ctrl+spacebar. Fourth Edit and Continue feature is the ability to fix runtime errors on the fly. Fifth SmartTags provide access to information and common tasks without forcing you to constantly navigate away from your work area.

Dynamic help is an excellent way to get information about the IDE and its features, as it provides a list of articles pertaining to the current content. To create a simple program, displaying text and an Image, follow these steps:

Create the new project as windows application. Set the text in the forms title bar by the forms Text property Resize the form through forms enabled sizing handles Change the forms background color through the BackColor property.

Customize the labels appearance and set the labels font size and align its text. Resize the label vertically if it is not large enough to hold the text (for this make sure that labels autosize property is false).

Add a picture box to the form to insert an image by clicking the picture box to display its properties and locating its Image property. A well-behaved application must contain data-validation code and exception handling. Following Listing examines the value of each text box before attempting to use it in any calculations: 'Validate amount If IsNumeric(txtAmnt.Text) Then LoanAmount =Convert.ToInt32 (txtAmnt.Text) Else MsgBox ("Please enter a valid amount")

Another way to create well-behaved applications is to use exception handling. Errors are now called exceptions. If an exception occurs, the program must execute special statements to handle the exception. The outline of the structured exception handler is the following: Try (Statements to be handled for exceptions) Catch Exception {Statements for handling} Finally (Optional statements to be executed after catch) End try VS makes use of different types of files and folders in applications. Solution file (.sln): contains such info like start-up project. Source (Code) file (.vb): It is Visual Basic Source (Code) file, can be viewed in two ways: code view and designer view. It is also called as the code behind (.vb) file. Designer Source (Code) file (.Designer.vb): Form.Designer.vb is the file which contains code of the visual part of the application. Resource File (.resx): specifies different resources of a project like documents, images and multimedia inside XML tags.

o
o

o o

Configuration File (.config): Configuration files contain information about the application, for use by the CLR at run time. They can instruct the CLR to do such things as use a different version of a dll or to look in additional directories when searching for a dll referenced by the program. Configuration files consist of XML code.

o o o

Different Database Files (.xsc, .xsd, .xss): These are different files related to database. Project files (vbproj): This is project info file. Bin and OBJ Folders: The OBJ folder is used to hold intermediate or temp build files. Deleting this folder will just force a recreation of it next time. The BIN folders are where the compiled source code goes as an exe (or dll) file.

o o

Release Folder: Release folder is used when you make a setup program for a project. Portable Executable (PE) is the file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows on any hardware. It is the code that is finally converted from MSIL. Ilasm.exe is a tool that generates PE files from MSIL code. Ildasm.exe is a tool that takes a PE file containing the MSIL code as a parameter and creates a text file that contains managed code (i.e. source code file).

Executable Files: Applications are distributed as executable files, along with their support files. The users of the application can't see your source code, and your application can't be modified. Under the project's file, you will find two folders named Bin and Obj. Open the Bin folder, and you will see that it contains a subfolder named Debug. This is where you will find the executable, which is named after the project and has the extension.exe. You can use it like any other application on your PC. The application will work only if the .NET Framework 2.0 is already installed on the target machine.

The caspol tool grants and modifies permissions to code groups at the user policy, machine policy, and enterprise policy levels. Test Projects option is very useful for experimenting etc. User can just create a temporary project and start coding without saving it. Simplified Build option provides build option similar to Visual Basic 6.0. This is a useful option for VB programmers. Stand-alone project is applicable for solution which has only one project. User will not see the solution in the Solution Explorer as well as the commands that act on solutions. However the solution files are still created.

Das könnte Ihnen auch gefallen