|
Article on other languages:
|
This article is about the Visual Basic language shipping with Microsoft Visual Studio 6.0 or earlier. For the Visual Basic language shipping with Microsoft Visual Studio .NET or later, see Visual Basic .NET.
Visual Basic (VB) is a third-generation event-driven programming language and associated development environment (IDE) from Microsoft for its COM programming model. VB is also considered a relatively easy to learn and use programming language, because of its graphical development features and BASIC heritage.[1] Visual Basic was derived from BASIC and enables the rapid application development (RAD) of graphical user interface (GUI) applications, access to databases using Data Access Objects DAO, Remote Data Objects RDO, or ActiveX Data Objects ADO, and creation of ActiveX controls and objects. Scripting languages such as VBA and VBScript are syntactically similar to Visual Basic, but perform differently.[2] A programmer can put together an application using the components provided with Visual Basic itself. Programs written in Visual Basic can also use the Windows API, but doing so requires external function declarations. The final release was version 6 in 1998. Microsoft's extended support ended in March 2008 and the designated successor was Visual Basic .NET.
Language featuresLike the BASIC programming language, Visual Basic was designed to be easy to learn and use. The language not only allows programmers to create simple GUI applications, but can also develop complex applications. Programming in VB is a combination of visually arranging components or controls on a form, specifying attributes and actions of those components, and writing additional lines of code for more functionality. Since default attributes and actions are defined for the components, a simple program can be created without the programmer having to write many lines of code. Performance problems were experienced by earlier versions, but with faster computers and native code compilation this has become less of an issue. Although programs can be compiled into native code executables from version 5 onwards, they still require the presence of runtime libraries of approximately 2 MB in size. This runtime is included by default in Windows 2000 and later, but for earlier versions of Windows or Windows Vista, it must be distributed together with the executable. Forms are created using drag and drop techniques. A tool is used to place controls (e.g., text boxes, buttons, etc.) on the form (window). Controls have attributes and event handlers associated with them. Default values are provided when the control is created, but may be changed by the programmer. Many attribute values can be modified during run time based on user actions or changes in the environment, providing a dynamic application. For example, code can be inserted into the form resize event handler to reposition a control so that it remains centered on the form, expands to fill up the form, etc. By inserting code into the event handler for a keypress in a text box, the program can automatically translate the case of the text being entered, or even prevent certain characters from being inserted. Visual Basic can create executables (EXE files), ActiveX controls, DLL files, but is primarily used to develop Windows applications and to interface web database systems. Dialog boxes with less functionality can be used to provide pop-up capabilities. Controls provide the basic functionality of the application, while programmers can insert additional logic within the appropriate event handlers. For example, a drop-down combination box will automatically display its list and allow the user to select any element. An event handler is called when an item is selected, which can then execute additional code created by the programmer to perform some action based on which element was selected, such as populating a related list. Alternatively, a Visual Basic component can have no user interface, and instead provide ActiveX objects to other programs via Component Object Model (COM). This allows for server-side processing or an add-in module. The language is garbage collected using reference counting, has a large library of utility objects, and has basic object oriented support. Since the more common components are included in the default project template, the programmer seldom needs to specify additional libraries. Unlike many other programming languages, Visual Basic is generally not case sensitive, although it will transform keywords into a standard case configuration and force the case of variable names to conform to the case of the entry within the symbol table entry. String comparisons are case sensitive by default, but can be made case insensitive if so desired. The Visual Basic compiler is shared with other Visual Studio languages (C, C++), but restrictions in the IDE do not allow the creation of some targets (Windows model DLL's) and threading models. Characteristics present in Visual BasicVisual Basic has the following traits which differ from C-derived languages:
Evolution of Visual BasicVB 1.0 was introduced in 1991. The drag and drop design for creating the user interface is derived from a prototype form generator developed by Alan Cooper and his company called Tripod. Microsoft contracted with Cooper and his associates to develop Tripod into a programmable form system for Windows 3.0, under the code name Ruby (no relation to the Ruby programming language). Tripod did not include a programming language at all. Microsoft decided to combine Ruby with the Basic language to create Visual Basic. The Ruby interface generator provided the "visual" part of Visual Basic and this was combined with the "EB" Embedded BASIC engine designed for Microsoft's abandoned "Omega" database system. Ruby also provided the ability to load dynamic link libraries containing additional controls (then called "gizmos"), which later became the VBX interface[5]. Timeline of Visual Basic (VB1 to VB6)
Derivative languagesMicrosoft has developed derivatives of Visual Basic for use in scripting. Visual Basic itself is derived heavily from BASIC, and subsequently has been replaced with a .NET platform version. Some of the derived languages are:
Performance and other issuesEarlier counterparts of Visual Basic (prior to version 5) compiled the code to P-Code or Pseudo code only. Visual Basic 5 and 6 are able to compile the code to either native or P-Code as the programmer chooses. The P-Code is interpreted by the language runtime, also known as virtual machine, implemented for benefits such as portability and small code. However, it usually slows down the execution by adding an additional layer of interpretation of code by the runtime although small amounts of code and algorithms can be constructed to run faster than the compiled native code. Visual Basic applications require Microsoft Visual Basic runtime MSVBVMxx.DLL, where xx is the relevant version number, either 50 or 60. MSVBVM60.dll comes as standard with Windows in all editions after Windows 98 while MSVBVM50.dll comes with all editions after Windows 95. A Windows 95 machine would however require inclusion with the installer of whichever dll was needed by the program. Legacy Development and SupportAll versions of Visual Basic from 1.0 to 6.0 have been retired and are now unsupported by Microsoft. Visual Basic 6 programs can still run on Windows versions up to and including Vista. Development and maintenance development for Visual Basic 6 is possible on Windows XP and Windows 2003 using Visual Studio 6.0. Documentation for Visual Basic 6.0, its application programming interface and tools is best covered in the last MSDN release before Visual Studio.NET 2002. Later releases of MSDN focused on .NET development and had significant parts of the Visual Basic 6.0 programming documentation removed. Development for this type of legacy system is typically done using a virtual machine with Windows 2003 or Windows XP, Visual Studio 6.0 and MSDN documentation. As of August 2008, both Visual Studio 6.0 and the MSDN documentation mentioned above are available for download by MSDN subscribers. Example codeHere are some examples of the language: Program to display a pop-up message box with the words "Hello, World!" on it: Private Sub Form_Load() MsgBox "Hello, World!" End Sub Program to display an input box: Sub Main() Dim a As String a = InputBox("Enter your name:") MsgBox a End Sub Running Another Application Using Visual Basic: Private Sub Run_Notepad() Shell "notepad.exe", vbMinimizedFocus 'opens notepad End Sub Printing multiplication table of 5 on form: Private Sub PrintMul_Click() Dim I As Integer For I = 1 To 10 Print 5; " x "; I; " = "; 5 * I Next I End Sub Displaying all prime numbers below 100: Private Sub DisplayPrimeNumbers() Dim Num As Long Dim NN As Long Dim IsPrime As Boolean For Num = 2 To 100 IsPrime = True For NN = 2 To Int(Num / 2) If Num Mod NN = 0 Then IsPrime = False Exit For End If Next If IsPrime Then MsgBox CStr(Num) + " is a prime number!" End If Next End Sub Printing the string in reverse format Private Sub DisplayReverseText(Byval Text as string) Dim i As Long For i = len(text) to 1 Step -1 Print Mid(Text, i, 1); Next print End Sub
See also
References
External linksWikibooks has a book on the topic of
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.
Mercedes Car
This site monitored by SitePinger.net