026 029




Visual Basic 6 Black Book:Visual Basic Overview
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




Note the last of the statements, Startup=“Sub Main”. This indicates that this program starts with a Main() procedure, not a startup form (we’ll 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 it’s 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. We’ll turn to an overview of another kind now: discussing topics that impact every chapter in the book. In this overview, we’re 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 it’s best to consider it first.

Visual Basic Programming Conventions
Microsoft 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 variable’s scope and type to someone reading your code. Because many Visual Basic programmers work in teams these days, we’ll 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.
Table 1.3 Variable scope prefix conventions.

Scope
Prefix

Global
g

Module-level or form-level
m

Local to procedure
None

The scope prefixes come before all other prefixes—and there are many other types, such as variable prefixes, control prefixes, and so on. We’ll 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.

Table 1.4 Variable prefixes.

Data Type
Prefix

Boolean
bln

Byte
byt

Collection object
col

Currency
cur

Date (Time)
dtm

Double
dbl

Error
err

Integer
int

Long
lng

Object
obj

Single
sng

String
str

User-defined type
udt

Variant
vnt

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 variable’s type, and that can be extraordinarily helpful if someone else will be reading your code. Note that it’s 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.



Previous
Table of Contents
Next






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.



Wyszukiwarka

Podobne podstrony:
026 029
E E 029
C I 026
026 027
Lesson Plan 029 Text
v 01 029
v 04 029
I E 029
027 029
029 Obcy Prąd
v 06 026
026 Prawo w prawie R Sobanski

więcej podobnych podstron