Microsoft KB Archive/246088: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "&" to "&")
m (Text replacement - """ to """)
 
Line 66: Line 66:
<pre class="codesample">CLOSE ALL
<pre class="codesample">CLOSE ALL
CLEAR ALL
CLEAR ALL
tSafety = SET(&quot;safety&quot;) &&Store SET status of Safety to a variable
tSafety = SET("safety") &&Store SET status of Safety to a variable
SET SAFETY OFF &&Check to see if the Dcolor table exists
SET SAFETY OFF &&Check to see if the Dcolor table exists
IF FILE(&quot;dcolor.dbf&quot;)
IF FILE("dcolor.dbf")
     USE dcolor EXCLUSIVE
     USE dcolor EXCLUSIVE
ELSE
ELSE
     CREATE TABLE dcolor (dcolor c(20),gcolor g) &&Create and add records if DColor table doesn't exist
     CREATE TABLE dcolor (dcolor c(20),gcolor g) &&Create and add records if DColor table doesn't exist
     INSERT INTO dcolor (dcolor) VALUES (&quot;Red&quot;)
     INSERT INTO dcolor (dcolor) VALUES ("Red")
     INSERT INTO dcolor (dcolor) VALUES (&quot;Green&quot;)
     INSERT INTO dcolor (dcolor) VALUES ("Green")
     INSERT INTO dcolor (dcolor) VALUES (&quot;Blue&quot;)
     INSERT INTO dcolor (dcolor) VALUES ("Blue")
     INSERT INTO dcolor (dcolor) VALUES (&quot;Purple&quot;)
     INSERT INTO dcolor (dcolor) VALUES ("Purple")
     INSERT INTO dcolor (dcolor) VALUES (&quot;Orange&quot;)
     INSERT INTO dcolor (dcolor) VALUES ("Orange")
     INSERT INTO dcolor (dcolor) VALUES (&quot;Yellow&quot;)
     INSERT INTO dcolor (dcolor) VALUES ("Yellow")
ENDIF
ENDIF
_rtfFile = SYS(3)+&quot;.rtf&quot; &&Create a legal file name with a .RTF extension
_rtfFile = SYS(3)+".rtf" &&Create a legal file name with a .RTF extension
*NOTE: The file must have a .RTF extension to work properly
*NOTE: The file must have a .RTF extension to work properly
SCAN &&Create a Richtext OLE bound control in the general field of the dColor table
SCAN &&Create a Richtext OLE bound control in the general field of the dColor table
Line 90: Line 90:
           The big \ul <<ALLT(dcolor.dcolor)>>\ulnone  dog\par}
           The big \ul <<ALLT(dcolor.dcolor)>>\ulnone  dog\par}
     SET TEXTMERGE TO
     SET TEXTMERGE TO
     APPEND GENERAL gcolor FROM &_rtfFile CLASS &quot;RICHTEXT.RICHTEXTCTRL.1&quot;
     APPEND GENERAL gcolor FROM &_rtfFile CLASS "RICHTEXT.RICHTEXTCTRL.1"
ENDSCAN
ENDSCAN
SET SAFETY &tSafety
SET SAFETY &tSafety

Latest revision as of 12:49, 21 July 2020

Knowledge Base


How to apply rich text effects in Visual FoxPro reports

Article ID: 246088

Article Last Modified on 2/17/2005



APPLIES TO

  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 3.0b Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 5.0a
  • Microsoft Visual FoxPro 6.0 Professional Edition
  • Microsoft Visual FoxPro 7.0 Professional Edition
  • Microsoft Visual FoxPro 8.0 Professional Edition
  • Microsoft Visual FoxPro 9.0 Professional Edition



This article was previously published under Q246088

SUMMARY

From time to time it would be good to have the ability to add formatting effects to individual words within Microsoft Visual FoxPro reports. This can be accomplished with the Rich Text ActiveX control, a general field and a OLE bound control on a Visual FoxPro report.

MORE INFORMATION

This example shows how to underline parts of a field from a table and display that formatting on a report. You can apply any effect or combination of effects possible in Rich Text to your example.

  1. Open Visual FoxPro and create a new report.
  2. Add a Picture/Active-X Bound Control to the detail band of the report. Set its FIELD property to Dcolor.gcolor.
  3. Save the report as rtfDemo.
  4. Paste the following code into a new program. Save that program in the same directory as the report, then run it.

    CLOSE ALL
    CLEAR ALL
    tSafety = SET("safety") &&Store SET status of Safety to a variable
    SET SAFETY OFF &&Check to see if the Dcolor table exists
    IF FILE("dcolor.dbf")
        USE dcolor EXCLUSIVE
    ELSE
        CREATE TABLE dcolor (dcolor c(20),gcolor g) &&Create and add records if DColor table doesn't exist
        INSERT INTO dcolor (dcolor) VALUES ("Red")
        INSERT INTO dcolor (dcolor) VALUES ("Green")
        INSERT INTO dcolor (dcolor) VALUES ("Blue")
        INSERT INTO dcolor (dcolor) VALUES ("Purple")
        INSERT INTO dcolor (dcolor) VALUES ("Orange")
        INSERT INTO dcolor (dcolor) VALUES ("Yellow")
    ENDIF
    _rtfFile = SYS(3)+".rtf" &&Create a legal file name with a .RTF extension
    *NOTE: The file must have a .RTF extension to work properly
    SCAN &&Create a Richtext OLE bound control in the general field of the dColor table
        SET TEXTMERGE TO &_rtfFile NOSHOW
        SET TEXTMERGE ON 
        *!!IMPORTANT!! The following richtext formatting line(s) need to be 
             *included as one line in your program.
             \\{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl
             {\f0\fnil\fcharset0 Times New Roman;}}\viewkind4\uc1\pard\f0\fs20
              The big \ul <<ALLT(dcolor.dcolor)>>\ulnone  dog\par}
        SET TEXTMERGE TO
        APPEND GENERAL gcolor FROM &_rtfFile CLASS "RICHTEXT.RICHTEXTCTRL.1"
    ENDSCAN
    SET SAFETY &tSafety
    ERASE &_rtfFile
    
    REPORT FORM rtfdemo PREVIEW NOCONSOLE
    USE
    CLOSE ALL

    When the report is printed, the color is underlined in the text.

    NOTE: In some cases the print preview of RTF formatted text does not look correct. However, when the string is printed, the output is formatted correctly .

    TIP: To generate a string similar to the one in the above code, create a template for your expression in Microsoft WordPad (or other application capable of creating Rich Text Files). Underline, color, and apply any other formatting to your text, then save it to a .RTF file. Open the .RTF file in Notepad and copy/paste the Rich Text code into your Visual FoxPro program.

    (This application requires the RichTX32.OCX control. Visual FoxPro 3.0 and 3.0b do not ship with RichTX32.OCX.)


Keywords: kbhowto kbreportwriter KB246088