Liberty BASIC Help Online

Text Window Commands
The commands in this topic work with the text window and texteditor control.  Anything printed to a text window is displayed exactly as sent.  To distinguish commands sent to a text window from text that is to be diplayed in the window, the ! character should be the first character in the string. It is no longer necessary to add a semicolon to the end of a printed command line to suppress a carriage return.  The semicolon at the end of a printed command is now optional.   When printing text, rather than commands, a carriage return is added to the text with each print statement, unless the statement ends with a semicolon.
Note: for instructions on sending text to the printer, see LPRINT.
Using variables in text commands:
Literal values are placed inside the quotation marks:
print #handle, "!line 3 string$"
Variables must be places outside the quotation marks, with blank spaces preserved:
print #handle, "!line ";lineNum;" string$"
See also:  Understanding Syntax - how to use literals and variables in commands.
For example:
'open a text window
    open "Example" for text as #1
'print Hello World in the window    
    print #1, "Hello World"      
'change the text window's font    
    print #1, "!font helv 16 37"  
'read line 1  
    print #1, "!line 1"              
    input #1, string$
    print "The first line is:"
    print string$
    input "Press 'Return'"; r$
'close the window
    close #1
Proper use of semicolons and the 'print' command.
In the following example, semicolons are omitted in printed commands.  They are used to force carriage returns when printing text.  It is also possible to omit the word "print" and to omit the comma after the handle when printing to a text window or texteditor.  This means that the word "print" and the comma following the handle are optional.
open "Example" for text as #1
print #1, "!trapclose [quit]"
'carriage return suppressed by semicolon:
print #1, "Hello";
'this line will have a carriage return:
#1 " World"
'this command omits the word 'print'
#1 "!font courier_new 12"
'print some more text into the window, no carriage return:
print #1, "This is a font called ";
'print text with carriage returns:
print #1, "courier_new."
'blank line:
print #1, ""
#1 "Done!"
close #1 : end
Note: Most of the commands listed below work with windows of type "text" and also with the "texteditor" control except where noted.
Here are the text window commands:
print #handle, "!cls" ;
This command clears the text window of all text.
print #handle, "!contents varname$";
print #handle, "!contents #handle";
This command has two forms as described above.  The first form causes the contents of the text window to be replaced with the contents of varname$, and the second form causes the contents of the text window to be replaced with the contents of the stream referenced by #handle.  This second form is useful for reading large text files quickly into the window.
Here is an example of the second form:
      open "Contents of AUTOEXEC.BAT" for text as #aetext
      open "C:\AUTOEXEC.BAT" for input as #autoexec
      print #aetext, "!contents #autoexec";
      close #autoexec
      'stop here
      input a$
print #handle, "!contents? string$";
This command returns the entire text of the window.  After this command is issued, the entire text is contained in the variable string$.
print #handle, "!copy" ;
This command causes the currently selected text to be copied to the WINDOWS clipboard.
print #handle, "!cut" ;
This command causes the currently selected text to be cut out of the text window and copied to the WINDOWS clipboard.
print #handle, "!font fontName pointsize" ;
This command sets the font of the text window to the specified name and size.  If an exact match cannot be found, then Liberty BASIC will try to match as closely as possible, with size taking precedence over name in the match.  Note that a font with more than one word in its name is specified by joining each word with an underscore _ character.  For example, the font Times New Roman becomes Times_New_Roman, and the font Courier New becomes Courier_New.
print #handle, "!font Times_New_Roman 10";
For more on specifying fonts read How to Specify Fonts
print #handle, "!insert varname$";
This command inserts the contents of the variable at the current caret (text cursor) position, leaving the selection highlighted.
print #handle, "!line n string$" ;
Returns the text at line n.  In the code above, n is standing in for a literal number.  If n is less than 1 or greater than the number of lines the text window contains, then "" (an empty string) is returned.  After this command is issued, the line's text is contained in the variable string$.
This sample code retrieves the contents of line  number 7 and places them into a variable called string$:
    print #textwindow, "!line 7 string$"
print #h, "!lines countVar" ;
This command returns the number of lines in the text window, placing the value into the variable countVar
print #handle, "!modified? answer$" ;
This command returns a string (either "true" or "false") that indicates whether any data in the text window has been modified.  The variable answer$ holds this returned string.  This is useful for checking to see whether to save the contents of the window before closing it.
print #h, "!origin? columnVar rowVar" ;
This command causes the current text window origin to be returned.  The origin is the upper left corner of the texteditor or textwindow.  When a text window is first opened, the result would be row 1, column 1.  The result is contained in the variables rowVar and columnVar.
print #handle, "!origin column row" ;
This command forces the origin of the window to be row and column.  This means that the row and column specified will appear in the upper left corner of the texteditor or text window.  Row and column must be literal numbers.  To  use variables for these values, place them outside the quotation marks, preserving the blank spaces, like this:
print #handle, "!origin ";column;" ";row
print #handle, "!paste" ;
This causes the text in the WINDOWS clipboard (if there is any) to be pasted into the text window at the current cursor position.
print #handle, "!select column row" ;
This command puts the blinking cursor at column rowColumn and row must be literal numbers.  To express them as variables, place the variables outside the quotation marks and preserve the blank spaces, like this:
print #handle, "!select ";column;" ";row
print #handle, "!selectall" ;
This causes everything in the text window to be selected (highlighted).
print #handle, "!selection? selected$" ;
This command returns the highlighted text from the window.  The result will be contained in the variable selected$.
print #handle, "!setfocus";
This causes Windows to give input focus to this control. This means that, if some other control in the same window was highlighted and active, this control now becomes the highlighted and active control, receiving keyboard input.
print #handle, "!trapclose branchLabel" ;
This command tells Liberty BASIC to continue execution of the program at branchLabel if the user double clicks on the system menu box or pulls down the system menu and selects "close."

Copyright (C) 2003 Shoptalk Systems
Liberty BASIC -