|
汽车零部件采购、销售通信录 填写你的培训需求,我们帮你找 招募汽车专业培训老师
Rudimentary of VB
The pioneer said to be the visual language of Visual Basic (hereafter referred to as VB ), and it is a visual the highest one of degree, to now from the day when VB emerged several years ago, it has already gone through five editions, and the tense reseach , test of carrying on VB6.0 of Microsoft now, such high turnover rate, nothing more than state two questions: Between user and to make earnest efforts VB, the attention to VB of Microsoft. The undeniable prediction ability to the market of Microsoft is extremely sophisticated , but its strong technology, financial resources are supported makes it in a lot of fields not entered in the past, is it become most effective rival to have within time not long, in the browser field one that is such as IE, " kingdom era " is all the best illustration in games. As to the thing that there is a very strong rival D DDelphi VB now, someone calls it VB killer, this obviously has places that goes to extremes, VB really has its weak points, but Delphi is really, and cordial to VB with Microsoft, the function of VB will inevitablely be stronger and stronger.
Birth of VB
The appearance of VB can be said to be the inevitable result ripe day by day of Microsoft Windows. Microsoft Windows has offered a common man-machine interface to programmer and end user. To users, Windows has offered the operating environment of a figure mouse, this environment is the same to all application program; To the programmer, Windows has offered one group to book the justice tool The software development toolbox (SDK ) known as Microsoft Windows, this tool can make the programmer set up a piece of the same application program as Windows interface , and, programmers needn't care about the hardware disposition situation of the end user . In this development environment, programmer's only difficulty is that Microsoft SDK has offered more than 600 pieces of function and drives (event-driven) programming technology instead of unanimous incident. Making numerous programmers get into a difficult position again alternately of two kinds of new methods, the programmer not merely wants to know that the procedure drive programming technology and the functions of more than 600 pieces of function, and must describe these questions in C language . So generally speaking, the programmer should master C procedure designing technique first, and then begin to study SDK . It is easy to operate to demand to present one under the enviroment of Microsoft many tasks under such a condition, new tool simple to use - ---Visual Basic was born from this.
In order to look at He
The meaning of English Visual is " vision ", this name of " Baisc that can be looked at " may be a little bit abstract, but it is the most ocular programming method in fact, named " can look at ing ", so long as you see that the boundary plane of VB will be understood , in fact you do not need programming , can finish a lot of steps . Having introduced the concept of the controlling part in VB, the figure of the controlling part is ubiquitous in Windows, various buttons , text frames , wireless buttons, is the kind of the controlling part, VB patterns these controlling parts, and each controlling part has appearance that several attribute is used for controlling the controlling part, work method. You can like on the drawing board in this way, mouse odd times a bit at will, a button has been finished, pass quite complicated work under these former programming languages.
Incident , attribute and data type
It drives " target -oriented programming " by the incident, to different targets, incidents that can sense will be different too, for example say that will touch off MouseMove incident as you move the mouse while entering a certain area, this is very ocular, apt to understand , but some incidents are more abstract, I following come to explain general incident for a while.
Paint incident: As one target is moved in the screen, change the size or after removing, the procedure will transfer Paint incident automatically. Notice: When the target's AutoDraw attribute is True (- 1 ), the procedure will not transfer Paint incident.
Resize incident: Touch off Resize incident when change in the target's size. Load incident: Only suitable for the body target of the window , run when the window body is loaded. Unload incident: Only suitable for the body target of the window , run when the window body is unloaded. Present incident GotFocus incident of cursor (Focus ): The incident happens when the cursor is focused on this target . LostFocus incident: The incident happens when leave this target in cursor. Notice: Focus English, for " focus ", purpose " focused on ", the most ocular example is, for example there is body of two windows, there is a part that hides each other, when you click the following window body, it will all show , it is in the state activated at this moment, and the title one becomes blue, this is GotFocus incident, and opposite, the body of another window is hidden , and the title one is turned into dust , called LostFocus incident. " cursor " mentioned above does not point the indicator of the mouse .
The mouse operates the incident Click incident: The mouse clicks the target . DbClick incident: Incident that the mouse doubles click.
MouseDown, MouseUp attribute: Push / unlock the key incident of the mouse.
MouseMove incident: The mouse moves the incident. DragDrop incident: Tow the incident of putting , is equivalent to the associations of MouseDown , MouseMove and MouseUp.
 DragOver incident: The mouse will produce DragOver incident in the course of towing and putting.
Operation attribute of the keyboard
KeyDown, KeyUp incident: The pushing / unlocking the incident of the button.
 KeyPress incident: Button incident.
Change and control an incident
Change incident: When change in the target's content , touch off Change incident. The most typical example is a frame of the text (TextBox ).
DropDown incident: Make the incident of playing , is only used for making the target of frame (ComboBox ) up .
 PathChange incident: The route changes the incident, only used in the file and tabulate the target of frame (FileBox ).
Other incidents
Timer incident: Only used in the time-recorder , is touched off once at regular intervals. Each target has its attribute , and " Name " attribute is owned in common, can just be transfered in the procedure if there is " Name " attribute . To attribute, can finish in the overall arrangement of body of the window is operated , can change in the procedure runs too, this depend on need of you, but some attribute belong to read-only, it can only change at controlling part overall arrangement. I will introduce the function of each attribute concretly in the instance afterwards.
The people who have studied programming all know that most computer languages have all stipulated one's own data types, VB is no exception. In fact, the datum type needn't be made and stipulated in a simplest procedure, that is to say , the variable can use all kinds of , but in a complicated procedure, it is very dangerous to do it in this way , because will most likely entrust to different types for the same variable, and cause the procedure to make mistakes. So, it is rigorous and easy to look over , the correct definition data type is essential for the procedure. Another reason for defining the data is, different data take up different quantity of memory, for example datum account for byte 2 for the integrated type (Interger ), and long integrated type datum account for 4 byteses, define the suitable data type, whether you believe , it can save the memory !
VB commonly used data type has: Integrated type ( Integer, express the integer - between 32768 and 32767), long integrated type ( Long, express the integer - between 2,147,483,648 and 2,147,483,647), real type ( Single, real number on it show- 3.37E +38 to +38 of 3.37Es), pairs of precision type not real (Double,express- 1.67E +308 real number for +308 of 1.67Es), character (String, accounting for one byte each character, can store 0- 65,53 characters ), the cloth (Boolean, whether only two pieces of value True/-1 or False /0).
Definition method of the type of the data:
It is to use " Dim " key word to define the simplest method of the variable, its grammar:
Dim [ Variable name] As [Type of the data ]
For instance: Dim Index As Integer
Can define a lot of variables in the delegation too, for instance:
Dim Index As Integer , Dim Number As Long
Can write to define a lot of variables into the same type:
Dim Index , Number As Integer
Can carry on the assignment of the beginning while defining :
Dim Index =3
For being simple and convenient sometimes, carrying on the simple definition with the symbol too, function is as above. The integrated type can be replaced with " % ", long integrated type can with " & " replaces, the real type may spend "! ",pairs of precision real define " " can spending type, if the first example just now can be written:
Dim Index% equivalence is in Dim Index As Integer
The definition of the constant is defined with Const, for instance: Const COLOR =255.
For easy to consult we carry on the regulation to variable and literary style of constant among procedure, the variable generally uses the small letter way, the constant is all capitalized.
Notice: Use advantage of constant , as to number value that procedure appear often , should set up constant mean it, such one is written conveniently, second, if change this number value, only need to change and define the sentence value of the constant, and does not need to change each sentence , have raised the efficiency.
The definition of the array is similar to the variable to define, a different one is that the array need to appoint the number of element in arrays, for example:
Dim IntegerArray(99) As Integer
Including 100 elements in this array, the footnote is from 0 to 99.
Can appoint the initial value of the footnote too, for example:
Dim IntegerArray(2 to 10) As Integer
This array contains nine elements, the footnote is from 2 to 10.
Can also define many dimension groups :
Dim ThreeD(4,2 to 5,3 to 6) As Integer
Have had the example and defined one 3d/33.shtml' target =' _ blank' class =' article '> dimension group three (4* 4* 4 ).
Definition written down
It is the method of giving control power to users that the record is defined, it enables users to define one's own data type, it uses key word " Type ", the method is:
Type ¡¾Data type identification incantation ¡¿
<the domain name> As <data type >
<the domain name> As <data type >
<the domain name> As <data type >
End Type
Whether for example define first address datum.
Type Address
Street As String
ZipCode As String
Phone As String
End Type
Include three pieces of attribute in this address data, whether block, zipcode, telephone, can is it succeed type this to define some data.
Dim MyHome As Address
Similar to the operation to the target's attribute while transfering or changing the value of " MyHome ":
Variable name. Domain name =" ….. "
In order to simplify and write the repeated part , can use key word " With " :
With MyHome
. Street =" the mound becomes the way "
. ZipCode =" 100037"
. Phone =" 12345678" End With
|
|