![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
As an example of a multiple form project, we will use two of the software components we have already developed: the Calculator and the Baby Editor. Start Visual Basic and create a new Standard EXE project. Add a control array of three Command Buttons to the form, and assign Caption properties as follows:
Next, select the Add Form command on the Project menu. In the dialog box, click on the Existing tab and locate the Calculator form we created earlier, adding it to the project. Repeat to add the Baby Editor form as well. Add the code in Listing 11.17 to the Command Buttons Click event procedure. Save the project, using the name MultiForm for both the form and the project. When you run the program, you will first see a form with the three Command Buttons. Click on the Editor button and the Baby Editor appears; click on the Calculator button and the calculator appears. Click on either button again and the corresponding form disappears. When all three forms are displayed (as shown in Figure 11.7), you can switch among forms, move them around the screen, minimize them, and so on. Click on Quit to close all.
Listing 11.17 The Command Buttons Click event procedure. Private Sub Command1_Click(Index As Integer) Select Case Index Case 0: If frmBabyEditor.Visible = False Then frmBabyEditor.Show Else frmBabyEditor.Hide End If Case 1: If frmCalculator.Visible = False Then frmCalculator.Show Else frmCalculator.Hide End If Case 2: End End Select End Sub Figuring out how the code works is easy. For each form, the code first checks its Visible property to see if the form is already displayed. If Visible is False, the Show method is used to display the form. If Visible is True, Hide is used to close the form. In this project, the startup form remains visible when another form is displayed. This is not always desirable, of course, and you can use the Hide method to close the first form at the same time you are using Show to display the second form. Note also that the three forms in the project are independent of each otherno master form contains the others, as is the case with many Windows applications. This effect is obtained with a so-called multiple document interface project, which we will explore in Chapter 22. Additional Text ProcessingWe have learned a lot about working with text in this chapter, but Visual Basic offers even more. In particular, Visual Basics collection of built-in functions provides a wide range of useful text handling operations. You can, for example, locate one string within another, change capitalization, extract parts of strings, and apply specific formatting. Table 11.4 includes a brief listing of whats available; I leave it to you to locate the details in the Visual Basic Help system.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain |