Informatics, Uncategorized

Printing from EXTRA! Basic.

Attachmate EXTRA! is terminal emulation software to connect to mainframes. Part of this software is a Basic interpreter that allows you to write automation macros that do screenscraping on terminal screens. The scripting language used is called Extra Basic. Scripts have the extension .ebm, which stands for Extra Basic Macro.

This scripting language is a lot like Visual Basic, or QBasic and most code you can simply Copy & Paste. But there are differences.

At work, when extending an old macro (made by a now retired colleague) with printing capabilities I ran into some limitations of Extra Basic.

In QBasic there used to be a command LPRINT to send text to a line printer. Neither Visual Basic or Extra Basic have this command. To print from Visual Basic you use the Printer object, but to print from Extra Basic you need another approach.

Declare Function GetDefaultPrinter Lib "winspool.drv" Alias _
    "GetDefaultPrinterA" (ByVal sPrinterName As String, _
    lPrinterNameBufferSize As Long) As Long

Function MyGetDefaultPrinter() As String
    Dim sNameBuff As String
    Dim sPrinterName As string
    Dim lLen As Long
   
    GetDefaultPrinter Chr(0), lLen
    sNameBuff = Space(lLen)
    GetDefaultPrinter sNameBuff, lLen

    sPrinterName = Left(sNameBuff, lLen - 1)
    MyGetDefaultPrinter = sPrinterName
End Function

Sub Main()
    Dim sPrinter As String
    sPrinter = MyGetDefaultPrinter()
    Open sPrinter For Output As #1
    Print #1, "Hello World!"    
    Print #1, "Printing from EXTRA Basic is not that hard!"
    Print #1, Chr(12) ' Do a page feed
    Close #1
End Sub

It’s not as short as a simple LPRINT, but it will do the trick. Stuff like this makes me want to avoid Extra Basic as much as possible. Use any other more descent language instead to call the Attachmate EXTRA! ActiveX Control.

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*Required Fields