12
Introduction to Programming with Vi sual Basic 6.0 by McKeown and Pierc y 1 Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu System s Creating a Memo Editor Using the C lipboard Chapter 8: Security, Menus, and Files

Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Embed Size (px)

Citation preview

Page 1: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

1Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

Chapter 8:Security, Menus, and Files

Page 2: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

2Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

Security• Passwords are often used to control access to a

computer or software program.• Passwords should be at least 6 characters in

length and something that cannot be easily guessed.

• It should not be possible to move, resize, or bypass the password form in VB and it should be the Startup object.

• The Tag property for a textbox can be used for the password and the PasswordChar property can be used to disguise the password as it is entered.

• A user should be given a set number of “chances” to enter the correct password.

Page 3: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

3Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

Menu Systems in VB• A menu system for a form can be created using the

Menu Editor.• Menu bar options as well as submenus can be

created with this editor.• Menu and submenu items have caption and name

properties (the prefix is mnu).• Code is written for menu items just like for other

event procedures.• Menu options are always click events.• Most menus contain File and Help menu bar

options in addition to others specific to the application.

Page 4: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

4Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

Menu Editor

Page 5: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

5Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

Creating a Memo Editor• Creating a memo editor in VB involves using

a textbox as the location of the text and a menu system for the various editor commands.

• The textbox should have its MultiLine property set to true and its ScrollBars property set to vertical.

• The Form_Resize event occurs when the user displays a textbox--it can be used to cause the memo text box to fill its form by setting the Height and Width properties to ScaleHeight and ScaleWidth.

Page 6: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

6Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

The Memo Editor File Menu

• The File Menu should have options to begin a new memo, open an existing memo, save a memo under the current name or a new one, close the memo, print it, or exit the memo editor.

• Key to the File Menu is the use of the common dialog control which must be added to the Toolbar with the Project|Components VB menu option before being added to the form.

• The common dialog control (with dlg prefix) can be used to open or save files with the ShowOpen and ShowSave methods.

Page 7: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

7Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

Plan for Vintage Videos

Password form (Startup Form)

frmVintage (menusystem)

VideoSearchform

Memoform

LegendRental processMenu selections

MemberSearchform

Aboutform

Page 8: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

8Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

Saving a Memo• The Filter property of the common dialog

control is used to display a list of files.• It has the form: dlgName.Filter = “description1|filter1|description2|filter2|etc”

• The FilterIndex property determines the default file type.

• When a file is selected or a filename entered, this becomes the Filename property for the dialog box.

• The FreeFile function returns an unused file number and the On Error Goto statement causes control to jump to a label when an error is encountered. Both are useful in working with files.

Page 9: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

9Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

Other File Operations

• A file can be opened from a common dialog box with the ShowOpen method.

• The contents of the file can be input using the Input$ function:

Input$(number, #filenumber) where number = number of characters in file that

is identified by #filenumber.• The LOF(FileNumber) function can be used to

determine the number of characters in a file.• A memo can be saved by printing its contents to a

file—it is common to query the user to save the file if it has been changed.

Page 10: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

10Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

The Memo Editing Submenu

• Typical editing options are Cut, Copy, and Paste.

• All three use the Clipboard object to temporarily save information.

• The Clipboard SetText method transfers selected text to the clipboard and the GetText method retrieves text from clipboard.

• The Clipboard Clear method clears the Clipboard.

Page 11: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

11Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

Using the Clipboard

Page 12: Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

12Copyright © 2001 by Wiley. All rights reserved.

Chapter 8:Security, Menus, and Files

Security

Menu Systems

Creating a Memo Editor

Using the Clipboard

The Memo Format Submenu

• Formatting of text in the memo involves changing the Font and Style of the text.

• Menu control arrays are used to display different types of fonts and styles.

• The FontName property of the memo textbox determines the font type.

• FontBold, FontItalics, FontUnderline properties of the textbox control the style of the text.