|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Note the last of the statements, Startup=Sub Main. This indicates that this program starts with a Main() procedure, not a startup form (well see more about this in the next chapter). In the Main() procedure, the program first loads the splash screen, then the MDI frame window. The MDI frame window in turn loads its first child window, based on the frmDocument form. Taking a look at frmDocument.frm, which appears in Listing 1.3, indicates that this child window displays a rich text control (as you can see by the inclusion of the rich text control), which in fact handles all the text. As you can see, taking apart projects file by file this way removes all the mystery, and its a good skill for the Visual Basic programmer to have. Listing 1.3 frmDocument.frm
VERSION 6.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.1#0"; "RICHTX32.OCX"
Begin VB.Form frmDocument
Caption = "frmDocument"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 3195
ScaleWidth = 4680
Begin RichTextLib.RichTextBox rtfText
Height = 2000
Left = 100
TabIndex = 0
Top = 100
Width = 3000
_ExtentX = 5292
_ExtentY = 3519
_Version = 393216
Enabled = -1 'True
ScrollBars = 3
RightMargin = 8e6
TextRTF = $"frmDocument.frx":0000
End
End
Attribute VB_Name = "frmDocument"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub rtfText_SelChange()
fMainForm.tbToolBar.Buttons("Bold").Value = IIf(rtfText.SelBold, _
tbrPressed, tbrUnpressed)
fMainForm.tbToolBar.Buttons("Italic").Value = IIf(rtfText.SelItalic, _
tbrPressed, tbrUnpressed)
fMainForm.tbToolBar.Buttons("Underline").Value = _
IIf(rtfText.SelUnderline, tbrPressed, tbrUnpressed)
fMainForm.tbToolBar.Buttons("Align Left").Value = _
IIf(rtfText.SelAlignment = rtfLeft, tbrPressed, tbrUnpressed)
fMainForm.tbToolBar.Buttons("Align Right").Value = _
IIf(rtfText.SelAlignment = rtfRight, tbrPressed, tbrUnpressed)
fMainForm.tbToolBar.Buttons("Center").Value = _
IIf(rtfText.SelAlignment = rtfCenter, tbrPressed, tbrUnpressed)
End Sub
Private Sub Form_Load()
Form_Resize
End Sub
Private Sub Form_Resize()
On Error Resume Next
rtfText.Move 100, 100, Me.ScaleWidth - 200, Me.ScaleHeight - 200
rtfText.RightMargin = rtfText.Width - 400
End Sub
That completes our overview of Visual Basic projects for now, although there will be more about projects throughout the book. Well turn to an overview of another kind now: discussing topics that impact every chapter in the book. In this overview, were going to cover general Visual Basic programming issues, including Visual Basic conventions, best coding practices, and code optimization. This discussion touches practically every aspect of our book, so its best to consider it first. Visual Basic Programming ConventionsMicrosoft has set up a number of conventions for programming Visual Basic, including naming conventions. These conventions are not necessary if you program alone, but they can still be helpful. If you program as part of a team, these conventions can be very valuable, because they provide clues to a variables scope and type to someone reading your code. Because many Visual Basic programmers work in teams these days, well cover the Microsoft programming conventions here, beginning with variable scope prefixes. Variable Scope Prefixes You use a variable prefix in front of its name to indicate something about that variable. For example, if you have a global variable named ErrorCount, you can use the g prefix to indicate that that variable is global this way: gErrorCount. Microsoft has established scope prefixes for variables as shown in Table 1.3.
The scope prefixes come before all other prefixesand there are many other types, such as variable prefixes, control prefixes, and so on. Well continue with variable prefixes. Variable Prefixes Ideally, variable names should be prefixed to indicate their data type. Table 1.4 lists the prefixes that Microsoft recommends for all the Visual Basic data types.
Here are some prefixed variable names using the recommended variable prefixes: blnTrueFalse 'Boolean intCounter 'Integer sngDividend 'Single Using variable prefixes this way provides some clue as to the variables type, and that can be extraordinarily helpful if someone else will be reading your code. Note that its also a good idea to prefix function names using the above prefixes to indicate the return type of the function. Besides variable prefixes, Microsoft also has a set of prefixes for the standard control types.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |