_CLIPTEXT
Use the _CLIPTEXT system variable to read and write
text to the clipboard. For example a button on a Customer form can assemble the
four lines of the address into a block
of text on the clipboard:
Declare laLines[4]
laLines = ""
lnLine = 1
If Not Empty(Address1)
laLines[lnLine] = Alltrim(Address1)
lnLine = lnLine + 1
EndIf
If Not Empty(Address2)
laLines[lnLine] = Alltrim(Address2)
lnLine = lnLine + 1
EndIf
If Not Empty(Town)
laLines[lnLine] = Alltrim(Town)
lnLine = lnLine + 1
EndIf
If Not Empty(County)
laLines[lnLine] = Alltrim(County)
lnLine = lnLine + 1
EndIf
_CLIPTEXT = laLines[1] + Chr(13) + ;
laLines[2] + Chr(13) + ;
laLines[3] + Chr(13) + ;
laLines[4]
The user can switch to Word and paste the block as the header of a letter or go
to Excel and paste the address into an invoice.
This example uses CHR(13) to insert a carriage return between each field so that the address
will paste as four lines in Word or Excel. If you use CHR(9) to insert tab characters then
the address will paste as four cells on the same line in Excel.
DataToClip()
DataToClip is a method of the application object or the
_VFP system variable. It copies data
from the current work area onto the clipboard. If the TasTrade Customer table is open then
the command
_vfp.DataToClip()
followed by CTRL+V will put the following text onto the clipboard and paste it back into
the Command Window:
There's not enough space to show the entire output but every field of row of the table has been
placed on the Clipboard. Fields are separated by a single space and each record is on a new line.
The Cust_ID field is six characters wide. Each ID is only five characters long so there is a
trailing space in the field followed by the space which separates fields. This screen shot is
from VFP 9 with the View White Space option selected.
Parameters
DataToClip() accepts up to three parameters:
- cAlias: Copy records from this work area
- nRecords: Copy a specific number of records
- nFormat&tab: 1=Delimit with spaces, 3=Delimit with tabs
Notes
There are some annoying limitations to DataToClip():
- The first line of the output will always be the field names.
- There is no way of selecting which fields will be copied.
-
Memo fields are represented as 'Memo' or 'memo' depending on
whether they hold any text.
- General fields are not copied
The best way to use DataToClip() is in conjunction
with an SQL statement which will select the fields and records required into a
cursor.
Finally, note that DataToClip() does not behave like
a traditional FoxPro command. It cannot accept a FOR clause and the act of copying
to the clipboard does not move the record pointer.