Results 1 to 5 of 5

Thread: convert a peace of code from powerbasic to VB6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2018
    Posts
    20

    convert a peace of code from powerbasic to VB6

    Hello,
    I want to use this proc. as function under VB6, forget FunargIAU(), TWOPI,amodulo,A2R, and other Const... JulCity, J2000.
    Then i need help to convert it to VB6 function, will be glad for assistance.
    sub GetDpsiDeps(jed as double, dpsi as double, deps as double, _
    dpsidot as double, depsdot as double) static

    '----- Subprogram to compute dpsi, deps, dpsidot,
    '----- and depsdot.
    '----- Input: jed Julian day number on TDB scale
    '----- Output: dpsi nutation in longitude
    '----- deps nutation in obliquity
    '----- dpsidot derivative of dpsi in
    '----- radians/day
    '----- depsdot derivative of deps in
    '----- radians/day
    '-------------------------------------------------------------------------

    dim jedZ as double
    dim NutTermsRead as integer
    dim nc(min,2) as double
    dim FunArg(min,1) as double
    dim j as integer
    dim k as integer
    dim L as double
    dim Ldot as double
    dim lp as double
    dim lpdot as double
    dim f as double
    dim fdot as double
    dim d as double
    dim ddot as double
    dim n as double
    dim ndot as double
    dim LL as double
    dim LLdot as double
    dim t as double
    dim c1 as double
    dim c2 as double
    dim c3 as double
    dim c4 as double
    dim c5 as double
    dim lamp as double
    dim oamp as double
    dim ls as double
    dim os as double
    dim arg as double
    dim argdot as double

    '----- Read the coefficients from the data statements
    '----- only if not already done.
    if (NutTermsRead = 0) then
    redim nc(1 to 106, 1 to 9)
    redim FunArg(1 to 12)
    restore Terms
    for j = 1 to 106
    for k = 1 to 9
    read nc(j,k)
    next k
    next j
    NutTermsRead = 1
    end if

    t = (jed - J2000.0) / JulCty

    call FunArgIAU(jed, FunArg())
    L = FunArg(1) : Ldot = FunArg(7)
    lp = FunArg(2) : LPdot = FunArg(8)
    f = FunArg(3) : fdot = FunArg(9)
    d = FunArg(4) : ddot = FunArg(10)
    n = FunArg(5) : ndot = FunArg(11)
    LL = FunArg(6) : LLdot = FunArg(12)

    '----- evaluate the series
    dpsi = 0# '----- initialize to zero
    deps = 0#
    dpsidot = 0#
    depsdot = 0#
    for j = 1 to 106
    lamp = nc(j,1)
    oamp = nc(j,3)
    ls = nc(j,2)
    os = nc(j,4)
    c1 = nc(j,5)
    c2 = nc(j,6)
    c3 = nc(j,7)
    c4 = nc(j,8)
    c5 = nc(j,9)
    arg = c1 * L + c2 * LP + c3 * F + c4 * D + c5 * N
    arg = amodulo(arg, TWOPI)
    dpsi = dpsi + (lamp + ls * t) * sin(arg)
    deps = deps + (oamp + os * t) * cos(arg)
    argdot = c1 * Ldot + c2 * LPdot + c3 * fdot + c4 * ddot + c5 * ndot
    argdot = amodulo(argdot, TWOPI)
    dpsidot = dpsidot + (lamp + ls * t) * argdot * cos(arg)_
    + ls * sin(arg) / JulCty
    depsdot = depsdot - (oamp + os * t) * argdot * sin(arg)_
    + os * cos(arg) / JulCty
    next j

    '----- normalize and convert units
    dpsi = dpsi * 0.0001# * A2R
    deps = deps * 0.0001# * A2R
    dpsidot = dpsidot * 0.0001# * A2R
    depsdot = depsdot * 0.0001# * A2R

    '----- coefficients for IAU 1980 nutation theory
    Terms:
    data -171996#, -174.2#, 92025#, 8.9#, 0#, 0#, 0#, 0#, 1#
    data 2062#, 0.2#, -895#, 0.5#, 0#, 0#, 0#, 0#, 2#
    data 46#, 0#, -24#, 0#, -2#, 0#, 2#, 0#, 1#
    data 11#, 0#, 0#, 0#, 2#, 0#,-2#, 0#, 0#
    data -3#, 0#, 1#, 0#, -2#, 0#, 2#, 0#, 2#
    data -3#, 0#, 0#, 0#, 1#,-1#, 0#,-1#, 0#
    data -2#, 0#, 1#, 0#, 0#,-2#, 2#,-2#, 1#
    data 1#, 0#, 0#, 0#, 2#, 0#,-2#, 0#, 1#
    data -13187#, -1.6#, 5736#,-3.1#, 0#, 0#, 2#,-2#, 2#
    data 1426#, -3.4#, 54#,-0.1#, 0#, 1#, 0#, 0#, 0#
    data -517#, 1.2#, 224#,-0.6#, 0#, 1#, 2#,-2#, 2#
    data 217#, -0.5#, -95#, 0.3#, 0#,-1#, 2#,-2#, 2#
    data 129#, 0.1#, -70#, 0#, 0#, 0#, 2#,-2#, 1#
    data 48#, 0#, 1#, 0#, 2#, 0#, 0#,-2#, 0#
    data -22#, 0#, 0#, 0#, 0#, 0#, 2#,-2#, 0#
    data 17#, -0.1#, 0#, 0#, 0#, 2#, 0#, 0#, 0#
    data -15#, 0#, 9#, 0#, 0#, 1#, 0#, 0#, 1#
    data -16#, 0.1#, 7#, 0#, 0#, 2#, 2#,-2#, 2#
    data -12#, 0#, 6#, 0#, 0#,-1#, 0#, 0#, 1#
    data -6#, 0#, 3#, 0#, -2#, 0#, 0#, 2#, 1#
    data -5#, 0#, 3#, 0#, 0#,-1#, 2#,-2#, 1#
    data 4#, 0#, -2#, 0#, 2#, 0#, 0#,-2#, 1#
    data 4#, 0#, -2#, 0#, 0#, 1#, 2#,-2#, 1#
    data -4#, 0#, 0#, 0#, 1#, 0#, 0#,-1#, 0#
    data 1#, 0#, 0#, 0#, 2#, 1#, 0#,-2#, 0#
    data 1#, 0#, 0#, 0#, 0#, 0#,-2#, 2#, 1#
    data -1#, 0#, 0#, 0#, 0#, 1#,-2#, 2#, 0#
    data 1#, 0#, 0#, 0#, 0#, 1#, 0#, 0#, 2#
    data 1#, 0#, 0#, 0#, -1#, 0#, 0#, 1#, 1#
    data -1#, 0#, 0#, 0#, 0#, 1#, 2#,-2#, 0#
    data -2274#, -0.2#, 977#,-0.5#, 0#, 0#, 2#, 0#, 2#
    data 712#, 0.1#, -7#, 0#, 1#, 0#, 0#, 0#, 0#
    data -386#, -0.4#, 200#, 0#, 0#, 0#, 2#, 0#, 1#
    data -301#, 0#, 129#,-0.1#, 1#, 0#, 2#, 0#, 2#
    data -158#, 0#, -1#, 0#, 1#, 0#, 0#,-2#, 0#
    data 123#, 0#, -53#, 0#, -1#, 0#, 2#, 0#, 2#
    data 63#, 0#, -2#, 0#, 0#, 0#, 0#, 2#, 0#
    data 63#, 0.1#, -33#, 0#, 1#, 0#, 0#, 0#, 1#
    data -58#, -0.1#, 32#, 0#, -1#, 0#, 0#, 0#, 1#
    data -59#, 0#, 26#, 0#, -1#, 0#, 2#, 2#, 2#
    data -51#, 0#, 27#, 0#, 1#, 0#, 2#, 0#, 1#
    data -38#, 0#, 16#, 0#, 0#, 0#, 2#, 2#, 2#
    data 29#, 0#, -1#, 0#, 2#, 0#, 0#, 0#, 0#
    data 29#, 0#, -12#, 0#, 1#, 0#, 2#,-2#, 2#
    data -31#, 0#, 13#, 0#, 2#, 0#, 2#, 0#, 2#
    data 26#, 0#, -1#, 0#, 0#, 0#, 2#, 0#, 0#
    data 21#, 0#, -10#, 0#, -1#, 0#, 2#, 0#, 1#
    data 16#, 0#, -8#, 0#, -1#, 0#, 0#, 2#, 1#
    data -13#, 0#, 7#, 0#, 1#, 0#, 0#,-2#, 1#
    data -10#, 0#, 5#, 0#, -1#, 0#, 2#, 2#, 1#
    data -7#, 0#, 0#, 0#, 1#, 1#, 0#,-2#, 0#
    data 7#, 0#, -3#, 0#, 0#, 1#, 2#, 0#, 2#
    data -7#, 0#, 3#, 0#, 0#,-1#, 2#, 0#, 2#
    data -8#, 0#, 3#, 0#, 1#, 0#, 2#, 2#, 2#
    data 6#, 0#, 0#, 0#, 1#, 0#, 0#, 2#, 0#
    data 6#, 0#, -3#, 0#, 2#, 0#, 2#,-2#, 2#
    data -6#, 0#, 3#, 0#, 0#, 0#, 0#, 2#, 1#
    data -7#, 0#, 3#, 0#, 0#, 0#, 2#, 2#, 1#
    data 6#, 0#, -3#, 0#, 1#, 0#, 2#,-2#, 1#
    data -5#, 0#, 3#, 0#, 0#, 0#, 0#,-2#, 1#
    data 5#, 0#, 0#, 0#, 1#,-1#, 0#, 0#, 0#
    data -5#, 0#, 3#, 0#, 2#, 0#, 2#, 0#, 1#
    data -4#, 0#, 0#, 0#, 0#, 1#, 0#,-2#, 0#
    data 4#, 0#, 0#, 0#, 1#, 0#,-2#, 0#, 0#
    data -4#, 0#, 0#, 0#, 0#, 0#, 0#, 1#, 0#
    data -3#, 0#, 0#, 0#, 1#, 1#, 0#, 0#, 0#
    data 3#, 0#, 0#, 0#, 1#, 0#, 2#, 0#, 0#
    data -3#, 0#, 1#, 0#, 1#,-1#, 2#, 0#, 2#
    data -3#, 0#, 1#, 0#, -1#,-1#, 2#, 2#, 2#
    data -2#, 0#, 1#, 0#, -2#, 0#, 0#, 0#, 1#
    data -3#, 0#, 1#, 0#, 3#, 0#, 2#, 0#, 2#
    data -3#, 0#, 1#, 0#, 0#,-1#, 2#, 2#, 2#
    data 2#, 0#, -1#, 0#, 1#, 1#, 2#, 0#, 2#
    data -2#, 0#, 1#, 0#, -1#, 0#, 2#,-2#, 1#
    data 2#, 0#, -1#, 0#, 2#, 0#, 0#, 0#, 1#
    data -2#, 0#, 1#, 0#, 1#, 0#, 0#, 0#, 2#
    data 2#, 0#, 0#, 0#, 3#, 0#, 0#, 0#, 0#
    data 2#, 0#, -1#, 0#, 0#, 0#, 2#, 1#, 2#
    data 1#, 0#, -1#, 0#, -1#, 0#, 0#, 0#, 2#
    data -1#, 0#, 0#, 0#, 1#, 0#, 0#,-4#, 0#
    data 1#, 0#, -1#, 0#, -2#, 0#, 2#, 2#, 2#
    data -2#, 0#, 1#, 0#, -1#, 0#, 2#, 4#, 2#
    data -1#, 0#, 0#, 0#, 2#, 0#, 0#,-4#, 0#
    data 1#, 0#, -1#, 0#, 1#, 1#, 2#,-2#, 2#
    data -1#, 0#, 1#, 0#, 1#, 0#, 2#, 2#, 1#
    data -1#, 0#, 1#, 0#, -2#, 0#, 2#, 4#, 2#
    data 1#, 0#, 0#, 0#, -1#, 0#, 4#, 0#, 2#
    data 1#, 0#, 0#, 0#, 1#,-1#, 0#,-2#, 0#
    data 1#, 0#, -1#, 0#, 2#, 0#, 2#,-2#, 1#
    data -1#, 0#, 0#, 0#, 2#, 0#, 2#, 2#, 2#
    data -1#, 0#, 0#, 0#, 1#, 0#, 0#, 2#, 1#
    data 1#, 0#, 0#, 0#, 0#, 0#, 4#,-2#, 2#
    data 1#, 0#, 0#, 0#, 3#, 0#, 2#,-2#, 2#
    data -1#, 0#, 0#, 0#, 1#, 0#, 2#,-2#, 0#
    data 1#, 0#, 0#, 0#, 0#, 1#, 2#, 0#, 1#
    data 1#, 0#, 0#, 0#, -1#,-1#, 0#, 2#, 1#
    data -1#, 0#, 0#, 0#, 0#, 0#,-2#, 0#, 1#
    data -1#, 0#, 0#, 0#, 0#, 0#, 2#,-1#, 2#
    data -1#, 0#, 0#, 0#, 0#, 1#, 0#, 2#, 0#
    data -1#, 0#, 0#, 0#, 1#, 0#,-2#,-2#, 0#
    data -1#, 0#, 0#, 0#, 0#,-1#, 2#, 0#, 1#
    data -1#, 0#, 0#, 0#, 1#, 1#, 0#,-2#, 1#
    data -1#, 0#, 0#, 0#, 1#, 0#,-2#, 2#, 0#
    data 1#, 0#, 0#, 0#, 2#, 0#, 0#, 2#, 0#
    data -1#, 0#, 0#, 0#, 0#, 0#, 2#, 4#, 2#
    data 1#, 0#, 0#, 0#, 0#, 1#, 0#, 1#, 0#
    '----- end of IAU 1980 nutation coefficients

    end sub

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,176

    Re: convert a peace of code from powerbasic to VB6

    VB6 doesn’t support these data statements, so you have to come with an alternative.
    Also you have to check the other methods which are not supported by VB6

  3. #3
    Hyperactive Member
    Join Date
    Jul 2022
    Posts
    383

    Re: convert a peace of code from powerbasic to VB6

    You could dump the data in a csv and load the array from that data. I'll give it a go.

    EDIT:
    Just changed a couple things to make VB6 happy, everything else here is just copying the calcs you want into this:

    Code:
    Static Sub GetDpsiDeps(jed As Double, dpsi As Double, deps As Double, dpsidot As Double, depsdot As Double)
    
        Dim jedZ As Double
        Dim NutTermsRead As Integer
        Dim nc() As Double
        Dim FunArg(1, 1) As Double
        Dim j As Integer
        Dim k As Integer
        Dim L As Double
        Dim Ldot As Double
        Dim lp As Double
        Dim lpdot As Double
        Dim f As Double
        Dim fdot As Double
        Dim d As Double
        Dim ddot As Double
        Dim n As Double
        Dim ndot As Double
        Dim LL As Double
        Dim LLdot As Double
        Dim t As Double
        Dim c1 As Double
        Dim c2 As Double
        Dim c3 As Double
        Dim c4 As Double
        Dim c5 As Double
        Dim lamp As Double
        Dim oamp As Double
        Dim ls As Double
        Dim os As Double
        Dim arg As Double
        Dim argdot As Double
        
        ' open the text file that contains the data
        Dim fs As FileSystemObject ' ******* need to reference Microsoft Scripting Runtime
        Dim coefficientsFile As TextStream
        Dim textFileData() As String
        
        Set fs = New FileSystemObject
        Set coefficientsFile = fs.OpenTextFile("C:\Temp\coefficients_for_IAU_1980_nutation_theory.csv", ForReading)
        
        '----- Read the coefficients from the data statements
        '----- only if not already done.
        If (NutTermsRead = 0) Then
            ReDim nc(1 To 106, 1 To 9) As Double
            'ReDim FunArg(1 To 12) As Double
            
            For j = 1 To 106
                textFileData = Split(coefficientsFile.ReadLine, ",")
                For k = 1 To 9
                    nc(j, k) = CDbl(textFileData(k - 1))
                Next k
            Next j
            NutTermsRead = 1
        End If
        
        coefficientsFile.Close
        Set coefficientsFile = Nothing
        Set fs = Nothing
        
        
    End Sub

    copy this into a text file, name it and change the code to open it
    Code:
    -171996, -174.2, 92025, 8.9, 0, 0, 0, 0, 1
    2062, 0.2, -895, 0.5, 0, 0, 0, 0, 2
    46, 0, -24, 0, -2, 0, 2, 0, 1
    11, 0, 0, 0, 2, 0,-2, 0, 0
    -3, 0, 1, 0, -2, 0, 2, 0, 2
    -3, 0, 0, 0, 1,-1, 0,-1, 0
    -2, 0, 1, 0, 0,-2, 2,-2, 1
    1, 0, 0, 0, 2, 0,-2, 0, 1
    -13187, -1.6, 5736,-3.1, 0, 0, 2,-2, 2
    1426, -3.4, 54,-0.1, 0, 1, 0, 0, 0
    -517, 1.2, 224,-0.6, 0, 1, 2,-2, 2
    217, -0.5, -95, 0.3, 0,-1, 2,-2, 2
    129, 0.1, -70, 0, 0, 0, 2,-2, 1
    48, 0, 1, 0, 2, 0, 0,-2, 0
    -22, 0, 0, 0, 0, 0, 2,-2, 0
    17, -0.1, 0, 0, 0, 2, 0, 0, 0
    -15, 0, 9, 0, 0, 1, 0, 0, 1
    -16, 0.1, 7, 0, 0, 2, 2,-2, 2
    -12, 0, 6, 0, 0,-1, 0, 0, 1
    -6, 0, 3, 0, -2, 0, 0, 2, 1
    -5, 0, 3, 0, 0,-1, 2,-2, 1
    4, 0, -2, 0, 2, 0, 0,-2, 1
    4, 0, -2, 0, 0, 1, 2,-2, 1
    -4, 0, 0, 0, 1, 0, 0,-1, 0
    1, 0, 0, 0, 2, 1, 0,-2, 0
    1, 0, 0, 0, 0, 0,-2, 2, 1
    -1, 0, 0, 0, 0, 1,-2, 2, 0
    1, 0, 0, 0, 0, 1, 0, 0, 2
    1, 0, 0, 0, -1, 0, 0, 1, 1
    -1, 0, 0, 0, 0, 1, 2,-2, 0
    -2274, -0.2, 977,-0.5, 0, 0, 2, 0, 2
    712, 0.1, -7, 0, 1, 0, 0, 0, 0
    -386, -0.4, 200, 0, 0, 0, 2, 0, 1
    -301, 0, 129,-0.1, 1, 0, 2, 0, 2
    -158, 0, -1, 0, 1, 0, 0,-2, 0
    123, 0, -53, 0, -1, 0, 2, 0, 2
    63, 0, -2, 0, 0, 0, 0, 2, 0
    63, 0.1, -33, 0, 1, 0, 0, 0, 1
    -58, -0.1, 32, 0, -1, 0, 0, 0, 1
    -59, 0, 26, 0, -1, 0, 2, 2, 2
    -51, 0, 27, 0, 1, 0, 2, 0, 1
    -38, 0, 16, 0, 0, 0, 2, 2, 2
    29, 0, -1, 0, 2, 0, 0, 0, 0
    29, 0, -12, 0, 1, 0, 2,-2, 2
    -31, 0, 13, 0, 2, 0, 2, 0, 2
    26, 0, -1, 0, 0, 0, 2, 0, 0
    21, 0, -10, 0, -1, 0, 2, 0, 1
    16, 0, -8, 0, -1, 0, 0, 2, 1
    -13, 0, 7, 0, 1, 0, 0,-2, 1
    -10, 0, 5, 0, -1, 0, 2, 2, 1
    -7, 0, 0, 0, 1, 1, 0,-2, 0
    7, 0, -3, 0, 0, 1, 2, 0, 2
    -7, 0, 3, 0, 0,-1, 2, 0, 2
    -8, 0, 3, 0, 1, 0, 2, 2, 2
    6, 0, 0, 0, 1, 0, 0, 2, 0
    6, 0, -3, 0, 2, 0, 2,-2, 2
    -6, 0, 3, 0, 0, 0, 0, 2, 1
    -7, 0, 3, 0, 0, 0, 2, 2, 1
    6, 0, -3, 0, 1, 0, 2,-2, 1
    -5, 0, 3, 0, 0, 0, 0,-2, 1
    5, 0, 0, 0, 1,-1, 0, 0, 0
    -5, 0, 3, 0, 2, 0, 2, 0, 1
    -4, 0, 0, 0, 0, 1, 0,-2, 0
    4, 0, 0, 0, 1, 0,-2, 0, 0
    -4, 0, 0, 0, 0, 0, 0, 1, 0
    -3, 0, 0, 0, 1, 1, 0, 0, 0
    3, 0, 0, 0, 1, 0, 2, 0, 0
    -3, 0, 1, 0, 1,-1, 2, 0, 2
    -3, 0, 1, 0, -1,-1, 2, 2, 2
    -2, 0, 1, 0, -2, 0, 0, 0, 1
    -3, 0, 1, 0, 3, 0, 2, 0, 2
    -3, 0, 1, 0, 0,-1, 2, 2, 2
    2, 0, -1, 0, 1, 1, 2, 0, 2
    -2, 0, 1, 0, -1, 0, 2,-2, 1
    2, 0, -1, 0, 2, 0, 0, 0, 1
    -2, 0, 1, 0, 1, 0, 0, 0, 2
    2, 0, 0, 0, 3, 0, 0, 0, 0
    2, 0, -1, 0, 0, 0, 2, 1, 2
    1, 0, -1, 0, -1, 0, 0, 0, 2
    -1, 0, 0, 0, 1, 0, 0,-4, 0
    1, 0, -1, 0, -2, 0, 2, 2, 2
    -2, 0, 1, 0, -1, 0, 2, 4, 2
    -1, 0, 0, 0, 2, 0, 0,-4, 0
    1, 0, -1, 0, 1, 1, 2,-2, 2
    -1, 0, 1, 0, 1, 0, 2, 2, 1
    -1, 0, 1, 0, -2, 0, 2, 4, 2
    1, 0, 0, 0, -1, 0, 4, 0, 2
    1, 0, 0, 0, 1,-1, 0,-2, 0
    1, 0, -1, 0, 2, 0, 2,-2, 1
    -1, 0, 0, 0, 2, 0, 2, 2, 2
    -1, 0, 0, 0, 1, 0, 0, 2, 1
    1, 0, 0, 0, 0, 0, 4,-2, 2
    1, 0, 0, 0, 3, 0, 2,-2, 2
    -1, 0, 0, 0, 1, 0, 2,-2, 0
    1, 0, 0, 0, 0, 1, 2, 0, 1
    1, 0, 0, 0, -1,-1, 0, 2, 1
    -1, 0, 0, 0, 0, 0,-2, 0, 1
    -1, 0, 0, 0, 0, 0, 2,-1, 2
    -1, 0, 0, 0, 0, 1, 0, 2, 0
    -1, 0, 0, 0, 1, 0,-2,-2, 0
    -1, 0, 0, 0, 0,-1, 2, 0, 1
    -1, 0, 0, 0, 1, 1, 0,-2, 1
    -1, 0, 0, 0, 1, 0,-2, 2, 0
    1, 0, 0, 0, 2, 0, 0, 2, 0
    -1, 0, 0, 0, 0, 0, 2, 4, 2
    1, 0, 0, 0, 0, 1, 0, 1, 0
    Attached Images Attached Images  
    Last edited by jdelano; Jun 19th, 2024 at 05:40 AM.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2018
    Posts
    20

    Re: convert a peace of code from powerbasic to VB6

    Awsome !
    Very nice, data are stored in csv file.
    thank you very match jdelano .

  5. #5
    Hyperactive Member
    Join Date
    Jul 2022
    Posts
    383

    Re: convert a peace of code from powerbasic to VB6

    You're welcome, happy to lend a hand.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width