Tech Tip: Utility Method: List Box to Pasteboard
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: June 9, 2011
This method will copy data from a List Box to the Pasteboard. Pass a pointer to the List Box variable to the method. The default delimeters are Tab and Carriage Return. You can optionally specify the delimieters.
Interestngly enough, the feature that makes this method much easier is the ability to pass a string to the String command. Thus there is no need to check the type of the List Box column; just pass everything to String.
C_POINTER($1;$lbPointer_p) C_TEXT($2;$columnSeparator_t) C_TEXT($3;$rowSeparator_t) C_LONGINT($i;$numRows_l) C_LONGINT($j;$numCols_l) C_TEXT($theData_t) ARRAY TEXT($colNames_at;0) ARRAY TEXT($headerNames_at;0) ARRAY POINTER($colVars_ap;0) ARRAY POINTER($headerVars_ap;0) ARRAY BOOLEAN($colsVisible_ab;0) ARRAY POINTER($styles_ap;0) $lbPointer_p:=$1 If (Count parameters>1) $columnSeparator_t:=$2 $rowSeparator_t:=$3 Else $columnSeparator_t:=Char(Tab) $rowSeparator_t:=Char(Carriage return) End If ` Note this is one line. LISTBOX GET ARRAYS($lbPointer_p->;$colNames_at;$headerNames_at;$colVars_ap;$headerVars_ap;$colsVisible_ab;$styles_ap) $numRows_l:=Size of array($colVars_ap{1}->) $numCols_l:=Size of array($colNames_at) For ($i;1;$numRows_l) For ($j;1;$numCols_l) If ($colsVisible_ab{$j}=True) If ($j#1) $theData_t:=$theData_t+$columnSeparator_t End If $theData_t:=$theData_t+String($colVars_ap{$j}->{$i}) End If End For If ($i<$numRows_l) $theData_t:=$theData_t+$rowSeparator_t End If End For SET TEXT TO PASTEBOARD($theData_t) |