I used to engage in VC before, recently received a task to maintain an old VB program, is made from VB4, experience VB4, VB5, VB6, may be due to too much limited, so there is a shortest problem (I think it is a problem, compared with VC), please heroes guidance: How to do the most correct, how to do the best for me
1, use a lot, quite a large global variable, and many are defined inside the modules, the survival period is too long, and it is easy to name conflicts, cross access, no protection level, cross-use is also difficult to find;
2, the variable is naming, many of the names of XPM, YPM, XPM0, YPM0, is difficult to memorize, and the auxiliary function of VB6 seems not enough. The mouse does not change the variable type, annotation and other information;
3. Another drawback of the auxiliary function is to do not support the mid-axis, and the top and down the page is very hard;
4, forms and modual naming are also irregular, do not know if they can be renamed;
5, there is a main entrance and a master form, MIAN calls Form, has been loop in the background after forming Form, monitoring two communication port status (it is said to prevent response communication events), although using doevents, the CPU resource occupation has always been 100 %; The usual way to use a secondary thread "waiting" communication event, basically do not have to worry about the response delay, it seems to be able to do this, but the level is limited, there is no relevant information yet.
6, need to be compatible with 98 and 2K, do not know what aspects needed? Now I don't even know that Sleep can't be used under 98;
7, the drawing control seems to be able to only operate Interge, and I need Double operation, the minimum is also long ... The number of effective bits can not be too small;
8, the interface is difficult, no color has no dynamic form, and the background color grayscale used in the form is different;
9. There are too many forms in the Project window, do not know how to make them separate, and Modules will have a similar situation;
10. Only a few structural types, no class, switch to class system workload seems too big, and there is a little virtual;
Also mention a few questions:
1. I don't know how the private variable defined in Formp, how to use the sub-Forms that calls FORMP?
2. If the public variable is defined in the form, does the variable still exist after unload form? What is otherwise? Some books say public and static, don't understand ...
3. Whether it is customized a type (structure), can it use it to define a variable in other places? Don't you need a header file or declaration in C ?
4. If the project is placed to vc.net is actually: Is the workload increase? Is the compatibility that will affect? Look at some information to mention many new features of VC.Net, and C is getting more similar, if you can assign a initial value (defined when you can use it), you can inherit the class (rather than implementing the interface), etc., it feels quite intimate.
5. It is said that the VB call API is easy to trigger, and I'm can't capture, so it is easy to die, I don't know if there is anything?
First asked so much, you gave a doctor, thank you first!
I immediately advocated rewriting, rewritten with VC, and then rewrite it with VB.NET, but unfortunately, the head disagree! Everyone, the disease, the disease may be too cumbersome, you will give me a few fitness squares, such as doing projects with VB doing projects: variable definition, survival, protection level, form and module Relationship, etc.
In fact, I want to open this maintenance, although I have painted, I really realized the importance of documentation, programming style, design model, etc., anyway, I don't hurry, I plan to rewrite while learning using rose2k, if you are interested Friends can contact: rainee_my@hotmail.com
Also mention a few questions:
1. I don't know how the private variable defined in Formp, how to use the sub-Forms that calls FORMP?
In form:
Private M_Spage As String
Friend Property Get () AS STRING
Page = m_spage
End Property
Friend Property Let Page (Byval Spage As String)
m_spage = spage
End Property
In forms:
Formp.page =
2. If the public variable is defined in the form, does the variable still exist after unload form? What is otherwise? Some books say public and static, don't understand ...
The global public, private should be, public and static should not be the same, PUBLIC should be accessible by external access, static can't
3. Whether it is customized a type (structure), can it use it to define a variable in other places? Don't you need a header file or declaration in C ?
Public Type declared in the module is like this
4. If the project is placed to vc.net is actually: Is the workload increase? Is the compatibility that will affect? Look at some information to mention many new features of VC.Net, and C is getting more similar, if you can assign a initial value (defined when you can use it), you can inherit the class (rather than implementing the interface), etc., it feels quite intimate.
do not know
5. It is said that the VB call API is easy to trigger, and I'm can't capture, so it is easy to die, I don't know if there is anything?
It should not be captured, and the illegal operation of the API application is often often
Thank you for your support.
About the variable I have summarized something:
Variable definition, survival (scope is slight)
Process grade:
Allow two ways to define DIM or STITIC, DIM's survival is only in the process, and Static's survival is equal to the survival of the program;
STATIC FUNCTION DIM declaration is equivalent to STATIC;
"
Form-level:
Allow three ways to define DIM, PRIVATE, PUBLIC, DIM = private;
The survival period generates from the form to the form unload and the form name set nothing, only unload does not set SET FORM = Nothing Can't release the variable memory
"
Modular level:
DIM = private, global = public;
The survival is equal to the survival of the program;
"
Class: Not tested, should it be similar to C ? "
Precautions:
The Static type can be defined in the process grade;
Specifications, fixed length strings, arrays, custom types, assertions, etc. must not use public types;
Form should also be seen as a special Class
As for Private, Public, Global, DIM, I understand this way
Global is completely used for compatible with previous VB4
I never used it when I write.
The module-level edges are used with private, public instead of DIM
As for management, it is generally
Project Folder
|
- Form (Forder)
- Class (Folder)
- Module (Folder)
- Projects Relation Files (Like .vbp, .vbg)
--_ Resource (Folder)
| | |
| - CURSOR (Folder)
| - iCon (Folder)
| | - 16X16 (Folder)
| | - 32x32 (Folder)
| - Images (Folder)
|
--_ Documents (Folder)
|
_History (Folder)
--_Release (Folder)
|
|
The above is for reference only, usually put _Document, etc., in the Folder of the previous layer, it is simply written here.
The problem of the landlord is what problems that are troublesome.
Unlike the landlord, it is the graduation student this year, there is not much experience
And my project leader, I graduated more than I have been, I like "repairing replenishment",
Which variables want to do, what is the name of what is the name, no comment, no documentation.
The program framework is never discussed with me or not. Don't consider my feelings.
Many things must rely on my own reading code to digest the experience.
The first error of the landlord will often appear:
1, use a lot, quite a large global variable, and many are defined inside the modules, the survival period is too long, and it is easy to name conflicts, cross access, no protection level, cross-use is also difficult to find;
Many times, telling that this kind of maintenance is more despread, but I think if I change to him,
He may not be better than me.
1, use a lot, quite a large global variable, and many are defined inside the modules, the survival period is too long, and it is easy to name conflicts, cross access, no protection level, cross-use is also difficult to find;
Try not to define global variables in Modules, and add a comment for indeed needs. For constants, use the Const statement. If a variable in a from other from other from calls, you can declare a public variable in this From, which is called with fromName. Variable, you can solve the problem of naming conflicts, cross-access, and survival (occupied memory).
2, the variable is naming, many of the names of XPM, YPM, XPM0, YPM0, is difficult to memorize, and the auxiliary function of VB6 seems not enough. The mouse does not change the variable type, annotation and other information;
VB has its own naming norm, and C is not only the same, such as DIM INTPOS AS INTEGER, DIM STRNAME AS STRING, DIM BLNFLAG AS BOOLEAN, etc., the range prefix (M, g) array prefix (A) type prefix (int, Str ...) variable name, such as modular grade characters array variable: maastrid, global level integer variable: gintyear, process grade long integer variable: LNGX. Good naming habits can reduce a lot of unnecessary mistakes, in addition, in the first line of from or modules, plus Option Explicit (must be declared before variable) is a very good habit. Named specifications for variables, objects, and controls can be found in MSDN. 3. Another drawback of the auxiliary function is to do not support the mid-axis, and the top and down the page is very hard;
This has a solution.
4, forms and modual naming are also irregular, do not know if they can be renamed;
The form is prefixed in FRM, the module is prefixed in MDL, and the class module is prefixed in CLS. After the project is established, you can change the name of the form and module, but the file name will not change. If you want to change the file name, you must save it. The best way is to simply create a form or module, name the code to the code with the specified name.
5, there is a main entrance and a master form, MIAN calls Form, has been loop in the background after forming Form, monitoring two communication port status (it is said to prevent response communication events), although using doevents, the CPU resource occupation has always been 100 %; The usual way to use a secondary thread "waiting" communication event, basically do not have to worry about the response delay, it seems to be able to do this, but the level is limited, there is no relevant information yet.
Take a specific code, you can send it to everyone.
6, need to be compatible with 98 and 2K, do not know what aspects needed? Now I don't even know that Sleep can't be used under 98;
Is there a Sleep this function in VB?
7, the drawing control seems to be able to only operate Interge, and I need Double operation, the minimum is also long ... The number of effective bits can not be too small;
I don't know which drawing control you said, everyone discusses.
8, the interface is difficult, no color has no dynamic form, and the background color grayscale used in the form is different;
The VB interface can be done very nice, and it will not trouble more than VC.
9. There are too many forms in the Project window, do not know how to make them separate, and Modules will have a similar situation;
It seems that there is no other way, huh, huh.
10. Only a few structural types, no class, switch to class system workload seems too big, and there is a little virtual;
The VB support class, but not complete, such as can't rewrite the constructor, can not inherit.
Also mention a few questions:
1. I don't know how the private variable defined in Formp, how to use the sub-Forms that calls FORMP?
Private variables cannot be called in other forms
2. If the public variable is defined in the form, does the variable still exist after unload form? What is otherwise? Some books say public and static, don't understand ...
After unload from, the variables in the FROM will naturally be released. Demo001 said that when you call Print from2.i, from2 has been Load. That is to say, if this from the version is not loaded, VB will automatically load it, Demo001 may wish to write a line of code in from_load to verify. 3. Whether it is customized a type (structure), can it use it to define a variable in other places? Don't you need a header file or declaration in C ?
Must be declared in the module as public
4. If the project is placed to vc.net is actually: Is the workload increase? Is the compatibility that will affect? Look at some information to mention many new features of VC.Net, and C is getting more similar, if you can assign a initial value (defined when you can use it), you can inherit the class (rather than implementing the interface), etc., it feels quite intimate.
What should the landlord say that VB.NET? VB.NET is actually very different from VB. I don't know what this software is mainly used. If you contain more graphic processing, use VB.NET to write. VB.NET has an essential difference from VB on graphic processing. In addition, most of the statements and functions of VB can be used in VB.NET, but it is a bit uncomfortable, you can use VB.NET's VB6 upgrade guide test, but it is estimated that you still have to do a lot.
5. It is said that the VB call API is easy to trigger, and I'm can't capture, so it is easy to die, I don't know if there is anything?
ON Error cannot capture an API error. VB Call API As long as you pay attention to the conversion of the variable type, the release of memory is fine, not so terrible.
I have a little bit of experience, everyone is interested in discussing.
If the public variable is defined in the form, does the variable still exist after Unload Form? What is otherwise? Some books say public and static, don't understand ...
After unload from, the variables in the FROM will naturally be released. Demo001 said that when you call Print from2.i, from2 has been Load. That is to say, if this from the version is not loaded, VB will automatically load it, Demo001 may wish to write a line of code in from_load to verify.
--------------------------------
The landlord has already said, after set nothing, it can be completely destroyed, this statement is
No matter you
SET O = New Form2
O.SHOW
still is
FORM2.SHOW
Finally, only SET NOTHING can be completely destroyed, otherwise you can still reference its public variables
Others' code is indeed a headache, especially if the unregulated code is too big, I would rather rewrite
In VB.NET, the main function can still be the entry of the program, but the program is terminated after the main function is executed.
For example, we often write this in VB6
Sub main ()
init ()
frmmain.show
End Sub
However, in VB.NET is executed, the program is exited, and it is not running like VB. You can move the code of the main function to the LOAD event of the startup form, or the way Application.Run can be used as a program's entry point.
Firechun (Tianhu) According to my analysis, the object instance of Form2 and its global variable are not together.
This is why, you unload, can still quote form2.i
To destroy Form2 completely cutly
Correct way:
Unload form2
SET FORM2 = Nothing
This first unresses the FORM2 object, then destroy the Form2 data area
As for what you said, Debug.print Form2.i is still available
Nice, that is because Form2 is reselected, i is a reassigned memory, the value is empty
Will automatically Initialize, not LOAD
The LOAD event should only be triggered when Load Form, Form.show.
So if you don't set nothing is just unload, then the global variable is not destroyed.
You can still reference global variables in Form2 (value will not change)
Parled in the right place, all ax
Rainee (replenishment)
However, it seems that both functions should be added to the BY REF, the efficiency is relatively high.
--------------------------------------------
How do you say this, you say that it is faster according to the address.
However, in consideration of the concept of the package, the requirements for the interface will be more stringent.
Our standardized writes, do not use BYVAL without special circumstances
I have learned a lot :)
To Nik_AMIS (Azrael)
About Byref I have a sense of feeling, it is really useful to use the value of the value, preventing the unexpected memory operation in the function affects the original value, only needs to be in the custom class or structure (large volume) and string ( Personally feel that it should be used in both cases. And VB.NET also turns the default BYREF mode of the function parameters into the default Byval.
To Firechun (Tianhuo)
Handle error, is preparing to transplant to VB.NET, but yesterday attempted that in addition to a large pile of unlessned variables after the project upgrade, even the MIAN entrance has been lost, and it is estimated that there will be a way to solve, but I don't know where to start, I have to complete some standardized work in VB6.
Your explanation of FORM is very incisive, benefiting a lot.
Today, I joined Option Explicit declaration, and the result is doing the work of defining variables all day, and I haven't ended yet, sweat ...
The cycle is extremely simple, it is doevent, judges the status of the serial port (two) writes and processes, loop, as for whether it will be delayed as it is said above, wait for me to complete the "Specification" work after actually testing Bar;
Sleep refers to the API function. Sorry, no explanation; how do I mean how to deal with the compatibility of 98, 2k or even XP, what experience is there, the ex-car, the return of the car;
The drawing control is the PictureBox, but not integer, but single; mainly uses it to do some flat drawing, if you let me red, maybe I will choose to use OpenGL, but I am not OpenGL master, I want to borrow project learning. Let's stop :)
To Demo001
I have a good mouse is Shuangfei Yan, I will try it.
Listening to your project, the person in charge seems to be quite complained. In fact, there are this situation in many places. After all, arrange and managers are a very complicated thing, first do your work, have time to learn, one day sooner or later You will have the opportunity to show your fists.