guides:programming:programmers_reference_manual:oipi_example1

OIPI_EXAMPLE1

The OIPI_EXAMPLE1 program uses most of the OIPI features. To run this example start OpenInsight, and then start the System Editor. Copy the example text below, and paste it into a new record in the System Editor. Then compile the program and run it. Here is an example of the print preview:

OIPI_EXAMPLE1
subroutine OIPI_Example1(dummy)

/*

OIPI_Example1

This is an example program on how to use the OpenInsight Printer Interface.

This example uses most of the features of the OpenInsight Printer Interface, and

is a good place to start learning how to create reports with the OIPI.

*/

declare function Set_Printer, Get_Printer, RGB

declare function msg

$insert OIPRINT_EQUATES

* Create the fonts for the OIPI report

* 18 point Arial font with left justified, bold and dark blue color

Font1 = "Arial":@fm:18:@fm:"L":@fm:1:@fm:0:@fm:0:@fm:0:@fm:RGB(0, 0, 172)

* 16 point Times New Roman with left justified bold, italics, underline, and dark magenta

Font2 = "Times New Roman":@fm:16:@fm:"L":@fm:1:@fm:1:@fm:1:@fm:0:@fm:RGB(192, 0, 172)

* 14 point Times New Roman with left justified

Font3 = "Times New Roman":@fm:14

* Start the OIPI report with the INIT message

FileName = "OIPI_Example1"

PrintTitle = "OIPI Printing..."

PreviewTitle = "OIPI Print Preview" ;* Change the title of the print preview window

margins = 1:@fm:1:@fm:1:@fm:1  ;* Set one inch margins

Orientation = 0

PrintSetup = ""

PrintSetup<1, 1> = 5 ;* Print Preview at a specific location - defined In PrintSetup <3>, <4>, <5> & <6>

PrintSetup<1, 2> = 2 ;* Hide the PrintSetup button

PrintSetup<2> = -1  ;* Set initial zoom to PageWidth

PrintSetup<3> = 5   ;* Set the Print Preview position at 5% from top and left

PrintSetup<4> = 5

PrintSetup<5> = 95

PrintSetup<6> = 95

status = Set_Printer("INIT", FileName, PrintTitle:@fm:PreviewTitle, Margins, Orientation, PrintSetup)

If status < 1 Then

*Always check the return value of the INIT message for errors

ErrorMsg = "Fatal error with the INIT message"

Goto fatalExit

End

* Set the line style for the border - a dotted red line with a thickness of 1

If Set_Printer("LINESTYLE", PS_DOT:@fm:1:@fm:RGB(128, 0, 0)) < 0 Then

ErrorMsg = "Error with the LINESTYLE message"

Goto fatalExit

End

* Print border slightly outside of the margins

If Set_Printer("RECT", -0.05:@fm:-0.05:@fm:6.55:@fm:9.05, 1) < 0 Then

ErrorMsg = "Error with the RECT message"

Goto fatalExit

End

* Set the font for all of the headers and footers

If Set_Printer("FONTHEADFOOT", "Arial":@fm:14:@fm:"L":1) < 0 Then

ErrorMsg = "Error with the FONTHEADFOOT message"

Goto fatalExit

End

* Print the header with the file name centered on the first line And

* the Long format of the date left justified and the page number right justified

* on the second line.

If Set_Printer("HEADER", @vm:"'F'":@fm:"'DL'":@vm:@vm:"Page 'P'":@fm) < 0 Then

ErrorMsg = "Error with the HEADER message"

Goto fatalExit

End

If Set_Printer("FONT", Font1) < 0 Then

ErrorMsg = "Error with the FONT message"

Goto fatalExit

End

If Set_Printer("TEXT", "Welcome to the OpenInsight Printer Interface!!!") < 0 Then

* I'm not going to check the remaining TEXT messages, because if the first one

* works then the remaining TEXT messages should also work.

ErrorMsg = "Error with the TEXT message"

Goto fatalExit

End

If Set_Printer("FONT", Font2) < 0 Then

ErrorMsg = "Error with the FONT message"

Goto fatalExit

End

x = Set_Printer("TEXT", @fm:"Introduction")

If Set_Printer("FONT", Font3) < 0 Then

ErrorMsg = "Error with the FONT message"

Goto fatalExit

End

text = "This program will demonstrate the basic features of the OpenInsight Printer Interface.  "

text: = "Please check the online help file for the latest message formats."

x = Set_Printer("TEXT", text)

if Set_Printer("FONT", Font2) < 0 Then

ErrorMsg = "Error with the FONT message"

Goto fatalExit

End

x = Set_Printer("TEXT", @fm:"Get_Printer for VERSION and SERIAL")

If Set_Printer("FONT", Font3) < 0 Then

ErrorMsg = "Error with the FONT message"

Goto fatalExit

End

ver = Get_Printer("VERSION")

ser = Get_Printer("SERIAL")

text = "You are currently using version '":ver<1>:"' of the OIPI, "

text:= "and the OIPI build number is '":ver<2>:"' and the VSVIEW control version is '":ver<3>:"'":@FM:"Your "

text:= "serial number is ":ser

x = Set_Printer("TEXT", text)

If Set_Printer("FONT", Font2) < 0 Then

ErrorMsg = "Error with the FONT message"

Goto fatalExit

End

x = Set_Printer("TEXT", @fm:"BMP and TEXTXY")

If Set_Printer("FONT", Font3) < 0 Then

ErrorMsg = "Error with the FONT message"

Goto fatalExit

End

text = "This will demonstrate the use of graphic files and the TEXTXY message.  The "

text:= "graphic file (BANNER.WMF) is printed first, "

text:= "then the text is printed over it with the TEXTXY message.  The text shadow "

text:= "is created by offsetting two separate TEXTXY messages."

text:= "The current Y position is used to determine where to print the graphics "

text:= "and text using the Get_Printer POS message."

text:= "You can stretch the graphics with the BMP message.":@fm

x = Set_Printer("TEXT", text)

* Print the banner.wmf and text inside

pos = Get_Printer("POS")

if Set_Printer("BMP", "BANNER.WMF", 0:@FM:pos<2>:@FM:3.5:@FM:1, 0, 0) < 0 then

ErrorMsg = "Error with the BMP message"

goto fatalExit

End

if Set_Printer("TEXTXY", "Banner Text", .77:@FM:pos<2>+0.48, "Arial":@FM:24:@FM:"L":@FM:1:@FM:0:@FM:0:@FM:0:@FM:RGB(192,192, 192):@FM:100, 0) < 0 then

ErrorMsg = "Error with the TEXTXY message"

goto fatalExit

End

if Set_Printer("TEXTXY", "Banner Text", .80:@FM:pos<2>+0.45, "Arial":@FM:24:@FM:"L":@FM:1:@FM:0:@FM:0:@FM:0:@FM:RGB(128,0, 128):@FM:100, 0) < 0 then

ErrorMsg = "Error with the TEXTXY message"

goto fatalExit

End

if Set_Printer("BMP", "PRINTER.BMP", 4.0:@FM:pos<2>:@FM:1.6:@FM:1, 0, 0) < 0 then

ErrorMsg = "Error with the BMP message"

goto fatalExit

End

* Reset the text position below the graphics by adding one inch to the last position

x = Set_Printer("POS", 0:@FM:pos<2> + 1)

if Set_Printer("FONT", Font2) < 0 then

ErrorMsg = "Error with the FONT message"

goto fatalExit

End

x = Set_Printer("TEXT", @FM:"RECT, CALC_TEXT, POLYGON, and Colors")

if Set_Printer("FONT", Font3) < 0 then

ErrorMsg = "Error with the FONT message"

goto fatalExit

End

text = "The next section demonstrates how to use colors with the RECT message, and "

text := "how to use the CALC_TEXT message to calculate the height and width of text and place "

text := "a box around the text.  "

text := "The POLYGON message is used to print the gray shading in the 3D button."

x = Set_Printer("TEXT", text)

* Print pyramid

if Set_Printer("LINESTYLE", PS_NULL) < 0 then

ErrorMsg = "Error with the LINESTYLE message"

goto fatalExit

End

pos = Get_Printer("POS")

y = pos<2>

offset = 0

for c = 0 to 128 step 12.8

if Set_Printer("FILLSTYLE", BS_SOLID:@FM:RGB(0, 0, 128 + c)) < 0 then

ErrorMsg = "Error with the FILLSTYLE message"

goto fatalExit

end

if Set_Printer("RECT", 1+offset:@FM:y+offset:@FM:3-offset:@FM:y-offset+2, 0) < 0 then

ErrorMsg = "Error with the RECT message"

goto fatalExit

end

offset = offset + 0.05

next c

for c = 0 to 128 step 12.8

if Set_Printer("FILLSTYLE", BS_SOLID:@FM:RGB(c, c, 255)) < 0 then

ErrorMsg = "Error with the FILLSTYLE message"

goto fatalExit

end

if Set_Printer("RECT", 1+offset:@FM:pos<2>+offset:@FM:3-offset:@FM:pos<2>+2-offset,0) < 0 then

ErrorMsg = "Error with the RECT message"

goto fatalExit

end

offset = offset + 0.05

next c

if Set_Printer("LINESTYLE", PS_SOLID:@FM:1:@FM:RGB(0, 0, 0)) < 0 then

ErrorMsg = "Error with the LINESTYLE message"

goto fatalExit

End

if Set_Printer("FILLSTYLE", BS_HOLLOW) < 0 then

ErrorMsg = "Error with the FILLSTYLE message"

goto fatalExit

End

if Set_Printer("RECT", 1:@FM:pos<2>:@FM:3:@FM:pos<2>+2, 0) < 0 then

ErrorMsg = "Error with the RECT message"

goto fatalExit

End

if Set_Printer("LINE", 1:@FM:pos<2>:@FM:3:@FM:pos<2>+2, 0) < 0 then

ErrorMsg = "Error with the LINE message"

goto fatalExit

End

if Set_Printer("LINE", 3:@FM:pos<2>:@FM:1:@FM:pos<2>+2, 0) < 0 then

ErrorMsg = "Error with the LINE message"

goto fatalExit

End

* print a 3D button

text = "3D Button"

if Set_Printer("FILLSTYLE", BS_SOLID:@FM:RGB(128, 128, 128)) < 0 then

ErrorMsg = "Error with the FILLSTYLE message"

goto fatalExit

End

if Set_Printer("FONT", "Arial":@FM:14) < 0 then

ErrorMsg = "Error with the FONT message"

goto fatalExit

End

if Set_Printer("CALCTEXT", text) < 0 then

ErrorMsg = "Error with the CALCTEXT message"

goto fatalExit

End

size = Get_Printer("CALCTEXT")

width = size<1>

height = size<2>

poly = ""

poly<1> = 3.5+width+.4:@VM:y

poly<2> = 3.5+width+.4:@VM:y+height+.4

poly<3> = 3.5:@VM:y+height+.4

poly<4> = 3.5+.1:@VM:y+height+.3

poly<5> = 3.5+width+.3:@VM:y+height+.3

poly<6> = 3.5+width+.3:@VM:y+.1

if Set_Printer("POLYGON", poly, 0) < 0 then

ErrorMsg = "Error with the POLYGON message"

goto fatalExit

End

if Set_Printer("FILLSTYLE", BS_HOLLOW) < 0 then

ErrorMsg = "Error with the FILLSTYLE message"

goto fatalExit

End

if Set_Printer("RECT", 3.5:@FM:y:@FM:3.5+width+.4:@FM:y+height+.4, 0) < 0 then

ErrorMsg = "Error with the RECT message"

goto fatalExit

End

if Set_Printer("FILLSTYLE", BS_SOLID:@FM:RGB(192, 192, 192)) < 0 then

ErrorMsg = "Error with the FILLSTYLE message"

goto fatalExit

End

if Set_Printer("RECT", 3.5+.1:@FM:y+.1:@FM:3.5+width+.3:@FM:y+height+.3, 0) < 0 then

ErrorMsg = "Error with the RECT message"

goto fatalExit

End

if Set_Printer("TEXTXY", text, 3.7:@FM:y+.2, "", 0) < 0 then

ErrorMsg = "Error with the TEXTXY message"

goto fatalExit

End

if Set_Printer("FONT", "Times New Roman":@FM:12) < 0 then

ErrorMsg = "Error with the FONT message"

goto fatalExit

End

* Force a page break

if Set_Printer("PAGEBREAK") < 0 then

ErrorMsg = "Error with the PAGEBREAK message"

goto fatalExit

End

if Set_Printer("FONT", Font2) < 0 then

ErrorMsg = "Error with the FONT message"

goto fatalExit

End

x = Set_Printer("TEXT", "POLYLINE, ADDTABLE, and TEXTXY")

if Set_Printer("FONT", Font3) < 0 then

ErrorMsg = "Error with the FONT message"

goto fatalExit

End

text = "The POLYLINE message is used to create this Graph, and the ADDTABLE message"

text:= " is used to create the Table.  The TEXTXY message is used to print the labels."

x = Set_Printer("TEXT", text)

pos = Get_Printer("POS")

y = pos<2>+.25

if Set_Printer("FILLSTYLE", BS_SOLID:@FM:RGB(255, 255, 128)) < 0 then

ErrorMsg = "Error with the FILLSTYLE message"

goto fatalExit

End

ErrorMsg = "There was some problem with the Graph part of the example"

if Set_Printer("RECT", 3:@FM:y:@FM:6:@FM:y+2, 0) < 0 then goto fatalExit

if Set_Printer("RECT", 1:@FM:y:@FM:2.5:@FM:y+0.5, 0) < 0 then goto fatalExit

if Set_Printer("LINESTYLE", PS_DOT:@FM:0:@FM:RGB(0, 0, 0)) < 0 then goto fatalExit

if Set_Printer("LINE", 3:@FM:y+.5:@FM:6:@FM:y+.5, 0) < 0 then goto fatalExit

if Set_Printer("LINE", 3:@FM:y+1:@FM:6:@FM:y+1, 0) < 0 then goto fatalExit

if Set_Printer("LINE", 3:@FM:y+1.5:@FM:6:@FM:y+1.5, 0) < 0 then goto fatalExit

initrnd timedate()

poly1 = ""

for i = 0 to 12

sx = i/4

sy = y+1-rnd(100)/100

poly1<i+1,1> = sx + 3

poly1<i+1,2> = sy

next i

if Set_Printer("LINESTYLE", PS_SOLID:@FM:1:@FM:RGB(0, 128, 0)) < 0 then goto fatalExit

if Set_Printer("POLYLINE", poly1, 0) < 0 then goto fatalExit

if Set_Printer("LINE", 1.2:@FM:y+0.15:@FM:1.5:@FM:y+0.15, 0) < 0 then goto fatalExit

poly2 = ""

for i = 0 to 12

sx = i/4

sy = y+1-rnd(100)/100

poly2<i+1,1> = sx + 3

poly2<i+1,2> = sy

next i

if Set_Printer("LINESTYLE", PS_SOLID:@FM:1:@FM:RGB(128, 0, 0)) < 0 then goto fatalExit

if Set_Printer("POLYLINE", poly2, 0) < 0 then goto fatalExit

if Set_Printer("LINE", 1.2:@FM:y+0.35:@FM:1.5:@FM:y+0.35, 0) < 0 then goto fatalExit

if Set_Printer("LINESTYLE", PS_SOLID:@FM:1:@FM:RGB(0, 0, 0)) < 0 then goto fatalExit

if Set_Printer("FONT", "Arial":@FM:8) < 0 then goto fatalExit

if Set_Printer("TEXTXY", "4.0", 2.8:@FM:y-.05, "", 0) < 0 then goto fatalExit

if Set_Printer("TEXTXY", "3.0", 2.8:@FM:y+.45, "", 0) < 0 then goto fatalExit

if Set_Printer("TEXTXY", "2.0", 2.8:@FM:y+.95, "", 0) < 0 then goto fatalExit

if Set_Printer("TEXTXY", "1.0", 2.8:@FM:y+1.45, "", 0) < 0 then goto fatalExit

if Set_Printer("TEXTXY", "0.0", 2.8:@FM:y+1.95, "", 0) < 0 then goto fatalExit

if Set_Printer("TEXTXY", "Years", 4.4:@FM:y+2.05, "", 0) < 0 then goto fatalExit

if Set_Printer("TEXTXY", "$Millions", 2.8:@FM:y-.2, "", 0) < 0 then goto fatalExit

if Set_Printer("FONT", "Arial":@FM:10) < 0 then goto fatalExit

if Set_Printer("TEXTXY", "XYZ Co.", 1.6:@FM:y+0.07, "", 0) < 0 then goto fatalExit

if Set_Printer("TEXTXY", "ABC Co.", 1.6:@FM:y+0.27, "", 0) < 0 then goto fatalExit

if Set_Printer("FILLSTYLE", BS_HOLLOW) < 0 then goto fatalExit

if Set_Printer("RECT", 3:@FM:y:@FM:6:@FM:y+2, 0) < 0 then goto fatalExit

ErrorMsg = "There was some problem with the ADDTABLE part of the example"

if Set_Printer("POS", 0:@FM:y+1) < 0 then goto fatalExit

header = "Year":@VM:"XYZ Co. Sales ($Mill)":@VM:"ABC Co. Sales ($Mill)":@FM

table = ""

for i = 0 to 12

table<i+1,1> = 1990+i

table<i+1,2> = 3.5+y-poly1<i+1,2>

table<i+1,3> = 3.5+y-poly2<i+1,2>

next i

if Set_Printer("FONT", "Arial":@FM:10:@FM:"L":@FM:1) < 0 then goto fatalExit

ColumnFormat = "_^770":@VM:"_>1080":@VM:"_>1080":@FM

if Set_Printer("ADDTABLE", ColumnFormat, header, table, RGB(0, 222, 0), "", "", TB_BOX_COLUMNS) < 0 then goto fatalExit

if Set_Printer("CALCTABLE", ColumnFormat:header:table) < 0 then goto fatalExit

size = Get_Printer("CALCTABLE")

if Set_Printer("POS", 0:@FM:y+1+size<2>) < 0 then goto fatalExit

if Set_Printer("FONT", Font2) < 0 then

ErrorMsg = "Error with the FONT message"

goto fatalExit

End

x = Set_Printer("TEXT", @FM:"Other New Features in the OIPI")

if Set_Printer("FONT", Font3) < 0 then

ErrorMsg = "Error with the FONT message"

goto fatalExit

End

text = "  *  The ADDTABLE message was added to improve the quality of tables.  This":@FM

text := "  *  message should be used to replace all TABLE and TEXTCOL messages.":@FM

text := "  *  The Print Preview window can be scrolled with the mouse and all pages":@FM

text := "  *  are viewable as soon as they are printed.":@FM

text := "  *  The INIT message can be used to change the size of the paper without":@FM

text := "  *  using the Printer Setup dialog box.":@FM

text := "  *  The CALCBMP and CALCTABLE messages were added.":@FM

text := "  *  The title of the Print Preview window can be customized.":@FM

x = Set_Printer("TEXT", text)

* End the report

x = Set_Printer("TERM")

Return

* jump here if any Set_Printer returns a value < 1

fatalExit:

x = Msg("", ErrorMsg)

x = Set_Printer("TERM")

Return
  • guides/programming/programmers_reference_manual/oipi_example1.txt
  • Last modified: 2024/06/19 20:20
  • by 127.0.0.1