Advisor Answers. Using textbox for email address. November, 2005 VFP 9/8



Similar documents
Binding logging code to application code lets you track your application without changing its code

Creating Interactive PDF Documents with CorelDRAW

UNIVERSITY OF CALGARY Information Technologies WEBFORMS DRUPAL 7 WEB CONTENT MANAGEMENT

ADOBE ACROBAT 7.0 CREATING FORMS

Microsoft Expression Web Quickstart Guide

Managing Your Desktop with Exposé, Spaces, and Other Tools

(These instructions are only meant to get you started. They do not include advanced features.)

1. To start Installation: To install the reporting tool, copy the entire contents of the zip file to a directory of your choice. Run the exe.

Block Unwanted Web Pages Limit to only one domain

Writer Guide. Chapter 15 Using Forms in Writer

Creating Hyperlinks & Buttons InDesign CS6

Easy WP SEO User Guide. Version 1.5

Triggers & Actions 10

HOUR 3 Creating Our First ASP.NET Web Page

FrontPage 2003: Forms

Content Author's Reference and Cookbook

Handout: Word 2010 Tips and Shortcuts

6. If you want to enter specific formats, click the Format Tab to auto format the information that is entered into the field.

Chapter 15 Using Forms in Writer

AppShore Premium Edition Campaigns How to Guide. Release 2.1

Excel 2003 Tutorial I

Windows XP Pro: Basics 1

WebFOCUS BI Portal: S.I.M.P.L.E. as can be

12Planet Chat end-user manual

Please select one of the topics below.

ASSET CASE MANAGEMENT 3-1 STRUCTURE OF SYSTEM FUNCTIONS

WORDPAD TUTORIAL WINDOWS 7

Joomla! 2.5.x Training Manual

Microsoft Word 2010: How to Resize and Move Clip Art

How To Change Your Site On Drupal Cloud On A Pcode On A Microsoft Powerstone On A Macbook Or Ipad (For Free) On A Freebie (For A Free Download) On An Ipad Or Ipa (For

Using Form Scripts in WEBPLUS

Administrator s Guide ALMComplete Support Ticket Manager

FirstClass FAQ's An item is missing from my FirstClass desktop

3. Surfing with Your Tablet

JOOMLA 2.5 MANUAL WEBSITEDESIGN.CO.ZA

Hypercosm. Studio.

Acrobat PDF Forms - Part 2

Alfresco Online Collaboration Tool

The Settings tab: Check Uncheck Uncheck

ITCS QUICK REFERENCE GUIDE: EXPRESSION WEB SITE

Shopping Cart Manual. Written by Shawn Xavier Mendoza

Creating and Using Links and Bookmarks in PDF Documents

Website Creator Pro Quick Reference Guide. Version: 0.5

How to create PDF maps, pdf layer maps and pdf maps with attributes using ArcGIS. Lynne W Fielding, GISP Town of Westwood

Creating a website using Voice: Beginners Course. Participant course notes

Microsoft Publisher 2010 What s New!

Create Charts in Excel

Document Revision Date: August 14, Create a New Data Protection Policy in the Symantec.cloud Management Portal

CMS Training Manual. A brief overview of your website s content management system (CMS) with screenshots. CMS Manual

PDF Expenses Form. Projects 1

Using an Access Database

Chapter 12 Creating Web Pages

Microsoft Excel 2010 Training

Venza Group. Learning Management System (LMS) Login and Dashboard Guide

Simple Document Management Using VFP, Part 1 Russell Campbell russcampbell@interthink.com

Weebly.com First Steps

Answers Implementation Guide

Designing and Implementing Forms 34

CORSAIR GAMING KEYBOARD SOFTWARE USER MANUAL

Welcome to CSU The Software Used To Data Conference.

Access to NetSuite should already be configured and working normally before proceeding with this integration.

Macros in Word & Excel

The Power Loader GUI

DESIGN A WEB SITE USING PUBLISHER Before you begin, plan your Web site

Mac OS X (Leopard) The Basics

Outlook . User Guide IS TRAINING CENTER. 833 Chestnut St, Suite 600. Philadelphia, PA

MAXMAILER USER GUIDE

Where do I start? DIGICATION E-PORTFOLIO HELP GUIDE. Log in to Digication

1. Tutorial - Developing websites with Kentico Using the Kentico interface Managing content - The basics

Managing Your ecommerce Store

Microsoft Windows Overview Desktop Parts

Learning Activity Management System TEACHER S GUIDE. October 2006 LAMS V2.0 for The First International LAMS Conference 2006

Getting Started Guide. Chapter 14 Customizing LibreOffice

Dashboard Skin Tutorial. For ETS2 HTML5 Mobile Dashboard v3.0.2

Vote 411 User Guide HOW TO LOG IN:

A L E P H 5 0 0, V E R S I O N Vendors in Acquisitions

Red Hat Linux 7.2 Installation Guide

Form And List. SuperUsers. Configuring Moderation & Feedback Management Setti. Troubleshooting: Feedback Doesn't Send

Version 7 Editor s Manual

Introduction to Programming with Xojo

Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick Reference Guide

Writer Guide. Chapter 15 Using Forms in Writer

A Tutorial on dynamic networks. By Clement Levallois, Erasmus University Rotterdam

Ansur Test Executive. Users Manual

MICROSOFT OUTLOOK 2010 WORK WITH CONTACTS

Dreamweaver and Fireworks MX Integration Brian Hogan

BUILDING APPLICATIONS USING C# AND.NET FRAMEWORK (OBJECT-ORIENTED PROGRAMMING, X428.6)

General Outlook Tips Last Name first or last name

Intellect Platform - Tables and Templates Basic Document Management System - A101

Intro to Excel spreadsheets

Most of your tasks in Windows XP will involve working with information

Vertigo's Running Dedicated Server HOWTO (v1.2)

efiletexas.gov Review Queue User Guide

Chapter 9 Slide Shows

No restrictions are placed upon the use of this list. Please notify us of any errors or omissions, thank you,

Microsoft Office PowerPoint 2013

Tutorial: Creating a form that s the results to you.

Installing Ubuntu. Obtaining files required

Table of Contents. Introduction: 2. Settings: 6. Archive 9. Search Browse Schedule Archiving: 18

Getting Started with Web Based Data Reporting. November, 2005

Transcription:

November, 2005 Advisor Answers Using textbox for email address VFP 9/8 Q: I need to have a textbox configured so that when the user types in an email address, he can click on the email address and go to the default email program. I know you can set the textbox property EnableHyperlinks to True and the put "mailto:" in front of the email address and it will work that way. But I don't want users to have to type "mailto:" in front of the email address. James Lansden (via Advisor forums) A: This is an intriguing little problem. While setting up the Click to start a new email is fairly simple, getting the textbox to behave as users expect is a little trickier. There are a number of prefixes you can add to the front of a string to indicate that the string is a hyperlink. In addition to "mailto:", you can use "http://" to indicate a web address, "ftp://" to indicate a file transfer address and "news:" to point to a newsgroup. Let me start with a quick look at the EnableHyperlinks property. Added in VFP 8, this property of textboxes and editboxes determines whether strings that look like links are treated as links. When EnableHyperlinks is.t., any string beginning "www." or starting with one of the other link prefixes is underlined and clickable. Depending on the _VFP.EditorOptions setting, you can execute the link with either Ctrl+Click or just a click. So why not use this property? As you note, the problem is that it requires the prefix for anything other than a web address beginning with "www." Most users aren't familiar with the "mailto:" prefix, so you rightly don't want them to have to type it. Fortunately, as is so often the case with FoxPro, there are alternatives. My immediate reaction to your problem was that you could handle it in just a few steps. First, make sure you actually have an email address. If so, add the "mailto:" tag at the front. Then, use ShellExecute to call on the default email client. In fact, this is more or less the outline of

the solution, but as I worked on it, I realized that it could be far more generic. ShellExecute is an API function that lets you run the default application for a file name or string. Rather than using it directly, you can take advantage of the _ShellExecute class in the FoxPro Foundation Classes. This class handles all the details of calling ShellExecute. All you have to do is instantiate it and call its ShellExecute method, passing the appropriate string. The basic strategy for turning a textbox value into a link is the same no matter which type of link it is. So, I created an abstract textbox subclass that contains almost all the code for dealing with links. Then, I subclassed for different types of links. The abstract class is called txtlink. It has four custom properties: cprefix the prefix to add for this type of link. Empty in txtlink and set in the subclasses. cunderline the name of a line object created to serve as the underline for this textbox. lislink indicates whether the current value of the textbox is a link of the appropriate type. oshellexecute object reference to a _ShellExecute object. Two custom methods combine to execute the appropriate action when the user clicks on the textbox value. FollowLink adds the prefix, if necessary, and calls the _ShellExecute object's ShellExecute method. LOCAL clink, nprefixlen nprefixlen = LEN(This.cPrefix) IF UPPER(LEFT(This.Value, nprefixlen))== ; UPPER(This.cPrefix) clink = This.Value ELSE clink = ALLTRIM(This.cPrefix) + ALLTRIM(This.Value) IF This.GetShellExecute() This.oShellExecute.ShellExecute(cLink) GetShellExecute makes sure there's a reference to a _ShellExecute object, instantiating one if necessary. Once it's instantiated, the reference is saved, so that future clicks can use the same _ShellExecute object.

IF VARTYPE(This.oShellExecute) <> "O" This.oShellExecute = NEWOBJECT("_ShellExecute", ; HOME() + "Ffc\_Environ.vcx") The Click method calls this code: IF This.lIsLink This.FollowLink() Another custom method, CheckFormat, examines the textbox's value to see whether it has the appropriate format for a link of the specified type. This method is abstract at this level; it needs to be filled in with the appropriate test in each subclass. The remaining code in txtlink deals with visual issues. To match user expectations, when the textbox contains a link, the value should be underlined. In addition, when clicking the value will fire the link, the mouse pointer should indicate that. MouseEnter and MouseLeave handle the mouse pointer. MouseEnter checks whether the current value is a link and if so, switches to the arrow pointer: IF This.lIsLink This.MousePointer = 15 MouseLeave resets the pointer to its default value: This.MousePointer = 0 Underlining the value to indicate a link is a little more complicated. My first approach used FontUnderline and InputMask to make the textbox underline itself. It turned out that getting it exactly right was difficult. Instead, when the value of the textbox constitutes a link, I display a line object beneath it. InteractiveChange handles adding and resizing the line, as well as hiding it when the value no longer constitutes a link. Here s the code: LOCAL ounderline, lchanged, cstyle This.lIsLink = This.CheckFormat() IF This.lIsLink cstyle = "" IF This.FontBold cstyle = cstyle + "B"

IF This.FontItalic cstyle = cstyle + "I" IF EMPTY(This.cUnderline) This.cUnderline = "linunderline" + ; ALLTRIM(This.Name) ThisForm.AddObject(This.cUnderline,"Line") ounderline = EVALUATE("ThisForm." + This.cUnderline) WITH ounderline.left = This.Left + 5.Top = This.Top + FONTMETRIC(1, ; This.FontName,This.FontSize,cStyle)+ 1.Height = 0.BorderColor = RGB(0,0,255).Visible =.T. * Adjust form font, if necessary IF ThisForm.FontName <> This.FontName OR ; ThisForm.FontSize <> This.FontSize OR ; ThisForm.FontBold <> This.FontBold OR ; ThisForm.FontItalic <> This.FontItalic * Save current settings lchanged =.T. WITH ThisForm.LockScreen =.T. cfontname =.FontName nfontsize =.FontSize lfontbold =.FontBold lfontitalic =.FontItalic.FontName = This.FontName.FontSize = This.FontSize.FontBold = This.FontBold.FontItalic = This.FontItalic ENDWITH.Width = ThisForm.TextWidth(ALLTRIM(This.Value)) IF ounderline.width > This.Width - 10 * Max line out at end of textbox ounderline.width = This.Width - 10 * Now reset if necessary IF lchanged WITH ThisForm.FontName = cfontname.fontsize = nfontsize.fontbold = lfontbold.fontitalic = lfontitalic.lockscreen =.F.

ENDWITH ENDWITH ELSE IF NOT EMPTY(This.cUnderline) ounderline = EVALUATE("ThisForm." + ; This.cUnderline) ounderline.visible =.F. Keeping the line displayed is a little tricky. A number of things can make it disappear. To ensure it s visible when it should be, I added a method called RepaintLine and call it from the Click and KeyPress methods. RepaintLine is simple: IF NOT EMPTY(This.cUnderline) ounderline = EVALUATE("ThisForm." + This.cUnderline) ounderline.visible =.t. KeyPress requires a little special handling. You need to call RepaintLine after the keystroke has been processed. This code does the trick: LPARAMETERS nkeycode, nshiftaltctrl DODEFAULT(nKeyCode, nshiftaltctrl) IF (m.nkeycode==9 and m.nshiftaltctrl==0) OR ; (m.nkeycode==15 and m.nshiftaltctrl==1) * Do nothing to make TAB and SHIFT+TAB work ELSE NODEFAULT This.RepaintLine() Even with all this, there's still one situation where the line disappears. When the value is long enough to scroll the textbox, the line disappears until the textbox loses focus. I've tried a couple of tricks to get it back, but nothing works reliably, so make sure to size the textbox large enough for the expected contents. (My thanks to Christof for suggesting the line object and helping me work out some of the visual issues.) With all this code in place, the subclasses of txtlink don't require much work. Set cprefix to the appropriate string, and put code in CheckFormat to check for a valid link of the specified type.

I created two subclasses, txtmailtolink and txthyperlink. In txtmailtolink, cprefix is set to "Mailto:" and CheckFormat contains very basic code to check for an email address. A string is considered a valid email link if it contains the character "@", followed at some point by a period. (For a more rigorous approach, see Pamela's answer in the July, 2005 issue.) LOCAL lreturn, cvalue lreturn =.F. cvalue = This.Value IF "@"$cvalue AND "."$SUBSTR(cValue, AT("@", cvalue)) lreturn =.T. RETURN lreturn In txthyperlink, cprefix is set to "http://" and CheckFormat contains code that checks that the string either contains a period or begins "http". Again, you may want to apply a more rigorous test. It doesn't check for "www" because some web addresses don't require that string. * Check whether current value is a web address. LOCAL lreturn, cvalue cvalue = This.Value lreturn =.F. IF "."$cvalue OR UPPER(LEFT(cValue, 4))="HTTP" lreturn =.T. RETURN lreturn All three classes (txtlink, txtmailtolink and txthyperlink in WebControls.VCX) are included on this month's Professional Resource CD, along with a very simple form that demonstrates their use. I'll leave it to you as exercise to create the ftp and news subclasses. Tamar