Printer Compatibility Library

The Print Method offers no provision for the ';' syntax of VB. While I understand that adding new syntax is not possible what can work is the ability to print lines without a carriage return.

 

For example

Object.PrintNoReturn("Hello")

Object.PrintNoReturn(" ")

Object.PrintNoReturn("World")

Object.Print("")

Would work the same as the VB6 code

Object.Print "Hello";

Object.Print " ";

Object.Print "World";

Object.Print

In addition look at the IL of the library I notice you are using stringbuilder

The original procedure looks something like this

If you made builder1 a private member of the class called PrintBuilder (or whatever your team chooses) Then PrintNoReturn can work like this.

Public Sub Print(ByVal ParamArray args As Object())

Dim text1 As String = Support.TabLayout(args)

If PrintBuilder Is Nothing Then

PrintBuilder = New StringBuilder(text1)

Else

PrintBuilder.Append(text1)

End If

PrintBuilder.Replace(ChrW(13) & ChrW(10), ChrW(10))

PrintBuilder.Replace(ChrW(13), ChrW(10))

Dim textArray1 As String() = PrintBuilder.ToString.Split(New Char() {ChrW(10)})

Dim text2 As String

For Each text2 In textArray1

Me.PrintLine(text2)

Next

PrintBuilder = Nothing

End Sub

Public Sub PrintNoReturn(ByVal ParamArray args As Object())

Dim text1 As String = Support.TabLayout(args)

If PrintBuilder Is Nothing Then

PrintBuilder = New StringBuilder(text1)

Else

PrintBuilder.Append(text1)

End If

End Sub

Now somewhere in EndDoc you would have to check PrinterBuilder and print anything in it if it is not set to nothing. It just a rough example I am presenting. But doing this will allow a missing piece of functionality that is part of many different example of printing code.

Also if you are able to break out the Graphics portions of the Printer Compatibility Library into a VB Graphics Class that you can attach a WinForms Graphics Object too that would also help with compatibility issues between VB6 and VB.NET.

Rob Conley

Plasma Automation

PS You need a better of inserting tabs into this forum software.

 

 

 



Answer this question

Printer Compatibility Library

  • pmanisekaran

    Thanks for the great observation, Robert.

    The discard of syntax supports for ‘;’ basically caused the blind point to us that we did not see the need for calling ‘Print()’ while keeping in line.

    Your solution can be surely a solution to this issue, yet I herewith propose another solution for public discussion.

    Shall we introduce an escape method, namely, ‘KeepInLine()’, inserting an escape object, e.g. 'KeepInLineObject' into the parameter array.

    When we parse to the object we force to print current buffer and keep the position not skipping to a next line.

    Such an escape object will just serve as a traditional Visual Basic 6 semicolon, and when we work with migration tool, the tool can care to convert the semicolon it meets to this method call.

    Generally I think the implementation should work like this,

    Public Sub Print(ByVal ParamArray args As Object())

        Dim strBldr As New StringBuilder

        For Each obj As Object In args

            If obj Is KeepInLineObject Then

                FlushPrintingLines(strBldr)          ' flush the buffer to printer document

                strBldr.Length = 0                   ' clear the string builder

            Else

                BuildPrintingLines(strBldr, obj)     ' build the lines as it should behave

            End If

        Next

        If strBldr.Length > 0 Then

            FlushPrintingLines(strBldr)              ' flush the buffer to printer document

            AdvanceToNextLine()                      ' actually move to a next line here

        End If

    End Sub

    Neal

     



  • kangalert

    nealzhu_MSFT wrote:

    Thanks for the great observation, Robert.

    The discard of syntax supports for ‘;’ basically caused the blind point to us that we did not see the need for calling ‘Print()’ while keeping in line.

    Your solution can be surely a solution to this issue, yet I herewith propose another solution for public discussion.

    Shall we introduce an escape method, namely, ‘KeepInLine()’, inserting an escape object, e.g. 'KeepInLineObject' into the parameter array.

    That fine, but make sure it pass the following tests

    Print "Hello", "World"; "here", "there"

    results in

    Hello Worldhere there

    Also

    Print("01234", KeepInLine(), "56789")

    should print the same thing as

    Print ("01234",KeepInLine())

    Print ("56789",KeepInLine())

    Print ("")

    or

    Print ("01234",KeepInLine())

    Print ("56789")

    which all should result in

    "0123456789" with no spaces between the 4 and the 5

    last it would be nice if this works

    Print "Hello"; Tab(20); "World"
    Hello World

    and this as well

    Print "Hello", Tab(20), "World"
    Hello World

    Something like first would be

    Print("Hello",KeepInLine(), Tab(20), KeepInLine(),"World")

    the second would be

    Print("Hello", Tab(20), "World")

    Finally I would suggest NoCR() instead of KeepInLine(). KeepInLine is a lot of typing to do if you making new code.

    object.Print("#", NoCR())

    object.Print(Tab(20), NoCR())

    object.Print("ID", NoCR())

    object.Print(Tab(40), NoCR())

    object.Print("Description", NoCR())

    object.Print("")

    I found this method when I had to add print preview to my application (A CAD/CAM software written in VB6) I changed my printing to work through a interface which meant I had to forgo the Print syntax in favor of a function based approach. After experimentming I came up with a DrawText method (couldn't use Print as it was a keyword) like this

    Public Sub DrawText(ByVal text as String, Optional ByVal DoCR as Boolean=True)

    Thanks

    Rob Conley


  • Codegirl

    I think Georges workaround should use currenty instead of currentx

    The introduction of your toll says:

    charPos

    Optional. Specifies the insertion point for the next character. Use a semicolon (Wink to position the insertion point immediately after the last character printed. Use Tab(n) to position the insertion point at an absolute column number, where n is the column number. Use Tab without an argument to position the insertion point at the start of the next print zone. If charPos is omitted, the next character is printed on the next line.

    its obviously wrong!

    when will the next release be ready


  • fhunter

    Thanks George for the great work around.

    We looking at adding a Printer.Write method in a future release which I think will accomplish the same thing as the semicolin did in the VB6 Printer.Print.



  • dpeeth

    I like the code you are presenting but the question remain, how can I print without having a New Line.

    I do not understant the magic your are using since I do not see were "FlushPrintingLine" is comming from.

    I there a solution

    I am using:

    curX = printer.currentX

    printer.print "keep the same line"

    printer.currentX = curX

    but that will be nice to have a real Compatiblity driver.

    Keeping text on the same line was common in the good old time. Mainframe were using it to bold and many other usages.

    George


  • Printer Compatibility Library