Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Working With Text
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 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
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
Figure 11.4. The completed menu displayed in the Menu Editor.
Other Menu Editor Options
The Menu Editor contains checkboxes for setting several menu item properties. These properties control how the menu item is displayed when the program is running and the user pulls down the menu:
CheckedDisplays a check mark next to the menu item when the menu is displayed.
EnabledIndicates that a menu item is available. If a menu item is disabled, it is grayed out, indicating it is unavailable to the user.
VisibleToggles the display of a menu item. You can hide a menu command by setting its Visible property to False.
You can also edit the structure of a menu as follows:
Click on the up or down arrow to move the current menu item (the one highlighted in the hierarchical list) without changing its left-right position.
Click on the left or right arrow to change a menu items position in the hierarchy. You can have as many as four levels in a menu system.
Click on the Insert button to add a new, blank menu item above the current item.
Click on the Delete button to delete the current menu item.
A few items in the Menu Editor remain to be covered. Ill let you explore them on your own.
Programming The Editor, Part 2
With the two controls placed and the menus designed, we have completed the visual design part of the Baby Editor project. Now we are ready to turn our attention to the code. Lets start with the general declarations section, which is where we place the declarations of global variables and constantsthose variables and constants that must be available in all of the modules procedures. We require two type Boolean flags, plus two type String variables. The general declarations code is shown in Listing 11.1.
In case you dont remember how to display a specific part of a projects code, let me refresh your memory. If the Code Editing window is not open, click on the View Code button in the Project window. At the top of the window, use the Object list to select the object whose code you want to view (in this case, select General) and use the Proc list to select the specific procedure (in this case, Declarations).
Listing 11.1 General declarations in BABYEDITOR.FRM.
Option Explicit
True if the text being edited has changed.
Dim TextChanged As Boolean
True if a file has just been loaded.
Dim JustLoaded As Boolean
Dim FileName As String, OldName As String
Next, we will write the forms Form_Load event procedure, which is triggered when the form is first loaded. With a single-form program such as this one, the form is loaded when the program begins execution. That makes this procedure the ideal place for program initialization codecode that does things like initializing variables and object properties. We have two tasks for Form_Load : setting the two flag variables to False and setting the Common Dialog controls Filter property. I dont want to explain the details of this property setting here, because Ill be devoting a good deal of attention to the Common Dialog control later in the chapter. For now, try to restrain your curiosity. The code for the Form_Load procedure is presented in Listing 11.2.
Listing 11.2 The Form_Load event procedure.
Private Sub Form_Load()
Dim Filter As String
Clear flags.
TextChanged = False
JustLoaded = True
Load filters into the common dialog box.
Filter = Text files (*.txt) | *.txt
Filter = Filter & |Batch files (*.bat) | *.bat
Filter = Filter & |INI files (*.ini) | *.ini
Filter = Filter & |All files (*.*) | *.*
CommonDialog1.Filter = Filter
End Sub
The next procedure, Form_Resize, has the job of setting the size and position of the Text Box control to fill the form. The Form_Resize event procedure is triggered every time the forms size is changed, as well as when it is first displayed. The code for this procedure is shown in Listing 11.3. By setting the Text Boxs Top and Left properties to zero, it positions the Text Box against the top and left edges of the form. By setting the Text Boxs Width and Height properties to the values of the forms ScaleWidth and ScaleHeight properties, the Text Boxs size is made equal to the forms internal display area.
Listing 11.3 The Form_Resize event procedure.
Private Sub Form_Resize()
Size the Text Box to fill the form.
Text1.Top = 0
Text1.Left = 0
Text1.Width = ScaleWidth
Text1.Height = ScaleHeight
End Sub
Note that a form object also has Width and Height properties, but these differ from ScaleWidth and ScaleHeight. The former two properties give the outer dimensions of an object; in the case of a form object, these dimensions include its border, title bar, etc. The ScaleHeight and ScaleWidth properties refer specifically to the forms display areathe area where you can place other objects.
Youre probably wondering why we didnt specify an object for the ScaleWidth and ScaleHeight properties. Why didnt I write the code like this:
Text1.Width = frmBabyEditor.ScaleWidth
Text1.Height = frmBabyEditor.ScaleHeight
In truth, I could have written it this way. The code would have worked fine; it just wasnt necessary. In an objects own event procedures, any reference to a property without an object name automatically refers to the objects own properties.
If you run the project now, youll see that you can enter text into the Text Box. You can also select text using the standard methods: dragging with the mouse or holding Shift while using the cursor movement keys.
TIP: Getting With It
The With statement can save you typing when you are working with several of an objects properties. The general syntax is as follows:
With object
.Property1 = value1
.Property2 = value2
...
End With
Thus, to change several properties of a Text Box object named Text1, you could write:
With Text1
.Text = Hello"
.Visible = True
.Height = 1500
.Width = 4000
End With
Implementing Cut, Copy, And Paste
The first requirement for the Cut, Copy, and Paste operations is taken care of for us by the Text Boxs built-in capabilities. As well soon see, so are most of the other parts.
During program execution, the user can select text in the Text Box using the standard Windows techniques. The Text Box control has a property named SelLength that gives us the length (in characters) of the selected text in the Text Box, and another property named SelText that returns the selected text itself. Its a trivial matter to see if any text is selected (simply verify that SelLength is greater than zero) and, if so, to retrieve it.
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. Read EarthWeb's privacy statement.
Wyszukiwarka
Podobne podstrony:
11 03 200311 03 Zurawie zurawiki dzwigi windy suwniceGinekologia W3 11 03 2014 poród fizjologiczny11 03 08 sem IVTI 98 11 03 B pl(1)Dz U 2004 242 2421 zmiana z dnia 2004 11 0311 03 20100203 11 03 2009, wykład nr 3 , Białka powierzchni komórkowej Cząsteczki adhezyjneHanza KLCW 2007 11 0311 03Benedykt XVI 2011 11 03 – orędzie na Wielki Post w 2012rwyklad farma 11 03 13Wykład 11 03 2012więcej podobnych podstron