Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1025
  • Last Modified:

how to turn vb6 code into VB.net Code?

Im converting a vb6 app to VB.net, but im having problem with drawing my line in VB.net because CurrentX, CurrentY and ScaleLeft and ScaleWidth are no longer used.

heres my vb6 code

CurrentX = ScaleLeft
CurrentY = .RegVal(CDbl(ScaleLeft))

    For i = ScaleLeft To ScaleWidth Step R
          Line -(i, .RegVal(CDbl(i))), vbBlue \ 2
    Next i

Open in new window


This is what I have in VB.net so far...and its not working at all, my line is way off

For i = Me.Left To Me.Width Step R
            g.DrawLine(Pens.MidnightBlue, 0, CInt(Reg.RegVal(CDbl(Me.Left))), i, CInt(Reg.RegVal(CDbl(i))))
        Next i

Open in new window


is there an equivalent in VB.net to the VB6 coding methods?
0
ezdrt
Asked:
ezdrt
  • 5
  • 3
  • 2
  • +1
1 Solution
 
HainKurtSr. System AnalystCommented:
have a look at here

http://home.wordpress.com/2010/05/20/vb6-scaleleft-scaletop-to-vb-net-conversion/

TextBox1.ScaleTop
TextBox1.ScaleLeft
TextBox1.ScaleHeight
TextBox1.ScaleWidth

-->

TextBox1.ClientRectangle.Top
TextBox1.ClientRectangle.Left
TextBox1.ClientRectangle.Height
TextBox1.ClientRectangle.Width
0
 
ezdrtAuthor Commented:
oh thanks:)

That will work, but what about the CurrentX and CurrentY properties? Is there a work around for those?

basically im clicking the screen and it draws a circle and a regression line. everytime i click another circle on the screen the line is suppossed to adjust itself.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Can you show a screenshot and/or screencast of it in action?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
ezdrtAuthor Commented:
Sure thing :)

heres the Form code

Option Explicit On

Imports System.Data
Imports System.Math
Imports System.Drawing.Graphics
Imports System.Drawing.Printing
Imports System.Windows.Forms


Public Class Form1

    Private Structure PointType
        Dim X As Double
        Dim Y As Double
    End Structure

    Dim Reg As New RegressionObject
    Private LastEndPoint As New Point(0, 0)

    Const R = 100
    Dim P(0 To 200) As PointType

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Reg.Degree = 3
    End Sub

    Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
        Dim X, Y As Single

        X = e.X
        Y = e.Y
        With Reg
            .XYAdd(X, Y)
            P(.XYCount).X = X
            P(.XYCount).Y = Y
            Redraw()
        End With
    End Sub

    Private Sub Redraw()
        Dim g As System.Drawing.Graphics
        g = CreateGraphics()
        Dim i&

        With Reg
            For i = 1 To .XYCount
                DrawACircle(g, New Point(P(i).X, P(i).Y), R / 2)
            Next i

            LastEndPoint = New Point(P(i).X, P(i).Y)

            LastEndPoint.X = Me.ClientRectangle.Left
            LastEndPoint.Y = .RegVal(CDbl(Me.ClientRectangle.Left))
            For i = Me.ClientRectangle.Left To Me.ClientRectangle.Width Step R
                g.DrawLine(Pens.BlueViolet, LastEndPoint.X, LastEndPoint.Y, i, CInt(.RegVal(CDbl(i))))
            Next i
        End With
    End Sub

    Private Sub DrawACircle(ByRef g As Graphics, ByRef center As Point, ByVal radius As Integer)
        ' Select a pen object and make it red
        Dim pn As New Pen(Color.Red)
        pn.Width = 5
        ' Create a bounding rectangle and make its center the center of our point
        ' Then make its width 2 * the radius
        ' Then draw our ellipse
        Dim rect As New Rectangle(center.X - 12, center.Y - 12, radius, radius)
        g.DrawEllipse(pn, rect)
    End Sub

End Class

Open in new window


SCREEN
http://postimage.org/image/1s2wynrhg/



HERES THE VB6 VERSION....this is what its supposed to do
http://postimage.org/image/1s4dvuvac/


0
 
ezdrtAuthor Commented:
Oh I almost forgot, heres more of the VB6 code...

'WHEN THE MOUSE IS DOWN IT GET THE COORDINATES
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  With Reg
    .XYAdd X, Y
    P(.XYCount).X = X
    P(.XYCount).Y = Y
    Redraw
  End With
End Sub


'THIS IS WHERE THE CIRCLE AND LINES ARE DRAWN
Private Sub Redraw()
Dim i&
  Cls
  With Reg
    For i = 1 To .XYCount
      Circle (P(i).X, P(i).Y), R
    Next i
    CurrentX = ScaleLeft
    CurrentY = .RegVal(CDbl(ScaleLeft))
    For i = ScaleLeft To ScaleWidth Step R
      Line -(i, .RegVal(CDbl(i))), vbBlue
    Next i
  End With


End Sub

Open in new window

0
 
HainKurtSr. System AnalystCommented:
you shoudl not start with 0 all the time... but dont know where to start :) maybe you should start from previous point

g.DrawLine(Pens.MidnightBlue, 0, CInt(Reg.RegVal(CDbl(Me.Left))), i, CInt(Reg.RegVal(CDbl(i))))
-->
g.DrawLine(Pens.MidnightBlue, ?, CInt(Reg.RegVal(CDbl(Me.Left))), i, CInt(Reg.RegVal(CDbl(i))))
0
 
x77Commented:
1 - g - Graphics - is a Disposable object, You need use dispose
            or use "Using Sintax to ensure object dispose:

      Using g = Me.CreateGraphics
          ....
      End Using

2 - Vb clasic Line method is like g.DrawLine method but:      Lie x1,y1,x2,y2
      it support abreviated syntax                                           Line -x2,y2
      Equivalent to:                                                                  Line Currentx,Currenty,x2,y2

      Line method  set the CurrentX and Current y for final Point.
       
To do same on Vb.Net, Declare CurrentX,Currenty and set it:

            Dim CurrentX = Me.ClientRectangle.Left
            Dim CurrentY = .RegVal(CDbl(Me.ClientRectangle.Left))
            For i = CurrentX+R To Me.ClientRectangle.Width Step R
                Dim V = CInt(.RegVal(CDbl(i)))
                g.DrawLine(Pens.BlueViolet, CurrentX, CurrentY, i, v)
                CurrentX=i
                CurrentY=V
            Next i



Note that I Increment the Initial Point In Foor loop:      CurrentX+R  
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Don't use CreateGraphics() like that.  Instead, use the Graphics supplied by the "e" parameter in the Paint() event of the Form.  To trigger a repaint, use the Refresh() method like this "Me.Refresh()".

See if this works: *Lots of changes in here...look closely*
Option Explicit On

Imports System.Data
Imports System.Math
Imports System.Drawing.Graphics
Imports System.Drawing.Printing
Imports System.Windows.Forms

Public Class Form1

    Private Structure PointType
        Dim X As Double
        Dim Y As Double
    End Structure

    Dim Reg As New RegressionObject
    Private LastEndPoint As New Point(0, 0)

    Const R = 100
    Dim P(0 To 200) As PointType

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Reg.Degree = 3
    End Sub

    Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Dim pt As New Point(e.X, e.Y)
            With Reg
                .XYAdd(pt.X, pt.Y)
                P(.XYCount).X = pt.X
                P(.XYCount).Y = pt.Y
            End With
            Me.Refresh()
        End If
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim i As Integer
        Dim g As System.Drawing.Graphics = e.Graphics
        With Reg
            Using pn As New Pen(Color.Red, 5)
                For i = 1 To .XYCount
                    DrawACircle(g, pn, New Point(P(i).X, P(i).Y), R / 2)
                Next i
            End Using
            
            LastEndPoint = New Point(0, Me.ClientRectangle.Height)
            Dim CurrentPoint As Point
            For i = 0 To Me.ClientRectangle.Width Step R
                CurrentPoint = New Point(i, CInt(.RegVal(CDbl(i))))
                g.DrawLine(Pens.BlueViolet, LastEndPoint, CurrentPoint)
                LastEndPoint = CurrentPoint
            Next i
        End With
    End Sub

    Private Sub DrawACircle(ByVal g As Graphics, ByVal P As Pen, ByVal center As Point, ByVal radius As Integer)
        ' Create a bounding rectangle and make its center the center of our point
        ' Then make its width 2 * the radius
        ' Then draw our ellipse
        Dim rect As New Rectangle(center, New Size(0, 0))
        rect.Inflate(radius, radius)
        g.DrawEllipse(P, rect)
    End Sub

End Class

Public Class RegressionObject

    Private _regVal As Integer

    Property Degree As Integer

    Property XYCount As Object

    Property RegVal(ByVal p1 As Double) As Integer
        Get
            Return _regVal
        End Get
        Set(ByVal value As Integer)
            _regVal = value
        End Set
    End Property

    Sub XYAdd(ByVal X As Single, ByVal Y As Single)
        Throw New NotImplementedException
    End Sub

End Class

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
*Ignore my lines 69 thru 90...that was just to make my compiler shut up.  ;)
0
 
ezdrtAuthor Commented:
Thanks guys Im gonna give these suggestions a shot and ill let you know what I come up with:)

0
 
ezdrtAuthor Commented:
Awesome, thank you sir :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now