Journal MickLinux's Journal: Parker Sochacki VB Macro for multiply
Function CSP(TayA1 As Variant, TayA2 As Variant, PC1 As Variant, IncPd As Variant, RowNo As Variant, konst As Double) As Variant
; © Mike Rudmin, released under Creative Commons Share-Alike and Attribute License.
; If this is not good enough, specific permission is given to reverse engineer or read the
; document, and rewrite from scratch.
Rem TayA1 and TayA2 are Example GREEN
Rem PC1 is Example Blue
Rem IncPd is Example Red
Dim TA1(0 To 5000)
Dim TA2(0 To 5000)
Dim i, j, k, lp0, lp1, lp2, lp3, lp4, lp5, off1(0 To 5), off2(0 To 5) As Integer
Dim Element As Variant
Dim MaxTerm(0 To 5), RowStuff(0 To 5) As Integer
' First we see the cycledat
j = 0
For Each Element In TayA1
TA1(j) = Element
j = j + 1
Next Element
k = 0
For Each Element In TayA2
TA2(k) = Element
k = k + 1
Next Element
i = 0
For i = 0 To 5
MaxTerm(i) = 0
RowStuff(i) = 1
Next i
i = 0
For Each Element In IncPd
RowStuff(i) = Element
i = i + 1
Next Element
totterm = 0
i = 0
For Each Element In PC1
MaxTerm(i) = Element
totterm = totterm + Element * RowStuff(i)
i = i + 1
Next Element
k = k - 1
j = j - 1
If totterm = j And totterm = k And totterm = RowNo Then
totterm = 0
For lp0 = 0 To MaxTerm(0)
off1(0) = RowStuff(0) * lp0
off2(0) = RowStuff(0) * (MaxTerm(0) - lp0)
For lp1 = 0 To MaxTerm(1)
off1(1) = off1(0) + RowStuff(1) * lp1
off2(1) = off2(0) + RowStuff(1) * (MaxTerm(1) - lp1)
For lp2 = 0 To MaxTerm(2)
off1(2) = off1(1) + RowStuff(2) * lp2
off2(2) = off2(1) + RowStuff(2) * (MaxTerm(2) - lp2)
For lp3 = 0 To MaxTerm(3)
off1(3) = off1(2) + RowStuff(3) * lp3
off2(3) = off2(2) + RowStuff(3) * (MaxTerm(3) - lp3)
For lp4 = 0 To MaxTerm(4)
off1(4) = off1(3) + RowStuff(4) * lp4
off2(4) = off2(3) + RowStuff(4) * (MaxTerm(4) - lp4)
For lp5 = 0 To MaxTerm(5)
j = off1(4) + RowStuff(5) * lp5
k = off2(4) + RowStuff(5) * (MaxTerm(5) - lp5)
totterm = totterm + TA1(j) * TA2(k)
Next lp5
Next lp4
Next lp3
Next lp2
Next lp1
Next lp0
CSP = totterm * konst
Else
If j totterm Or k totterm Then
CSP = StrConv("data error: field 5 plus 1 should equal number of terms in field 1 and number of terms in field 2.", vbProperCase)
Else
If RowNo totterm Then
CSP = StrConv("alignment error: sum of terms in field 3 * terms in field 4 should equal term in field 5.", vbProperCase)
End If
End If
End If
End Function
Function Deriv(TayA1 As Variant, PC1 As Variant, IncPd As Variant, RowNo As Variant) As Variant
Rem TayA1 is Example GREEN
Rem PC1 is Example Blue
Rem IncPd is Example Red
Dim TA1(0 To 5000)
Dim TA2(0 To 5000)
Dim i, j, k, lp0, lp1, lp2, lp3, lp4, lp5, off1(0 To 5), off2(0 To 5) As Integer
Dim Element As Variant
Dim MaxTerm(0 To 5), RowStuff(0 To 5) As Integer
' First we see the cycledat
j = 0
For Each Element In TayA1
TA1(j) = Element
j = j + 1
Next Element
k = 0
For Each Element In TayA2
TA2(k) = Element
k = k + 1
Next Element
i = 0
For i = 0 To 5
MaxTerm(i) = 0
RowStuff(i) = 1
Next i
i = 0
For Each Element In IncPd
RowStuff(i) = Element
i = i + 1
Next Element
totterm = 0
i = 0
For Each Element In PC1
MaxTerm(i) = Element
totterm = totterm + Element * RowStuff(i)
i = i + 1
Next Element
k = k - 1
j = j - 1
If totterm = j And totterm = k And totterm = RowNo Then
totterm = 0
For lp0 = 0 To MaxTerm(0)
off1(0) = RowStuff(0) * lp0
off2(0) = RowStuff(0) * (MaxTerm(0) - lp0)
For lp1 = 0 To MaxTerm(1)
off1(1) = off1(0) + RowStuff(1) * lp1
off2(1) = off2(0) + RowStuff(1) * (MaxTerm(1) - lp1)
For lp2 = 0 To MaxTerm(2)
off1(2) = off1(1) + RowStuff(2) * lp2
off2(2) = off2(1) + RowStuff(2) * (MaxTerm(2) - lp2)
For lp3 = 0 To MaxTerm(3)
off1(3) = off1(2) + RowStuff(3) * lp3
off2(3) = off2(2) + RowStuff(3) * (MaxTerm(3) - lp3)
For lp4 = 0 To MaxTerm(4)
off1(4) = off1(3) + RowStuff(4) * lp4
off2(4) = off2(3) + RowStuff(4) * (MaxTerm(4) - lp4)
For lp5 = 0 To MaxTerm(5)
j = off1(4) + RowStuff(5) * lp5
k = off2(4) + RowStuff(5) * (MaxTerm(5) - lp5)
totterm = totterm + TA1(j) * TA2(k)
Next lp5
Next lp4
Next lp3
Next lp2
Next lp1
Next lp0
CSP = totterm * konst
Else
If j totterm Or k totterm Then
CSP = StrConv("data error: field 5 plus 1 should equal number of terms in field 1 and number of terms in field 2.", vbProperCase)
Else
If RowNo totterm Then
CSP = StrConv("alignment error: sum of terms in field 3 * terms in field 4 should equal term in field 5.", vbProperCase)
End If
End If
End If
End Function