?
Solved

how to turn vb6 code into VB.net Code?

Posted on 2011-09-16
11
Medium Priority
?
952 Views
Last Modified: 2012-05-12
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
Comment
Question by:ezdrt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 58

Expert Comment

by:HainKurt
ID: 36552372
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
 

Author Comment

by:ezdrt
ID: 36552525
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36552564
Can you show a screenshot and/or screencast of it in action?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ezdrt
ID: 36552611
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
 

Author Comment

by:ezdrt
ID: 36552622
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
 
LVL 58

Expert Comment

by:HainKurt
ID: 36552677
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
 
LVL 15

Expert Comment

by:x77
ID: 36553100
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 36553101
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36553103
*Ignore my lines 69 thru 90...that was just to make my compiler shut up.  ;)
0
 

Author Comment

by:ezdrt
ID: 36561254
Thanks guys Im gonna give these suggestions a shot and ill let you know what I come up with:)

0
 

Author Closing Comment

by:ezdrt
ID: 36561457
Awesome, thank you sir :)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question