Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Threading
Imports System.Windows.Forms
Imports System.Math

Public Class PlanetSForm
    Inherits System.Windows.Forms.Form

    ' 23-12-2010    First Release  Copied From Planet1
    ' 23-12-2010    All usage of backgrounworkers removed

    Private WithEvents startAsyncButton As System.Windows.Forms.Button
    Private WithEvents cancelAsyncButton As System.Windows.Forms.Button
    Private WithEvents endAsyncButton As System.Windows.Forms.Button
    ' Private tdeltaL, seccntL, nplL As System.Windows.Forms.Label
    Private Label1, Label2, Label3(2), Label4, Label5, Label6 As System.Windows.Forms.Label
    Private ResultLabelpp1, ResultLabelpp2, ResultLabelpp3, ResultLabelpp4, ResultLabelpp5 As System.Windows.Forms.Label
    ' Private tdeltaT, seccntT, nplT As System.Windows.Forms.TextBox
    Private x1T, x2T, x3T, x4T As System.Windows.Forms.TextBox
    Private y1T, y2T, y3T, y4T As System.Windows.Forms.TextBox
    Private r1T, r2T, r3T, r4T As System.Windows.Forms.TextBox
    Private pl1T, pl2T, pl3T, pl4T As System.Windows.Forms.TextBox
    Private rev1T, rev2T, rev3T, rev4T As System.Windows.Forms.TextBox

    Private hh, dhh, dd, ddd As Integer

    Public x(idim), y(idim), z(idim)
    Public vx(idim), vy(idim), vz(idim)
    Public ax(idim), ay(idim), az(idim)
    Public Rev(idim) As Integer              ' revolution counter
    Public pl_itercnt(idim) As Integer       ' iteration counter per planet
    Public m(idim)
    Public itercnt(5), seccnt(5)
    Public perfs As String
    Public nplanets, nplanetsl, holdrev, holdreq, errorc As Integer
    Public state(5) As Integer
    Const StartSt As Integer = 1, ActiveSt As Integer = 2, StopSt As Integer = 0, CancelSt As Integer = 3, Endst = 0
    Const StartSt1 As Integer = 4
    Const idim As Integer = 100
    Public dt, dtl As Single              ' delta t


    Public Sub New()

        InitializeComponent()
        InitializeForm()

    End Sub 'New

    Private Sub startAsyncButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startAsyncButton.Click
        ResultLabelpp1.Text = " "
        state(1) = ActiveSt

        startAsyncButton.Enabled = False
        cancelAsyncButton.Enabled = True
        cancelAsyncButton.Text = "Stop"
        holdrev = HoldT.Value
        tdeltaT.Enabled = False
        nplT.Enabled = False
        HoldT.Enabled = False

        Master()

    End Sub


    ' This event handler 1 is where the time-consuming work is done.
    Private Sub Master()
        Dim i, j As Integer
        Dim sec1, sec2 As Integer
        Dim dx, dy, dz, r2, r, a, ynew As Double
        Dim b As String
        sec1 = Second(Now)
        holdreq = 0
        b = tdeltaT.Text : dt = Val(b)      ' Delta t
        If dt = 0 Then dt = 0.02
        b = nplT.Text : nplanets = Val(b)
        If nplanets < 1 Then nplanets = 1
        If nplanets > idim Then nplanets = idim
        state(1) = ActiveSt

        Debug.Print("PP1 Load " + Str(1) + "  dt = " + Str(dt))

        Init()
        itercnt(1) = 0 : seccnt(1) = -2

        Do
            Application.DoEvents()
            If Rev(1) = holdrev Or holdreq = 2 Then
                ' Hold
                holdreq = 1
                holdrev = -1
                Display()
                cancelAsyncButton.Enabled = True
                cancelAsyncButton.Text = "Restart"
                HoldT.Enabled = True
            End If
            If holdreq = 1 Then
                System.Threading.Thread.Sleep(1)
            Else
                If state(1) = CancelSt Then
                    'E.Cancel = True
                    state(1) = Endst
                    Debug.Print("Master Cancelst " + Str(state(1)))
                    Exit Sub
                Else
                    itercnt(1) = itercnt(1) + 1
                    'Debug.Print(itercnt(1))
                    For i = 0 To nplanets
                        ax(i) = 0 : ay(i) = 0 : az(i) = 0
                        For j = 0 To nplanets
                            If i <> j Then
                                dx = x(i) - x(j) : dy = y(i) - y(j) : dz = z(i) - z(j)
                                r2 = (dx * dx + dy * dy + dz * dz) : r = Sqrt(r2)
                                a = m(j) / (r2 * r)
                                ax(i) = ax(i) + a * dx
                                ay(i) = ay(i) + a * dy
                                az(i) = az(i) + a * dz
                            End If
                        Next
                        vx(i) = vx(i) - ax(i) * dt
                        vy(i) = vy(i) - ay(i) * dt
                        vz(i) = vz(i) - az(i) * dt
                    Next

                    For i = 0 To nplanets
                        x(i) = x(i) + vx(i) * dt
                        ynew = y(i) + vy(i) * dt
                        If y(i) < 0 And ynew > 0 Then Rev(i) = Rev(i) + 1
                        y(i) = ynew
                        z(i) = z(i) + vz(i) * dt
                        pl_itercnt(i) = pl_itercnt(i) + 1
                    Next


                    ' Perform a time consuming operation and report progress.
                    sec2 = Second(Now)
                    If sec2 <> sec1 Then
                        sec1 = Second(Now)
                        seccnt(1) = seccnt(1) + 1
                        If seccnt(1) <= 0 Then
                            itercnt(1) = 0
                            perfs = 0
                        Else
                            perfs = Int(itercnt(1) / seccnt(1))
                        End If
                        Display()
                    End If
                End If
            End If
        Loop
    End Sub

    Private Sub cancelAsyncButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelAsyncButton.Click

        Test()

        If cancelAsyncButton.Text = "Stop" Then
            holdreq = 2
            ' See Master
        Else
            cancelAsyncButton.Text = "Stop"
            endAsyncButton.Enabled = True
            holdreq = 0
            holdrev = HoldT.Value
            If holdrev = Rev(1) Then holdrev = -1
            HoldT.Enabled = False
            itercnt(1) = 0 : seccnt(1) = -2
        End If

    End Sub

    Private Sub EndSyncButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles endAsyncButton.Click

        Test()
        If state(1) = ActiveSt Then
            startAsyncButton.Enabled = True
            cancelAsyncButton.Enabled = False
            tdeltaT.Enabled = True
            nplT.Enabled = True
            HoldT.Enabled = True
            state(1) = CancelSt
            holdreq = 0
        Else
            Debug.Print("Click End - no Error")
            End
        End If

    End Sub

 
    ' This event handler 1 updates the progress.
    Private Sub Display()
        Dim pl As Integer
        Dim r As Double
        If holdreq = 0 Then
            ResultLabelpp1.Text = perfs
        End If
        seccntT.Text = Str(seccnt(1))

        pl = Val(pl1T.Text)
        If pl < 0 Then pl = 0
        x1T.Text = Str(Int(x(pl)))
        y1T.Text = Str(Int(y(pl)))
        r = Sqrt(x(pl) * x(pl) + y(pl) * y(pl))
        r1T.Text = r
        rev1T.Text = Str(Rev(pl))

        pl = Val(pl2T.Text)
        If pl < 0 Then pl = 0
        x2T.Text = Str(Int(x(pl)))
        y2T.Text = Str(Int(y(pl)))
        r = Sqrt(x(pl) * x(pl) + y(pl) * y(pl))
        r2T.Text = r
        rev2T.Text = Str(Rev(pl))

        pl = Val(pl3T.Text)
        If pl < 0 Then pl = 0
        x3T.Text = Str(Int(x(pl)))
        y3T.Text = Str(Int(y(pl)))
        r = Sqrt(x(pl) * x(pl) + y(pl) * y(pl))
        r3T.Text = r
        rev3T.Text = Str(Rev(pl))

        pl = Val(pl4T.Text)
        If pl < 0 Then pl = 0
        x4T.Text = Str(Int(x(pl)))
        y4T.Text = Str(Int(y(pl)))
        r = Sqrt(x(pl) * x(pl) + y(pl) * y(pl))
        r4T.Text = r
        rev4T.Text = Str(Rev(pl))

    End Sub




    Private Sub Init()

        Dim i As Integer

        For i = 0 To idim
            x(i) = 0 : y(i) = 0 : z(i) = 0
            vx(i) = 0 : vy(i) = 0 : vz(i) = 0
            ax(i) = 0 : ay(i) = 0 : az(i) = 0
            pl_itercnt(i) = 0
            Rev(i) = 0     ' Revolution counter
        Next

        m(0) = 1000
        errorc = 0

        For i = 1 To nplanets
            m(i) = 0
            x(i) = 1000 + (i - 1) * 100
            If x(i) <> 0 Then vy(i) = Sqrt(m(0) / x(i))
        Next

        Printa(x, Str(pl_itercnt(0)) + " x")
        Printa(vy, Str(pl_itercnt(0)) + " vy")

    End Sub

    Private Sub Test()
        Dim a As String
        Dim i, j As Integer
        For i = 0 To nplanets - 1
            If pl_itercnt(i) <> pl_itercnt(i + 1) Then
                errorc = 1
            End If
        Next i
        If errorc = 1 Then
            a = "Test error "
            For j = 0 To nplanets
                a = a + Str(j) + " " + Str(pl_itercnt(j)) + " "
            Next j
            Debug.Print(a)
        End If


    End Sub

    Private Sub Printa(ByVal xp(), ByVal str1)
        Dim b As String
        Dim j As Integer
        b = str1
        For j = 0 To nplanets
            b = b + Str(j) + " " + Str(xp(j)) + " "
        Next j
        Debug.Print(b)

    End Sub




    Private Sub InitializeForm()

        Me.startAsyncButton = New System.Windows.Forms.Button
        Me.cancelAsyncButton = New System.Windows.Forms.Button
        Me.endAsyncButton = New System.Windows.Forms.Button
        Me.Label2 = New System.Windows.Forms.Label
        Me.ResultLabelpp1 = New System.Windows.Forms.Label
        ' Me.tdeltaL = New System.Windows.Forms.Label
        ' Me.tdeltaT = New System.Windows.Forms.TextBox
        ' Me.seccntL = New System.Windows.Forms.Label
        ' Me.seccntT = New System.Windows.Forms.TextBox
        ' Me.nplL = New System.Windows.Forms.Label
        ' Me.nplT = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label3(2) = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.pl1T = New System.Windows.Forms.TextBox
        Me.pl2T = New System.Windows.Forms.TextBox
        Me.pl3T = New System.Windows.Forms.TextBox
        Me.pl4T = New System.Windows.Forms.TextBox
        Me.x1T = New System.Windows.Forms.TextBox
        Me.x2T = New System.Windows.Forms.TextBox
        Me.x3T = New System.Windows.Forms.TextBox
        Me.x4T = New System.Windows.Forms.TextBox
        Me.y1T = New System.Windows.Forms.TextBox
        Me.y2T = New System.Windows.Forms.TextBox
        Me.y3T = New System.Windows.Forms.TextBox
        Me.y4T = New System.Windows.Forms.TextBox
        Me.r1T = New System.Windows.Forms.TextBox
        Me.r2T = New System.Windows.Forms.TextBox
        Me.r3T = New System.Windows.Forms.TextBox
        Me.r4T = New System.Windows.Forms.TextBox
        Me.rev1T = New System.Windows.Forms.TextBox
        Me.rev2T = New System.Windows.Forms.TextBox
        Me.rev3T = New System.Windows.Forms.TextBox
        Me.rev4T = New System.Windows.Forms.TextBox


        Me.SuspendLayout()
        '
        'Row  1
        '
        hh = 12 : dhh = 34
        ddd = 70
        dd = 3
        Me.Label2.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.Label2.Location = New System.Drawing.Point(dd, hh)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(67, 13)
        Me.Label2.TabIndex = 16
        Me.Label2.Text = "Performance"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.TopLeft

        dd = dd + Label2.Width
        Me.ResultLabelpp1.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.ResultLabelpp1.Location = New System.Drawing.Point(dd, hh)
        Me.ResultLabelpp1.Name = "ResultLabelpp1"
        Me.ResultLabelpp1.Size = New System.Drawing.Size(36, 13)
        Me.ResultLabelpp1.TabIndex = 3
        Me.ResultLabelpp1.Text = "pp1"
        Me.ResultLabelpp1.TextAlign = System.Drawing.ContentAlignment.TopLeft

        dd = dd + ResultLabelpp1.Width
        Me.tdeltaL.Location = New System.Drawing.Point(dd, hh)

        dd = dd + tdeltaL.Width
        Me.tdeltaT.Location = New System.Drawing.Point(dd, hh)
        Me.tdeltaT.Size = New System.Drawing.Size(40, 20)

        dd = dd + tdeltaT.Width
        Me.seccntL.Location = New System.Drawing.Point(dd, hh)

        dd = dd + seccntL.Width
        Me.seccntT.Location = New System.Drawing.Point(dd, hh)
        Me.seccntT.Size = New System.Drawing.Size(40, 20)

        dd = dd + seccntT.Width
        Me.nplL.Location = New System.Drawing.Point(dd, hh)

        dd = dd + nplL.Width
        Me.nplT.Location = New System.Drawing.Point(dd, hh)
        Me.nplT.Size = New System.Drawing.Size(40, 20)
        '
        ' row 5 startAsyncButton   cancelAsyncButton  endAsyncButton
        '
        dd = 60
        hh = hh + dhh
        Me.startAsyncButton.Location = New System.Drawing.Point(dd, hh)
        Me.startAsyncButton.Name = "startAsyncButton"
        Me.startAsyncButton.Size = New System.Drawing.Size(63, 25)
        Me.startAsyncButton.TabIndex = 0
        Me.startAsyncButton.Text = "Start"

        dd = dd + ddd
        Me.cancelAsyncButton.Enabled = True
        Me.cancelAsyncButton.Location = New System.Drawing.Point(dd, hh)
        Me.cancelAsyncButton.Name = "cancelAsyncButton"
        Me.cancelAsyncButton.Size = New System.Drawing.Size(63, 25)
        Me.cancelAsyncButton.TabIndex = 1
        Me.cancelAsyncButton.Text = "Stop"

        dd = dd + ddd
        Me.endAsyncButton.Location = New System.Drawing.Point(dd, hh)
        Me.endAsyncButton.Name = "EndAsyncButton"
        Me.endAsyncButton.Size = New System.Drawing.Size(63, 25)
        Me.endAsyncButton.TabIndex = 2
        Me.endAsyncButton.Text = "End"

        dd = dd + ddd
        Me.HoldL.Location = New System.Drawing.Point(dd, hh)
        Me.HoldL.Size = New System.Drawing.Size(29, 13)

        dd = dd + HoldL.Width
        Me.HoldT.Location = New System.Drawing.Point(dd, hh)
        Me.HoldT.Size = New System.Drawing.Size(40, 20)
        '
        'Row  6    Planet  x  y  r  rev
        '
        dd = 80
        hh = hh + dhh
        Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.Label1.Location = New System.Drawing.Point(6, hh)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(40, 13)
        Me.Label1.TabIndex = 3
        Me.Label1.Text = "Planet"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.TopLeft

        Me.Label3(2).BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.Label3(2).Location = New System.Drawing.Point(dd, hh)
        Me.Label3(2).Name = "Label3(2)"
        Me.Label3(2).Size = New System.Drawing.Size(12, 13)
        Me.Label3(2).TabIndex = 3
        Me.Label3(2).Text = "x"
        Me.Label3(2).TextAlign = System.Drawing.ContentAlignment.TopLeft

        dd = dd + ddd
        Me.Label4.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.Label4.Location = New System.Drawing.Point(dd, hh)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(15, 13)
        Me.Label4.TabIndex = 3
        Me.Label4.Text = "y"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.TopLeft

        dd = dd + ddd
        Me.Label5.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.Label5.Location = New System.Drawing.Point(dd, hh)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(12, 13)
        Me.Label5.TabIndex = 3
        Me.Label5.Text = "r"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.TopLeft

        dd = dd + ddd
        Me.Label6.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.Label6.Location = New System.Drawing.Point(dd, hh)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(22, 13)
        Me.Label6.TabIndex = 3
        Me.Label6.Text = "rev"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.TopLeft
        '
        'Row  7    Planet 1
        '
        dhh = 25
        hh = hh + dhh    'hh=200
        Me.pl1T.Location = New System.Drawing.Point(13, hh)
        Me.pl1T.Name = "pl1T"
        Me.pl1T.Size = New System.Drawing.Size(21, 20)
        Me.pl1T.TabIndex = 3
        Me.pl1T.Text = "1"
        Me.pl1T.TextAlign = System.Drawing.ContentAlignment.TopLeft    ' right !
        dd = 60
        Me.x1T.Location = New System.Drawing.Point(dd, hh)
        Me.x1T.Name = "x1T"
        Me.x1T.Size = New System.Drawing.Size(61, 20)
        Me.x1T.TabIndex = 3
        Me.x1T.Text = "0"
        Me.x1T.TextAlign = System.Drawing.ContentAlignment.TopLeft
        dd = dd + ddd
        Me.y1T.Location = New System.Drawing.Point(dd, hh)
        Me.y1T.Name = "y1T"
        Me.y1T.Size = New System.Drawing.Size(61, 20)
        Me.y1T.TabIndex = 3
        Me.y1T.Text = "0"
        Me.y1T.TextAlign = System.Drawing.ContentAlignment.TopLeft
        dd = dd + ddd
        Me.r1T.Location = New System.Drawing.Point(dd, hh)
        Me.r1T.Name = "r1T"
        Me.r1T.Size = New System.Drawing.Size(61, 20)
        Me.r1T.TabIndex = 3
        Me.r1T.Text = "0"
        dd = dd + ddd
        Me.rev1T.Location = New System.Drawing.Point(dd, hh)
        Me.rev1T.Name = "rev1T"
        Me.rev1T.Size = New System.Drawing.Size(61, 20)
        Me.rev1T.TabIndex = 3
        Me.rev1T.Text = "0"
        Me.rev1T.TextAlign = System.Drawing.ContentAlignment.TopLeft    ' right !
        '
        'Row  8    Planet 2
        '
        hh = hh + dhh
        Me.pl2T.Location = New System.Drawing.Point(13, hh)
        Me.pl2T.Name = "pl2T"
        Me.pl2T.Size = New System.Drawing.Size(21, 20)
        Me.pl2T.TabIndex = 3
        Me.pl2T.Text = "2"
        Me.pl2T.TextAlign = System.Drawing.ContentAlignment.TopLeft    ' right !
        dd = 60
        Me.x2T.Location = New System.Drawing.Point(dd, hh)
        Me.x2T.Name = "x2T"
        Me.x2T.Size = New System.Drawing.Size(61, 20)
        Me.x2T.TabIndex = 3
        Me.x2T.Text = "0"
        Me.x2T.TextAlign = System.Drawing.ContentAlignment.TopLeft
        dd = dd + ddd
        Me.y2T.Location = New System.Drawing.Point(dd, hh)
        Me.y2T.Name = "y2T"
        Me.y2T.Size = New System.Drawing.Size(61, 20)
        Me.y2T.TabIndex = 3
        Me.y2T.Text = "0"
        Me.y2T.TextAlign = System.Drawing.ContentAlignment.TopLeft
        dd = dd + ddd
        Me.r2T.Location = New System.Drawing.Point(dd, hh)
        Me.r2T.Name = "r2T"
        Me.r2T.Size = New System.Drawing.Size(61, 20)
        Me.r2T.TabIndex = 3
        Me.r2T.Text = "0"
        dd = dd + ddd
        Me.rev2T.Location = New System.Drawing.Point(dd, hh)
        Me.rev2T.Name = "rev2T"
        Me.rev2T.Size = New System.Drawing.Size(61, 20)
        Me.rev2T.TabIndex = 3
        Me.rev2T.Text = "0"
        Me.rev2T.TextAlign = System.Drawing.ContentAlignment.TopLeft    ' right !
        '
        'Row  9    Planet 3
        '
        hh = hh + dhh
        Me.pl3T.Location = New System.Drawing.Point(13, hh)
        Me.pl3T.Name = "pl3T"
        Me.pl3T.Size = New System.Drawing.Size(21, 20)
        Me.pl3T.TabIndex = 3
        Me.pl3T.Text = "3"
        Me.pl3T.TextAlign = System.Drawing.ContentAlignment.TopLeft
        dd = 60
        Me.x3T.Location = New System.Drawing.Point(dd, hh)
        Me.x3T.Name = "x3T"
        Me.x3T.Size = New System.Drawing.Size(61, 20)
        Me.x3T.TabIndex = 3
        Me.x3T.Text = "0"
        Me.x3T.TextAlign = System.Drawing.ContentAlignment.TopLeft
        dd = dd + ddd
        Me.y3T.Location = New System.Drawing.Point(dd, hh)
        Me.y3T.Name = "y3T"
        Me.y3T.Size = New System.Drawing.Size(61, 20)
        Me.y3T.TabIndex = 3
        Me.y3T.Text = "0"
        Me.y3T.TextAlign = System.Drawing.ContentAlignment.TopLeft
        dd = dd + ddd
        Me.r3T.Location = New System.Drawing.Point(dd, hh)
        Me.r3T.Name = "r3T"
        Me.r3T.Size = New System.Drawing.Size(61, 20)
        Me.r3T.TabIndex = 3
        Me.r3T.Text = "0"
        dd = dd + ddd
        Me.rev3T.Location = New System.Drawing.Point(dd, hh)
        Me.rev3T.Name = "rev3T"
        Me.rev3T.Size = New System.Drawing.Size(61, 20)
        Me.rev3T.TabIndex = 3
        Me.rev3T.Text = "0"
        Me.rev3T.TextAlign = System.Drawing.ContentAlignment.TopLeft    ' right !
        '
        'Row  10    Planet 4
        '
        hh = hh + dhh
        Me.pl4T.Location = New System.Drawing.Point(13, hh)
        Me.pl4T.Name = "pl4T"
        Me.pl4T.Size = New System.Drawing.Size(21, 20)
        Me.pl4T.TabIndex = 3
        Me.pl4T.Text = "4"
        Me.pl4T.TextAlign = System.Drawing.ContentAlignment.TopLeft    ' right !
        dd = 60
        Me.x4T.Location = New System.Drawing.Point(dd, hh)
        Me.x4T.Name = "x4T"
        Me.x4T.Size = New System.Drawing.Size(61, 20)
        Me.x4T.TabIndex = 3
        Me.x4T.Text = "0"
        Me.x4T.TextAlign = System.Drawing.ContentAlignment.TopLeft
        dd = dd + ddd
        Me.y4T.Location = New System.Drawing.Point(dd, hh)
        Me.y4T.Name = "y4T"
        Me.y4T.Size = New System.Drawing.Size(61, 20)
        Me.y4T.TabIndex = 3
        Me.y4T.Text = "0"
        Me.y4T.TextAlign = System.Drawing.ContentAlignment.TopLeft
        dd = dd + ddd
        Me.r4T.Location = New System.Drawing.Point(dd, hh)
        Me.r4T.Name = "r4T"
        Me.r4T.Size = New System.Drawing.Size(61, 20)
        Me.r4T.TabIndex = 3
        Me.r4T.Text = "0"
        dd = dd + ddd
        Me.rev4T.Location = New System.Drawing.Point(dd, hh)
        Me.rev4T.Name = "rev4T"
        Me.rev4T.Size = New System.Drawing.Size(61, 20)
        Me.rev4T.TabIndex = 3
        Me.rev4T.Text = "0"
        Me.rev4T.TextAlign = System.Drawing.ContentAlignment.TopLeft    ' right !
        '
        'backgroundWorkerpp1
        '
        '
        'PlanetForm
        '
        Me.ClientSize = New System.Drawing.Size(dd + ddd, hh + dhh + 10)
        Me.Controls.Add(Me.cancelAsyncButton)
        Me.Controls.Add(Me.startAsyncButton)
        Me.Controls.Add(Me.endAsyncButton)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.ResultLabelpp1)
        Me.Controls.Add(Me.tdeltaL)
        Me.Controls.Add(Me.tdeltaT)
        Me.Controls.Add(Me.seccntL)
        Me.Controls.Add(Me.seccntT)
        Me.Controls.Add(Me.nplL)
        Me.Controls.Add(Me.nplT)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Label3(2))
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.pl1T)
        Me.Controls.Add(Me.x1T)
        Me.Controls.Add(Me.y1T)
        Me.Controls.Add(Me.r1T)
        Me.Controls.Add(Me.rev1T)
        Me.Controls.Add(Me.pl2T)
        Me.Controls.Add(Me.x2T)
        Me.Controls.Add(Me.y2T)
        Me.Controls.Add(Me.r2T)
        Me.Controls.Add(Me.rev2T)
        Me.Controls.Add(Me.pl3T)
        Me.Controls.Add(Me.x3T)
        Me.Controls.Add(Me.y3T)
        Me.Controls.Add(Me.r3T)
        Me.Controls.Add(Me.rev3T)
        Me.Controls.Add(Me.pl4T)
        Me.Controls.Add(Me.x4T)
        Me.Controls.Add(Me.y4T)
        Me.Controls.Add(Me.r4T)
        Me.Controls.Add(Me.rev4T)


        Me.Name = "PlanetSForm"
        Me.Text = "PlanetS Simulation"
        Me.ResumeLayout(False)


    End Sub 'InitializeComponent

     _
    Shared Sub Main()
        Application.Run(New PlanetSForm)
    End Sub 'Main
End Class 'PlanetSForm