subscribe: Posts | Comments

The programming environment of Visual Basic

0 comments
HTML clipboard

I. Let us know the programming language object
I-A. General
Visual Basic, is in perfect harmony with Windows. The developing an application through the following steps:
* Drawing of the user interface, ie windows and their constituents, using an interactive tool drawing, "the Visual Basic."
* Enrichment initial properties which are attributes or characteristics of each element of the interface.

I-B. Writing code BASIC
The programming of applications Visual Basic is known event, as opposed to the traditional linear programming.

Thus, a Visual Basic application consists of a set of procedures independent of each other.

I-C. The procedures
A procedure includes instructions written using the BASIC language. It is associated with an object, ie one element of a leaf, the leaf itself, or a button, a list, one entry fields etc. …
The procedure is called by Visual Basic occurs when an event for the corresponding object.

If you have not written code in a procedure to deal a type of event for a given object, nothing happens in particular when the event is generated.
To write the code of an application, it is therefore necessary to determine the events to which you want to react, and for what objects.
This determines the procedures under which the code is written.

II. The main window (GUI design)
II-A. 3 horizontal bars
The main window has three horizontal bars:

* The title bar, like any Windows application.
* The menu bar, allowing the seizure orders, and
* Toolbar providing quick access to major commands

II-B. The toolbox
The toolbox is a window that includes all the icons initially viewing custom controls (applying some additional controls are optional depending on the version you have) for the standard version 20 icons.

It is accessible only design phase (Mode Judgement)

II-C. The project window
The window project includes the list of the various constituent files an application.

(For the moment we only have a single file "Form1")

II-D. The properties window
The window properties include a list of properties of the object selected in the current leaf (leaf) or control) and their values.

II-E. Procedures
At the top the list of objects, now set out in the selected file in the window on the right project and the procedure called by Visual Basic occurs when an event for the corresponding object

III. Move forward in the implementation
At this stage of implementation, we have created a single window, then the main window.
The main window interface that I call home is the sheet that the user sees first when the program is launched.
We can build as many leaves as you want and determine thereafter it is the leaf which will become the host interface.
This possibility is achieved by setting the working environment of Visual Basic.

Click on the menu bar on the label "Project", then "Properties project1" selected "Subject starter."
If the entry fields include the value "Sub hand, edit and write" Form1 "which is the name of the sheet that we created and on which we are currently working on.
Thereafter we will change the value of the label to enter the name of the paper we want to launch the program start.

Before we embark on the super production that will keep us in suspense for a few hours, I must teach you a few ideas that seem indispensable for the proper understanding of the rest of the program.

III-A. A tiny little Theory
III-A-1. Methods
Sub Visual Basic, certain functions are accessible only in combination with objects. These instructions are called methods. For example, the method Show load and displays a window defined by the user (you in this case) (refer to sources for other methods)

III-A-2. Programming Event
Visual Basic programs are controlled by the events generated by the objects of the user interface.
For example, the loading of a leaf is an event in which certain instructions may be linked., Such as deleting a leaf in memory.
The event will be caused by a click of a mouse, in the case of a button, or a modification of the contents of a text box.

III-A-3. Area of validity of variables and procedures
Like any modern language, Visual Basic knows the global variables, local and static.
The global variables are accessible from the entire program but local variables are known only in their proceedings. The static variables retain their value out of the procedure, which distinguishes them from local variables.

 

III-A-4. Compilation
When a project has been compiled, its extension becomes EXE, and it is no longer possible to "dismantle" all its component files are now closely associated.
The images installed in a control are also integrated into the executable. Only OCX or TXT files remain autonomous, and must be delivered to the user.
DLL files will also be provided with the application.

III-A-5. The types of data

HT

Suffix Type Size Data Limits use
 % Integer Oct. 2 of -32,768 to 32767
 & Long Oct. 4 of -2,147,483,648 to 2,147,483,647
! Single (floating point a single precision) Oct.4  -3.402823 between E38 and -1.401298 E-45 for negative numbers
and between 1.401298 E-45 and 3.402823 E38 for positive
# Double (floating point double precision) Oct.8 -1.79769313486232 between E308 and -4.94065645841247 E-324 for negative numbers
and between 4.94065645841247 E-324 and E308 for 1.79769313486232 positive
@ Currency (Comma fixed 15 digits to the left of the decimal point and 4 figures on the right)  Oct.8 between -922 337 203 685 477.5808
and 922 337 203 685 477.5807
$  String Oct. 1 per character
nothing Variant  required number  

III-A-6. Some details
From this table that holds on whether to declare a variable alphanumeric (characters texts) on choose a variable String
For a deal with numbers or simple counting operations, choose a variable digital type Integer, or long for significant transactions (see limits).
For monetary calculations, we will choose the variable Currency.
The default type of a variable is VARIANT.Ce type Visual Basic indicates that the data is likely to contain various types of data.
I do not use the variable Variant, except in cases of force majeure.

III-A-7. What is a variable?
The instructions are verbs that act on variables.
A variable can be regarded as a memory box. It has a name and value.
The name is made up of letters, numbers and characters <_> (underlined), the first character must be a letter and there can be no more than 40 characters in a variable name.

III-A-8. Declarations of variables
The declaration of a variable is done in several ways, namely:
Sunday <name of the variable> As <type of variable>
Ex: to declare a variable String (Alpha), which you named <Bazile>, you write
Sunday Bazile As String represented in the program by <Bazile$>
If variable is the same type Integer (digital), you write:
Sunday Bazile As Integer represented in the program by <Bazile%>

III-A-9. Properties of an object
Example of an entry fields with a label whose property Caption: Name, and as property Name: Label1.


Do not confuse the Name property which is the default name of the object, and the Caption property which may have any name and in the present case is the name of the user to enter. You put some time you do, but you will understand with a little experience.

The property Name is the name you give to the object in the development phase. This property is not visible to the user. By against property Caption is the name you give the value of the label, in the example here is Name:, but it could have been <Adresse> or <Ville> etc. … and this property is visible to the user, but unlike the TextBox it can not be changed.

III-C. First lines of code
We will try to put into practice the formulas previously acquired.
When you are working on the interface of work you are in development mode.
You can control the smooth running of instructions or functions written in the code pages in passing mode execution.
We will write our first line of code and view the operation mode execution.
Writing in the property Caption button command "Command1" & Exit.

We will serve as a demonstration of this button to leave our application.

By doing a "DoubleClick" button, we open a sheet which is the piece of code of the object which has just been selected.

In view of the worksheet code corresponding button command "Command1"

This sheet is presented with a "ComboBox" (Command1), which allows you to click the little button right place a list that includes all the names of objects used in this sheet (Form1).
The "right ComboBox (Click) lists all the properties available for the selected object.
We must generate an event when the user presses the button, and when it will generate a click with the mouse.
We therefore select the event "Click".
Writing code in the worksheet code button command "Command1" with the event "Click"
We write our first procedure by typing:
Private Sub Command1_Click ()
'Exit program
End
End Sub
You saw that I put an apostrophe in front of the line of text "Quitting the program"
These lines starting with an apostrophe are called "lines of comments. It is indeed advisable to indicate in the form of text explanation of the event that we wanted to do.
This will be very useful especially when our program will consist of dozens of procedures.
Do not deprive them especially as the compiler completely ignores the lines of comments.

If you are a little curious (It must be a programming) and you have clicked on "General" in the worksheet code you find that the interface includes an instruction "Option Explicit."
This instruction force the developer to declare all variables used in its program.
If you forget to declare a variable in the design phase, the program will remind you to order and show you a mistake.

Since we have just set up our first procedure, trying to launch it to see what happens.
In the toolbar, then click on run

formed a small triangle.
The sheet must be displayed, and when you click "Exit", the application must close.

Visual Basic written warning under the blue all the words so-called "reserved" you can not use them outside the office established by the programming environment.