Printing the contents of a list
This example shows a simple way to print the contents of a list. It first saves the contents of the list to a file that the user selected and then uses a program starter to launch the Windows print command for the file. If you wish to print directly from VA Smalltalk, refer to Programmer Reference.
Begin by creating a new visual part. Add a single-selection list and a button labeled Print. You can populate the list in any fashion. Add AbtProgramStarterApp as a prerequisite, then switch to the Script Editor and create the following script:
printListContents
" Prints the contents of a list by writing each element to a new
line in a file and launching the Windows print command "
 
| dialog aList file fileStream aProgramStarter |
 
" Allow the user to specify the output file from which we will
later print "
dialog := CwFileSelectionPrompter new initialize;
title: 'Save As';
searchMask: '*.*'.
file := dialog prompt.
" File is nil if the user selected cancel "
file isNil ifFalse: [
" The user clicked on OK - assume the file is valid "
" Open the file for output "
fileStream := CfsWriteFileStream openEmpty: file.
 
" Write each element of the list to the file "
aList := (self subpartNamed: 'List1') items.
aList do: [ :each |
fileStream nextPutAll: each; cr.].
fileStream close.
 
" Create a VA Smalltalk Program Starter that"
launches CMD.EXE to do the printing "
aProgramStarter := AbtProgramStarter new.
aProgramStarter
programName: 'cmd.exe';
programInput: '/c print ', file;
startProgram.
 
" Discard the VA Smalltalk Program Starter "
aProgramStarter destroyPart.
]
Last modified date: 07/23/2020