Examples

This chapter is divided in two parts:

Proteus code fragments

Print lines longer than 72 characters:

IF GT(STRLEN(L), 72)
  PRINTLN L
FI

Print in reverse order all the fields (separated by ',') on every line:

H = TOKNEW(L, ",")
FOR X = TOKNUM(H) TO 1 STEP -1
  PRINT TOKGET(H, X)
NEXT
PRINTLN ""
TOKFREE(H)

Sum the numbers in the first column (separated by ',') and print total and average:

Total = ADD(Total, TOKEN(L, 1, ","))
IF EOF
  PRINTLN "The sum is " Total ", the average is " FDIV(Total, N)
FI

Copy a C program and insert the available include files:

NewL = LTRIM(L, " ")
IF STREQ(TOKEN(NewL, 1, " "), "#include")
  File = STRIPQUOTES(TOKEN(NewL, 2, " "))
  IF EQ(ISFILE(File), 1)
    FINSERT(File)
    IGNORE
  FI
FI
PRINTLN L

Print all the lines where the first field is different from the previous one:

Field1 = TOKEN(L, 1, ",")
IF STRNEQ(Field1, Prev)
  PRINTLN L
FI
Prev = Field1

Convert a date from the format DATE_TYPE to the format YY[YY]MMDD:

NewDate = STRTRAN(DCONVDATE(Date, 2), "/", "")

Full Proteus programs

Many examples are included in the Proteus package, so that a new user can learn how to use the language and take advantage of these scripts for developing new applications.

The following programs are located in the folder samples of the standard distribution; by clicking on the name on the left you can examine the source code:

437tolat.prt
transforms input into output by mapping characters from Codepage 437 to Iso Latin 1; demontrates mapping functions
arc.prt creates an archive file including all files specified, which can be later extracted by using dearc.prt; demonstrates file functions
asc2ebcd.prt translates input into output by mapping characters from ASCII encoding to EBCDC encoding (used by IBM® AS/400™); use ebcd2asc.prt to reverse the operation. Demontrates mapping functions
ascstat.prt
displays a graph (LENGTH columns wide) that represents the relative frequency of characters found in the specified file; output is written to console. Demonstrates functions on arrays, command line parameters, formatting results, traversing strings
bingo.prt
random drawing to console of numbers from 1 to 90 (no re-insert). Demonstrates queues, arrays, random number generator, UDF
cb1000.prt emulates keyboard by entering data coming from a device connected through an Ethernet Client Bridge (like Symbol CB1000). For the program to work correctly, it is necessary that the device be configured so that it accepts connections from the PC where this program is running. This program can be installed as a script for Proteus Service. Demonstrates: socket functions, keyboard emulation functions.
cb1000db.prt save to READINGS.MDB the data arriving from a device connected through an Ethernet Client Bridge (like Symbol CB1000). For the program to work correctly, it is necessary that the device be configured so that it accepts connections from the PC where this program is running. This program can be installed as a script for Proteus Service. Demonstrates: socket functions, DAO functions.
check.prt verify that the specified file does not contain characters outside of the ASCII range 32-126, 13, 10. Demonstrates part of the string functions.
checkpar.prt
verify that the number of open parenthesis ('(', '[', '{') matches the number of closing parenthesis (')', ']', '}'); parenthesis inside strings are ignored. No output file is produced; messages are sent to console. Demonstrates stacks, string functions, UDFs ONSTART and ONEND
chgdat2.prt
change in each line the first date found from the format 'dd/mm/yy[yy]' to the format 'dd mmm yyyy'; the date must use at least one of the separators in Seps (which must also include ' '). Demonstrates functions on dates, the static tokenizer, the predefined identifier MONTHS
chgdate.prt
change each date from the format 'dd/mm/yy' to the format 'dd mmm yyyy'; the date must use at least one of the separators in Seps (which must also include ' '). Demonstrate the dynamic tokenizer, REXMATCH, several string functions
clipboard.prt
Windows™ clipboard example; demonstrate how it is possible to invoke external functions, compiled into a DLL. See the chapter on the external functions for additional details
codice32.prt functions for encoding/decoding Code 32 (Italian Pharmaceutical).
codqt.prt accept code/quantity and save them to file operator.TXT; demonstrates many interactive functions.
convert.prt convert the input file (binary) into an array that can be used inside a "C" program.
crc32.prt
use the function CRC32 to calculate the 32 bit Ansi X3.66 cyclic redundancy check on the first file specified; CRC is also calculated by padding file to multiple of 128 and 1024 bytes with character ASCII 26
dbfcreat.prt create a DBF file from a text file. The database has two character fields: "CODE" (8 characters) and "DESC" (30 characters); the text file holds CODE in the first 8 characters and DESC in the remaining characters. Data are sorted by using an AVL before being inserted into the database. Demonstrates how to convert Proteus numbers to WORD/DWORD and vice versa.
dbfdump.prt print out the structure of a DBF file and its contents
dearc.prt extract files from an archive created with arc.prt. The files are extracted in the current directory.
decnum.prt
demonstration of a user library: UDF that prints integer numbers with thousand separators; support three types of alignment: centered, left justified, right justified
decrypt.prt
use the function DECRYPT to decrypt the file using the keys specified; if you need to specify more than one key, enclose them between double quotes. Use encrypt.prt to create encrypted files
demime64.prt
Mime Base 64 decoder for single section, MIME-64 encoded files; use mime64.prt to encode the file
denum.prt remove all line numbers from source file, writing result to destination. Source file must be a BASIC file with line numbers.
detab.prt
remove tabs using a column interval of 8; demonstrates function DETAB
doc.prt
extract documentation (between directives !bdoc and !edoc ) and (optionally) remarks from the specified Proteus files; delete directives and initial remark character (; and #)
dynaset.prt shows an example of Dynaset, obtained through a query on Sql Server. The code extract all customers (CFANAGRA) whose documents (DOC) have in their rows (DOCRIGHE) a particular article; the names of the customers found are saved to a text file, where each field is separated from the next by the character "|". Demonstrates DAO functions.
ebcd2asc.prt transforms input into output by mapping the characters from EBCDC (used by IBM® AS/400™) to ASCII encoding. Use asc2ebcd.prt to reverse the operation. Demonstrates mapping functions.
encrypt.prt
use the function CRYPT to encrypt the file with the specified keys; if you need to specify more than one key, enclose them between double quotes. Use decrypt.prt to decrypt the files created by this script.
entab.prt
replace spaces with tabs, using a column interval of 8. Demonstrates the function ENTAB
extfunc.prt demonstrate how it is possible to invoke an external function, compiled into a DLL. See the chapter on the external functions for additional details
fact.prt
ignore input file and print out factorial of numbers from Start to End. Demonstrates the library function FACT
filefunc.prt
functions used to verify and split file names (DOS, Windows™, Unix™); demonstrates a user library
getch.prt display the values returned by GETCH for each key pressed, until the user presses ESC.
glob.prt
demonstrates a user library: UDF to obtain into an array a list of files corresponding to spec
hexdump.prt this program prints out in readable format (hexadecimal) the contents of the specified file
htmindex.prt
create a new file including all bookmarks found inside HTML files matching specifications; this program was used to create an early version of the index ad the end of the Proteus Manual. Demonstrates directory functions, reading lines from files, REXMATCH and several string functions
latto437.prt
transforms input into output by mapping characters from Iso Latin 1 to Codepage 437; demonstrates mapping functions
liner.prt
copy each line, adding to the left its number; demonstrates re-using the same source file and the UDF ONEND
listdup.prt finds identical files with different names in the directory specified; demonstrates using CRC32
matrix.prt
demonstration of a user library; UDFs to manipulate bidimensional matrices (simulating them using arrays)
mdbdump.prt displays the contents of all the tables included in the database specified as the first parameter. Demonstrates DAO functions.
mime64.prt
write to output an encoded Mime Base 64 version of the first file specified. Use demime64.prt to decode the files created
mulblnk.prt
replace each space with two spaces; add: two spaces before and after each line, two spaces after '(', two spaces after ')', two spaces before and after ','. When run against a correct Proteus program, outputs a valid Proteus program that, when executed, produces the same results as the original, except for strings (whose size increases).
myfact.prt
ignore input and print out factorial of numbers from Start to End. Demonstrates the usage of recursive UDFs
palind.prt
print out all the palindromes longer than two characters found in input. Demonstrates the static tokenizer, the function REVERSE, the usage of a UDF
pctune.prt this program plays a melody in RTTTL format through PC speaker. Demonstrates using the function BEEP.
ping.prt pings a remote address, displaying response times, until the user presses Esc on the keyboard. Demonstrates using socket functions and how to convert Proteus numbers to WORD/DWORD and vice versa.
prnform.prt
CGI script sample: receive a form and returns an HTML page with field values
protform.prt
pretty-printer for Proteus programs: add standard formatting, keeping line length below 75 characters; vanilla syntax check. When run against a correct script, returns a program functionally equivalent; demonstrates:
prt2htm.prt
convert a Proteus program (.prt) into a HTML file, adding tags for syntax highlighting. The parameter "ISO" allow for PC 437 to ISO Latin 1 conversion during formatting. This program was used to format all the examples in this manual; a variant, that alphabetically sorts the HTML files produced and links one to the other, has created the samples in this chapter
remblnk.prt
remove all blank and empty lines; very basic example
remc.prt
remove "C" remarks. Demonstrates many string functions
remcpp.prt
remove "C++" remarks. Demonstrates many string functions
remvb.prt remove remarks from the specified Visual Basic files. Demonstrates many string functions
rex.prt
various tests with regular expressions. No input is used; output is sent to console (alternated '1' and '0'). The interest lies in the contents, that show many examples of simple and extended regular expressions
scanner.prt emulates keyboard (wedge emulation) by entering data coming from a serial device (e.g. a barcode scanner). This program can be installed as a script for Proteus Service. Demonstrates using SENDKEYS and serial ports.
send.prt send a file to the serial port using the specified parameters. Demonstrates functions on serial ports
sendlpt.prt send a file to the parallel port (direct write, does not use Windows™ drivers). Demonstrates Windows™ functions on files
simpremi.prt simulates a price generator; demonstrates using the random number generator
sngblnk.prt
replace multiple blank lines with a single blank line; very basic example
spooler.prt verify if a file exists; if it is so and the file is writable (it is not locked for update), process it by sending strings (e.g. commands to create a label on a barcode printer) merged with data available in the file. The printer where data are to be sent is specified by network address and port. Demonstrates using Socket functions.
statc.prt
statistics on a C program. Report:
  • total number of lines;
  • total number and percentage of non-blank lines;
  • total number and percentage of lines including directives.

Demonstrates:

tables.prt
print n * 1, .., n * 10, where n is between 1 and 10. Display the usage of the library matrix.prt
test.prt
several tests. Demonstrates using the libraries decnum.prt and filefunc.prt
todos.prt
transform to Dos (EOL = CR + LF) a text file in any format; demonstrates Proteus implicit transformation
tolower.prt renames all files corresponding to filespec so that their names are all lowercase
tomac.prt 
transform to Macintosh™ format (EOL = CR) a text file in any format; demonstrates the predefined identifier EOL
toshort.prt renames to Dos format (8 + 3 characters) all files corresponding to filespec
tounix.prt
Transforms to Unix™ format (EOL = LF) a text file in any format; demonstrates the predefined identifier EOL
toupper.prt renames to uppercase all files corresponding to filespec
txtform.prt
text formatting. All lines are converted to lines less than MaxLength character long; after each new dot ('.'), a new line is started. Demonstrate  the static tokenizer and several string functions
uplog.prt send a file to the serial port, by using the specified parameters; all characters returned by the remote device are saved to a log file. Demonstrates functions on serial ports
uudecode.prt
decodes a UU-encoded text file (single section)
uuencode.prt
writes to output a UU-encoded version of the first file specified
wc.prt
print the number of words, lines, characters and non-blank characters. Demonstrates the static tokenizer, the UDF ONEND
xcomp.prt
compare a group of file recursively between two directory trees. Demonstrates how Proteus is able to read both binary and text files, the usage of recursive functions and accessing public variables from a UDF
xmas.prt print a text in shape of a tree, with a single character at the top, 3 characters in the second row, 5 characters in the third, etc.

 

Start of page Next topic Previous topic Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell