|
|
Sign In Link to us |
|
Home 1. Introduction 2. Introducing VB 3. Projects 3.1 Stand-alone Project 3.2 Project Group 3.3 Projects Execution 3.4 Compile Projects 4. Containers 5. Controls 6. Code 7. Forms 8. Debugging Code 9. Error Handling 10. Objects 11. User Controls 12. Data Projects 13. API 14. Distribution
|
3. Projects3.1 Stand-alone ProjectIn Visual Basic, a Project is used to group together all of the files which make up your current application. In practice, a Project is just a text file, which refers to all of the Forms, Modules etc. used in your application.
Exercise ii:
Note:
Notice that you are asked to save a file called "Form1.frm" first. This is done first, because the Project file will need
to know where you saved it before it can be saved itself. You may be asked if you want to add the Project to SourceSafe.
This is a version control suite that allows several users to work on one project. The suite allows users to exclusively
"book-out" portions of the project. Once that part of the development is complete., the user may "book-in" the code at a
higher revision. For the purposes of this course, we will not be using SourceSafe - Click "No".
![]()
Note:
Notice the reference to the Form named "Form1.frm", which we saved as part of the Project.
In each project, there needs to be a "Startup" object. This is the first thing that your application will execute when the user runs the program. Visual Basic defaults to the first module you add into the project, but you can change the startup object by selecting "ProjectName Properties" from the "Project" menu. On the "General" tab, change the startup object in the list on the right. For most applications, the startup object will be the main form or perhaps a particular function in a basic code module. 3.2 Project GroupFrom time to time, when using Visual Basic, you may want to swap between several projects. For example, you might be developing an application that uses a custom control (see earlier), so need to keep changing from the application project to the custom control project.To make this easier, Visual Basic allows you to have more than one project open at once. Rather than having several instances of Visual Basic running, however, it can run them in the same Visual Basic instance. This 'collection' of Projects can be saved, so that all of the projects can be easily re-opened when returning to the development. This 'collection' is called a Project Group.
Exercise iii:
Note:
Notice that you are asked to save a file called "UserControl1.ctl" first. Again, this is done first, because the new ActiveX
Project file will need to know where you saved it. You will then be asked to save the Project file for the ActiveX project.
You may be asked if you want to add the Project to SourceSafe. Click "No". Once all of the projects have been saved, you will be
asked to save the Project Group.
![]()
Project Groups do not appear in the Project Explorer, however, as more projects are added to the group, they appear as top-level entries in the Project Explorer window. A Project Group file is similar to a Project file - It stores references to components in a text file. The difference is that a Project Group only stores the paths to the Projects within it.
Note:
It is important to remember that grouping projects like this has no programmatical impact. The individual projects are effectively
isolated from each other as if they were being developed separately. The Project Group function is merely for the convenience of
the programmer.
3.3 Projects ExecutionWhen running and testing projects inside Visual Basic, they are executed in a controlled way. If you accidentally write a program which can never terminate (e.g. an infinite "While" loop), you can press the "Ctrl" and "Break" together and Visual Basic will interrupt the project execution. When the project is made into an actual ".exe" file, any mistakes like this cannot be intercepted - they will crash.You can also tell Visual Basic to purposefully pause the project execution at a particular place. This is called a "Breakpoint". When Visual Basic encounters a Breakpoint, it pauses the execution and switches back to the Code View window, so that you can inspect the state of the variables etc. From here you can execute the code line-by-line if required. This is an excellent tool for debugging your applications.
![]() A breakpoint can be added by simply clicking in the margin beside the instruction where you want Visual Basic to pause. An active breakpoint is shown as a red dot in the margin and highlighted code text. 3.4 Compiling and Making ProjectsEach time you run the project inside Visual Basic, it is "Compiled". This process translates the Visual Basic code into actual code that will run on the PC. Whilst compiling, Visual Basic checks that there are no errors in the code or in the project set-up. If there are any errors, it will bring up a dialogue message telling you what is wrong.Once you have finished developing the project, you might want to create an executable file or ".exe". To do this, you have to Make the project. When Visual Basic makes a project, it compiles it first to make sure that there are no errors in the code or in the project set-up. It then generates the ".exe" file in the location you specify. Once made, a project can be run under Windows like any other ".exe" file (without the use of Visual Basic). Projects are made by selecting the "Make ProjectName.exe." option from the File menu. |