VB6 Development Pilot

Source: Internet
Author: User

Visual Basic 6 is famous for its friendly and easy-to-learn visual development environment and has become the preferred language for people to learn computer programming. University classrooms and training institutions all include her in the teaching content. Ask many programmers who are new to learning what they will do? They usually answer: "I will use VB !" However, if you want them to use VB to solve some practical problems, we will not talk about large software, that is, a small inventory, they will feel hard to do! Unreasonable design, constant bugs, changes to customer needs, and inevitable software changes may cause the use of an invoicing software to fall into a "quagmire "! If a large software is developed, you can imagine the complicated business process locks, the complexity of functional modules, and diversified user needs, many development groups may fall into this tar hole (In The Mythical man-month ).
I used VB for three years of software development and participated in the design and development of more than a dozen software products. I once hosted some large projects for the computing center of the Tianjin Municipal Foreign Trade Commission and Tianjin General Software Co., Ltd, summary of VB development, if you are using VB, I hope it will help you:

Chapter 1 good start is half the success
Solid Basic Skills
Master the basic knowledge of the operating system, data structure, database, software engineering, advanced mathematics, etc. These basic knowledge are all learned from universities. As long as the foundation is solid, this meets this requirement. If a high school student has great enthusiasm for software development, he needs to spend a lot of time learning this knowledge.

Ø interest is the best teacher
If you are interested in programming and want to develop software, it is most important to master a programming language! In the process of learning a program, you will encounter many difficulties. If you are not interested or patient, it is difficult to write a program!

Develop good programming styles and habits
1. program structure cleaning, add notes as appropriate
Add notes for each process
Add appropriate comments to the statements in the process
In if ....... Endif, ...... Next, do ...... While, select case ...... End select and other loops, branches, and condition statements are indented.

2. Standard Control and variable commands
We recommend that you use the following method:
Naming of common controls:
Example of control type prefix
Formfrmfrmmain
Menumnumnufileopen
Labellbllblhelpmessage
Check boxchkchkreadonly
Combo boxcbocboenglish
Command buttoncmdcmdexit
Common Dialog dlgdlgfileopen
Data griddgddgdtitles
Date pickerdtpdtppublished
Directory List boxdirdirsource
Drive list boxdrvdrvtarget
File List boxfilfilsource
Ado dataadoadobiblio
Framefrafralanguage
Hierarchical flexgridflexflexorders
Imageimgimgicon
Imagelistilsilsallicons
List boxlstlstpolicycodes
Listviewlvwlvwheadings
Month viewmvwmvwperiod
MS chartchchsalesbyregion
MS flex gridmsgmsgclients
MS tab m1_stfirst
Ole containeroleoleworksheet
Option buttonoptoptgender
Picture boxpicpicvga
Progressbarpruplgloadfile
Richtextboxrtfrtfreport
Statusbarstastadatetime
Tabstriptabtaboptions
Text boxtxttxtlastname
Toolbartlbtlbactions
Treeviewtretreorganization

Variable name
Data Type prefix example
String (string type) strstrfname
INTEGER (short Integer type) intintquantity
Long (Long Integer type) lnglngdistance
Single (single-precision floating point type) sngsngaverage
Double (double-precision floating point) dbldbltolerance
Boolean (Boolean Type) blnblnfound
Byte (byte type) bytbytrasterdata
Date (date type) dtedtenow
Currency (currency computing and fixed point computing) curcurrevenue
Object (Object Type) objobjcurrent
Variant (variant type) vntvntchecksum

In the programming process, although the variable type is not defined, VB will automatically determine the efficiency is low, as far as possible to define the variable during programming. It is best to add the option explicit statement at the top of the module, so that variables must be defined.

Improve code readability
For example:
Rs. Open "select * from table", CN, 1, 1
It is easier to read than Rs. Open "select * from table", CN, adopendynamic, and adlockbatchoptimistic.

Release resources
If A recordset record set is used, release it in the form_unload event.

Prepare high-quality code
For example, to define variant variables as few as possible, do not define them as double when you know the variable is an integer.
One of the most common examples:

Dim STR (400) as string for I = 0 to 400 STR (I) = "Number" & I & "" text1.text = text1.text & STR (I) Next
Dim STR (400) as string dim Strout as string for I = 0 to 400 STR (I) = "no" & I & "" Strout = Strout & STR (I) next text1.text = Strout

In the above two sections of code, the first section of code cyclically obtains the text attribute. The second section of code uses the loop to accumulate the variable Strout, and finally assigns the value to the text attribute. Although the two sections of code get the same result, the speed of the former cannot be compared with that of the latter. You must know that the speed of the access variable is about 20 times the speed of the access attribute, especially in the loop!
Database developers should also consider the efficiency when writing stored procedures! For example, if you use a cursor to read tables cyclically, more than 10 thousand records will be slow! In all words, we should emphasize writing high-quality code!

Use with... end with whenever possible when modifying the attributes of an object repeatedly

Write frequently used functions into modules to improve the universality and maintainability of programs.

Use enumeration whenever possible
The enumerated format is
[Public | private] Enum name
Membername [= constantexpression]
Membername [= constantexpression]
....
End Enum
Advantage: faster development

Debugging
Add a breakpoint during debugging
Debug with the prompt window
Or use DEBUG. Print to output to the current window.

Program error handling
If there is no good error handling, the program may quit due to a wrong message! We need to add the on error statement to handle the error. Of course, you can also write a global error handling module!

Mastering a database development language
Currently, most software development applications use databases, including access, SQL Server, and Oracle.

Learn more about msdn and access the internet.
Msdn is indispensable for programmers, and websites and forums are also good places to solve the problem.
I personally think the following is a good website:
Http://msdn.microsoft.com
Http://www.csdn.net
Http://www.vbgood.com
Http://www.dapha.net
Http://www.21code.com
Http://www.vbeden.com
Http://www.applevb.com
Http://www.codestudy.net
Http://www.vbaccelerator.com/
Http://www.mvps.org/vbnet/
Http://www.freevbcode.com/
Http://www.pscode.com/vb/
Http://www.allapi.net

Chapter 2 combine controls into a software
VB itself provides many controls that can be flexibly combined into a software. The combination mentioned here refers to the combination based on the business logic, rather than the random combination.
Common controls to be mastered: Engineering ---> components --->
Microsoft Windows Common controls 6.0
Microsoft Windows Common controls 2-6.0
Microsoft Common Dialog controls 6.0
Microsoft FlexGrid controls 6.0
Microsoft Hierarchical FlexGrid controls 6.0
Microsoft DataGrid controls 6.0
Microsoft Internet controls
Microsoft WinSock controls 6.0
Microsoft Rich Textbox controls 6.0
General Software, the use of the above controls can basically complete the majority.
1. first, we need to learn how to use menus, toolbar, and common controls. If you want to use floating toolbar, you can use toolbar and coolbar (there is a coolbar in Microsoft Windows Common controls 3-6.0 ), right-click coolbar --> property ---> band --> sub --> and add a toolbar so that the toolbar can be moved!

2. Second, we should be familiar with the use of the properties and methods of the above controls. The software interface is composed of some controls! The user interface is the embodiment of software operability and availability. Let's look at an example:
Customer Management is a common function of enterprise management software, including adding, deleting, querying, printing, and maintaining customers. How to design this interface? Generally, enterprise customers are classified into direct customers and distribution customers. Some enterprises are classified into domestic customers and foreign customers. Different enterprises have different divisions.
We can design it like this:
L a Treeview on the left that displays the customer category. Each category is represented by a different icon. (We can store the customer category in the database, and the customer can maintain the category)
L The right side is a customer list, which is displayed in tables. Generally, it is in the form of mshflexgrid or listview.
L click a node in Treeview on the left, and the table on the right refreshes the data to display the data of the current category.
L add a toolbar at the top of the form to add, delete, query, print, and exit buttons.
L in the customer list on the right, you can also right-click the menu to edit it (a new window is displayed to edit the selected customer, you can also print and delete the current customer information in a new window.
This interface is basically shaped! If you are familiar with database SQL, this function is easy to implement!
The interface is similar to this: http://www.gci-corp.com/images/fy.gif

3. If you do not have the ability or time to develop controls to complete a function, you can use third-party controls as appropriate.

Chapter 3 How to Become a developer
Master requirements:
Skills in using APIs
In the end, APIs are a series of underlying functions that are provided by the system for users to enter the core of the operating system for advanced programming. If you want to excel, you have to learn API programming. If you do not understand the API, you cannot become a master.
1) Using APIs, we can extend the functions of the VB standard control. Obviously, controls in Windows provide more attributes than those in VB. Microsoft may think that a programmer using VB will never encounter those attributes.

For example, if the Textbox Control has one fewer attribute to get the number of lines of text contained in it, we can use sendmessage to easily get it:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _     ByVal wMsg As Long, _     ByVal wParam As Long, _     lParam As Any) As LongConst EM_GETLINECOUNT = &HBAPublic Function LineCount(txtBox As TextBox) As Long     LineCount = SendMessage(txtBox.hwnd, EM_GETLINECOUNT, 0&, 0&)End FunctionPrivate Sub Command1_Click()    MsgBox LineCount(Text1)End Sub

Mastering ActiveX Control Development
Under the "external program" menu in VB 6, there is an "external program manager" ------ à select "ActiveX interface wizard" to enable/load, later, we can use the ActiveX interface Wizard to generate some common attributes, methods, and events of the control.
VB installation disk and some websites have a lot of control source code, such as http://www.dapha.net, etc.
Of course, developing a good control is not easy. He needs the experience of programmers!

Develop COM +
COM + provides general infrastructure required by enterprise applications, allowing programmers and users to focus their attention and energy on business logic rather than infrastructure.
Advantages: Make the components as common as possible, compile-time features are separated from runtime features, are compatible with previous COM components, and are transparent to customers and components.
For details, refer:
Http://www.icst.pku.edu.cn/CompCourse/

Supports mixed programming in multiple languages
Each development language has its own strengths and weaknesses, and sometimes we have to learn from each other. A good developer who wants to do something is generally not restricted by development tools. They are always looking for a good solution. Of course they are not blindly pursuing technical excellence. We need to consider the feasibility of time and money! If the VB developer still has VC, it will be a waste of water!
Summary:
If you have already met the above requirements, developed large software, and have some experience, you can generally become the technical backbone of the development team. At this time, you need to further improve. In general, the Project Manager can manage employees of less than 10 people. Such positions can still be obtained! Don't underestimate this position. It is a good opportunity to exercise your management skills! At this time, we have to learn how to lead the team for software development!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.