Visual Basic 6 Black Book:Text Boxes And Rich Text Boxes
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
Creating A Password Control
Its time to heighten security. Users of your new SuperSpecialDataBase program are worried about the low security of your program, so you decide to add a little security with password controls. Visual Basic will help out.
To convert a standard text box into a password box, you just assign some character (usually an asterisk [*]) to the text boxs PasswordChar property. After that, your program can read the text in the text box, but only the password character will appear on the screen each time the user types a character, as shown in Figure 6.7.
Figure 6.7 Creating a password control.
TIP: You may be concerned that someone can copy the text in a password control and paste it into a word processor to read it, but in fact, Clipboard-handling from the text box is disabled if you are using a password character.
WARNING! A note about security: dont trust the password control too far, because there may be some security loopholes in it that someone out there can exploit. I once wrote an article that included a tiny program to encrypt data in a minimum-security way just to get readers started and got a letter full of angry satisfaction from a code-breaking expert who told me it had taken him only five days (with full-time access to a supercomputer) to break a file encoded with my program.
Controlling Input In A Text Box
The Testing Department is on the phonetheres a bug in your program. The users are getting runtime errors. Dont panic, you say; youll be right down.
You ask the users to duplicate what caused the problem, and you find that theyre trying to add two numbers with your program: 15553 and 955Z. Whats 955Z? you ask. A typo, they say. Is there any way you can restrict user input so this doesnt happen?
Yes, you can. Just use the KeyPress event and check the KeyAscii parameter, which is the ANSI (not ASCII, despite its name) code for the just-struck key. Lets make this clearer with an example; heres how you would restrict users to only typing digits into Text1; all non-digits are simply discarded:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
KeyAscii = 0
End If
End Sub
Besides the KeyPress, text boxes support the KeyUp and KeyDown events, although the KeyPress event is easiest to use, because you get the character code of the typed character passed to you immediately. In the KeyUp and KeyDown events, you are passed a virtual key code you have to translate into a character, after checking to see if the Shift key was down and so on. You can also use the text boxs Change event, which occurs when theres a change in the text boxs text.
Adding An RTF Box To A Form
So youve decided to make the move from text boxes to rich text boxes, and you turn to the toolbox. Wait a minutewheres the Rich Text Box tool in the toolbox? The answer is that its not there until you add it.
To add a rich text box to a form, follow these steps:
1. Select the Project|Components menu item.
2. Click the Controls tab in the Components box.
3. Find and select the Microsoft Rich Textbox Control box, and click on OK to close the Components box.
4. The rich text control now appears in the toolbox (at lower right in Figure 6.1), and you can use it to add rich text boxes to your forms, as shown in Figure 6.8.
Figure 6.8 Displaying rich text in a rich text box.
TIP: What these steps really accomplish is to add the Richtx32.ocx file to your program, and youll need to distribute that file with your program if you use rich text boxes.
Accessing Text In A Rich Text Box
To access text in a rich text box, you can use two properties: Text and TextRTF. As their names imply, Text holds the text in a rich text box in plain text format (like a text box), and TextRTF holds the text in Rich Text Format.
Heres an example where we read the text in RichTextBox1 without any RTF codes and display that text as plain text in RichTextBox2:
Private Sub Command1_Click()
RichTextBox2.Text = RichTextBox1.Text
End Sub
Heres the same operation where we transfer the text including all RTF codesthat is, here were transferring rich text from one rich text box to another:
Private Sub Command1_Click()
RichTextBox2.TextRTF = RichTextBox1.TextRTF
End Sub
Selecting Text In Rich Text Boxes
Rich text boxes support the SetText property just like standard text boxes. However, SetText only works with plain text. You can set the start and end of plain-text selection with the SelStart and SelLength properties.
If you want to work with RTF-selected text, on the other hand, use the SelRTF property. For example, heres how we select the first 10 characters in RichTextBox1 and transfer them to RichTextBox2 using SelRTF:
Private Sub Command1_Click()
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = 10
RichTextBox2.TextRTF = RichTextBox1.SelRTF
End Sub
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:
logika 205208 09 (2)14 (208)205 06slub;wesele;suknie,kategoria,205INDEX (208)04 (208)208 212205 209więcej podobnych podstron