Operator '-' not defined VB6 to VB.NET

Viewed 97

Another migration question. I have a chunk of VB6 code that seems to need some workaround for .NET. For a shortened version, this is all it is doing:

Printer.Line (lftx * stepx * fx, k * stepy * fy)-(rgtx * stepx * fx, k * stepy * fy), RGB(77, 66, 71)
 

Keep giving me Error ID: BC30205, End of statement expected, on minus sign.

I have added a parenthesis that encloses the contents of the command, aware that it does not completely solve the problem. Doing so a different error appears, Error ID: BC30452, Operator '-' is not defined for types '(Single, Single)' and '(Single, Single)'. I guess it can't subtract because of the commas inside the brackets...

As you may have noticed, I never written in VB6 and im not a programmer. How do I implement the same thing in .NET? Thank you for all the help

1 Answers

An equivalent instruction for printer.line is e.Graphics.DrawLine(). Here is a sample code that you may find here and to which I have added e.Graphics.DrawLine in the following code:

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Printing

Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
    ' ...
    ' These two lines initiate printing. Place this code in an
    ' appropriate place in the application.
    Dim pd As New HelloPrintDocument()
    pd.Print()
End Sub
' ...

' This class manages the printing process.
Public Class HelloPrintDocument
    Inherits PrintDocument

    Protected Overrides Sub OnPrintPage(ByVal e As PrintPageEventArgs)
        MyBase.OnPrintPage(e)

        ' Draw text to the printer graphics device.
        Dim fnt As New Font("Arial", 10, FontStyle.Regular,
           GraphicsUnit.Point)
        e.Graphics.DrawString("Hello, Printer!", fnt, Brushes.Black, 0, 0)
        Dim x0 As Int32 = 0
        Dim y0 As Int32 = 0
        Dim x1 As Int32 = 0
        Dim y1 As Int32 = 50
        e.Graphics.DrawLine(Pens.Black, New Point(x0, y0), New Point(x1, y1))
        Dim w As Int32 = 200 ' rectangle width
        Dim h As Int32 = 50 '  rectangle height
        y0 += 12
        e.Graphics.DrawRectangle(Pens.Red, New Rectangle(New Point(x0, y0), New Size(w, h)))
        y0 = e.PageBounds.Height - h * 2
        e.Graphics.FillRectangle(Brushes.Green, New Rectangle(New Point(x0, y0), New Size(w, h)))

        fnt.Dispose()

        ' Indicate that there are no more pages.
        e.HasMorePages = False
    End Sub

End Class
Related