Jump to navigation
Jump to search
Regular Output
Description
- Causes text to be displayed in the mainwin. PRINT is also used to send data to a file or device.
- For GUI programs, PRINT sends commands or data to a window or control.
- (Note: The PRINT statement is a very versatile command. It has many uses. If you are just beginning with Just BASIC, you will find the first examples will show the basic uses of PRINT. More advanced uses are shown in the additional examples.)
Syntax
- Note: Expressions may be literal or variable, string or numeric.
To Display Text
- Empty Line
- Literals
- PRINT "Text"
- PRINT 123
- Variables
- PRINT String$
- PRINT Number
- Concatenating
- PRINT String$; Number
- PRINT String$ + String$
- Columnar Output
- PRINT String$, Number
- Suppressing New Line
- PRINT String$;
- PRINT Number;
- PRINT String$; Number;
To Write to a File
- Sequential files (opened for APPEND or for OUTPUT):
- Empty Line
- PRINT #handle, ""
- Line of data
- PRINT #handle, one or more expressions separated by semi-colons (;)
- Printing data, suppressing new line
- PRINT #handle, one or more expressions ending with a semi-colon (;)
- Binary files (opened for BINARY):
- Since printing to binary files does not append new line, (1) and (3) does not apply.
Use with GUI
Long form (outdated):
- PRINT #handle, {command}
- PRINT #handle, {text string} or {literal number}
- PRINT #handle, {var$} or {numVar}
Short form (preferred form): Omits the word "Print" and the comma after #handle.
- #handle {command}
- #handle {text string} or {literal number}
- #handle {var$} or {numVar}
Hints
- Place useful hints about this keyword here
Example
Regular Output
'Printing to the mainwin
print "A printing test"
print "" 'prints a blank line with line feed
print "hello world" 'prints content and LF, CR
print "hello world"; 'semi-colon (;) suppresses line feed
'next printed item will be on same line
print " and this on same line."
end
'using PRINT for columnar output
print "C-1", "C-2" 'A comma at the end of an expression will
'cause output to be printed in columns.
print "C-1",,,"C-4" 'Extra commas bypass that column.
end
Printing to Disk Files
open "addData.txt" for output as #myfile
print #myfile, "Data One" 'data will be stored on disk as one item on one line
print #myfile, "Data Two"; 'semi-colon causes next data item sent to the file
' to be stored on the same line with no space between
print #myfile, "Data Three"
'To separate the data, and provide a way to read data back as individual items,
' print a comma (,) between the items.
print #myfile, "Data Four"; ","; "Last Data"
close #myfile
end
' view file in Notepad, or print contents to see format
GUI Output
' In the GUI environment, printing content or commands to a window or control is also done
' with the PRINT command. To achieve this, the handle of the window or control must be
' included in the statement.
' The following examples show the syntax of a print statement for this use and are not
' complete, working programs.
print #main, "TABLE ONE" 'Printing literal text to a window will work
' only in windows of type "text".
' to print to controls, use the window's handle and the control's extent name
print #main.statictext1, "Item One" 'prints to a statictext control
' with the extent "statictext1"
' Printing a command to a window or control
print #main "trapclose [quit]" 'prints to the window
print #main.textbox1, "" '"commands" the textbox to clear it's contents
'Note: See other BB pages for definitions of controls and commands.
Useful Procedures
' Truncating data in columns in the mainwin
' Often, a "~" character is used to indicate the data has been truncated
name$(1) = "Jackson Brown"
name$(2) = "Elizabeth Warren"
name$(3) = "Gomer Pyle"
for i = 1 to 3
print displayName$(name$(i)), "000";i
next i
function displayName$(n$)
if len(n$) > 12 then
displayName$ = left$(n$,11) ; "~"
else
displayName$ = n$
end if
end function
end
' Output:
' Jackson Bro~ 0001
' Elizabeth W~ 0002
' Gomer Pyle 0003
' Caveats:
' Columnar data in the mainwin works best when mono-spaced font is used.
' Columns produced by using the comma are about 14 spaces wide; some trial
' and error may be required for the number of characters to return with the
' left$() function.
Graphics Method
Description
- This command sends the plotted image to the Windows Print Manager for output. The size argument is optional and is not dependent upon the user's display resolution (See table below).
Syntax
- PRINT #handle, "print"
- PRINT #handle, "print 420"
- PRINT #handle, "print vga"
- PRINT #handle, "print svga"
- PRINT #handle, "print xga"
- #handle "print"
- #handle "print 420"
- #handle "print vga"
- #handle "print svga"
- #handle "print xga"
Hints
- Make sure to have only one FLUSH issued before you print or some of the contents will not be printed.
- If you need more FLUSH commands, use the following approach to get a full printout:
- GETBMP the contents of the graphics control or window
- CLS
- DRAWBMP the previously captured image
- FLUSH
Scaling to full Paper Width Size Pixels any number as specified vga 640 svga 800 xga 1024
Example
nomainwin
' Open a graphics window
open "Draw a Circle" for graphics as #g
#g "trapclose [quit]" ' trap close event
' position pen in center of window and drop pen down
#g "home; down"
' draw a circle with radius of 50 pixels
#g "circle 50"
#g "up" ' raise the pen
' go to location under the circle to print label
#g "goto 125 225"
#g "down" ' put pen down
' write the label "Circle"
#g "\Circle"
#g "flush" ' make the graphics "stick"
#g "print" ' Send drawing to printer
wait ' wait for a user event
' event handler for closing window
[quit]
close #g 'close the graphics window
end
Useful Procedures
' Place a useful function or sub using this keyword here