PerfectScript Journal

June 1998: Using the GetData Command

The GetData function is sort of a catch all command that you can use to get lots of different data about your document, or about WordPerfect. The command is used to get information about all the various lists that are stored internally in WordPerfect and in the document.

It is sort of like the system variables, but you can get lots of different information all with one function. For instance, the names of the fonts are stored in a list, as well as the names of all the styles in the document. All the available printers are kept in a list, as are your abbreviations, bookmarks, and information stored in the document summary. This command allows you to access the information in all these lists.

For example, you may need to find out what the names of all the bookmarks in your document are, or you may want to know if a specific bookmark exists in your document. You can use the GetData command to find this information.

Here's an example that will return the name of the second bookmark in the Bookmark List:


GetData(vBooknum; Bookmark!; Count!; CurrentDoc!)
//get the number of bookmarks
IF(vBooknum >=2) //make sure there are some bookmarks
  GetData(vBookname; Bookmark!; Name!; CurrentDoc!; 2)
  //get the name of the 2nd bookmark in the list
ENDIF
          

This next example will get the names of all the bookmarks in the document.


GetData(vBooknum; Bookmark!; Count!; CurrentDoc!)
//find out how many bookmarks exist
IF(vBooknum) //make sure there are some bookmarks
  FORNEXT(x; 1; vBooknum)
    GetData(vBookname; Bookmark!; Name!; CurrentDoc!; x) //get name 
    Type(vBookname)
	HardReturn()      //type the name on the screen
  ENDFOR
ENDIF
          

The first parameter of the GetData command is a variable name. You can use any valid variable name in this parameter. The return value will be stored in this variable. 

The second parameter is the Group. The possible groups are:

Abbreviations!
(the Count!, Name!, and Data! (text) of the abbreviations)
Bookmark!
(the Count! and Name! of the bookmarks)
Printer!
(the Count!, Name!, Type!, and Port! of the printers)
PaperSize!
(the Count!, Name!, Width!, and Length! of the papersizes)
Font!
(the Count! and Name! of the fonts)
Summary!
(the Count!, Name!, Type!, Data!, and Tag! of the summary items)
SummaryTag!
(the Date!, Name!, and Type! of summary items, by their tag names)
OutlineStyles!
(the Count! and Name! of the outline styles)
Styles!
(the Count! and Name! of the non-system styles)
Table!
(the Name! and Type! of the current table)
TableNames!
(the Data! (current cell, row, or column), Name! (cell, row, or column name), and Type!)
ReplaceString!
(the Count! (number of replacement strings in memory), and the Data! (text of the replacement string) )
ODMA!
(get profile information from the document management system, such as SoftSolutions )

For most GetData groups, you should get the Count! first. This initializes the specified group list so that subsequent commands can get data, name, or other items from that group. It also allows you to access information about all the items in a list quickly and conveniently in a FORNEXT loop, as shown in the example above.

If you don't get the count first, you'll often have errors, or even crash WordPerfect.

Below are several examples of using the GetData command:


GetData(vSummaryItems; Summary!; Count!; CurrentDoc!)
Type("Number of summary items: "+vSummaryItems) 
HardReturn()
// Make sure you have a document summary before using!

GetData(vFieldtext; Summary!; Data!; CurrentDoc!; 1)
Type("Text from 1st summary field:"+ vFieldtext) 
HardReturn() 
// Make sure you have a document summary before using!

GetData(vItemTag; Summary!; Tag!; CurrentDoc!; 1)
Type("Tag ID of first summary item: "+vItemTag) 
HardReturn()
// Make sure you have a document summary before using!

GetData(vDescNameTxt; SummaryTag!; Data!; CurrentDoc!; 17)
Type("Text of Descriptive Name field:"+vDescNameTxt) 
HardReturn()
// Make sure you have a document summary before using!

GetData(vPnum; Printer!; Count!; CurrentDoc!)
Type("Number of printers: "+vPnum) 
HardReturn()

GetData(vPrinterName; Printer!; Name!; CurrentDoc!; 1)
Type("Currently-selected printer:"+vPrinterName) 
HardReturn()

GetData(vPrinterType; Printer!; Type!; CurrentDoc!; 1)
Type ("Type of currently-selected printer: "+vPrinterType) 
HardReturn()

GetData(vAbbrevNum; Abbreviation!; Count!; CurrentDoc!)
Type("Number of abbreviations defined:"+vAbbrevNum) 
HardReturn()

GetData(vAbbrevTxt; Abbreviation!; Data!; CurrentDoc!; 1)
Type("Text of the first abbreviation: "+vAbbrevTxt) 
HardReturn() 

GetData(vTable1; Table!; Count!; CurrentDoc!)
Type ("Number of tables in document: "+vTable1) 
HardReturn() // returns an incorrect value 

GetData(vTable2; Table!; Name!; CurrentDoc!;1)
Type("Name of current Table: "+vTable2) 
HardReturn()

GetData(vTable3; Table!; Type!; CurrentDoc!;1)
Type("In a table or floating cell? : "+vTable3) 
HardReturn() 
//Table=true, Floating cell should return false, but doesn't

GetData(vTable4; TableNames!; Data!; CurrentDoc!;1)
Type("Table Name Data: "+vTable4) 
HardReturn() 
//Crashes WP if no names in the table! 
//Will return a value such as ROW 1 
GetData(vTable5; TableNames!; Name!; CurrentDoc!;2)
Type("Name of the table cell/row/column: "+vTable5) 
HardReturn() 
//Crashes WP if no names in the table! 

GetData(vTable6; TableNames!; Type!; CurrentDoc!;3)
Type("Table Name Type: "+vTable6)
//Crashes WP if no names in the table!
//1=Block, 2=Row, 3=Column, etc.
       

Notice that for Summary!, Printer!, Table!, and Abbreviation! in the examples above, we must get the Count! first. This initializes the list so that we can get additional information, and also lets us know how many items exist in a particular group.

Another thing to keep in mind is that if you attempt to get some information for an item that does not exist (for instance, try to get text from the document summary when no document summary exists), a macro error will occur (and in some cases the computer will crash!). To avoid these errors you can test the Count! of Summary! to make sure it does not equal 0 before attempting to get additional information about a list item.

In the case of TableNames!, if no names exist in the current table, or if the cursor is not in a table, WordPerfect will crash altogether. Use care when getting names from a table with GetData.

Care must be taken when using many of the GetData groups. For example, if you are trying to get information about a table with the Table! or TableNames! groups, but no table exists in the document when you use, a PerfectScript error will occur when the macro tries to invoke the command. The same is true with when you use Summary! or SummaryTag!, but no document summary exists in the document.

For more information on GetData, see the WordPerfect Macro Online Help,
or my book.

For information on ordering my book see my web page.

 

Copyright Notice: The information included in the PerfectScript Journal is protected by US Copyright. The author grants you the right to use the routines in your own macros as needed. You may not sell, distribute, or publish them in any form.
If you choose to use the information here, you do so entirely at your own risk. No representations are made regarding the fitness of this information for your   particular purpose, or for your ability or inability to use the information. You   are advised to make backups of all relevant files before implementing any suggestion  or technique.
© Copyright 1998 by J. Jeppson.