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 OS/2 print command for the file. If you wish to print directly from VisualAge, refer to IBM Smalltalk Programmer's 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 OS/2 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 = nil) 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 VisualAge Program Starter " aProgramStarter := AbtProgramStarter new. " Launch CMD.EXE to do the printing " aProgramStarter programName: 'cmd.exe'; programInput: '/c print ', file; startProgram. " Discard the VisualAge Program Starter " aProgramStarter destroyPart. ]