Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Convert to VB.NET

Posted on 2005-04-18
Medium Priority
334 Views
I have some code that I found online.  I have no idea what language it is in, however, I was hoping someone out there would be able to convert it to VB.NET it is just a simple For loop but there are a couple of things that I am not getting correct.  The code is:

dK=2.0/(p1+1.0);
dEMAB=0.0;
p1=100;

for(j=n+1; j<n+1+p1; j++)
dEMAB+=m_aClose[j];

if(p1>0)
dEMAB=dEMAB/p1;

for(i=n; i>=0; i--)
{
m_aEMA[i]=dEMAB+dK*(m_aClose[i]-dEMAB);
dEMAB=m_aEMA[i];
}
0
Question by:johnywhite

LVL 52

Expert Comment

ID: 13810956
dK = 2.0 / (p1 + 1.0)
dEMAB = 0.0
p1 = 100

For j = n + 1 To (n + 1 + p1)
dEMAB += m_aClose(j)
Next j

If p1 > 0 Then
dEMAB = dEMAB / p1
End If

For i = n To 0 Step -1
m_aEMA(i) = dEMAB + dK * (m_aClose(i) - dEMAB)
dEMAB = m_aEMA(i)
Next i

Hope this helps.
0

LVL 7

Expert Comment

ID: 13812752
Hello,
The original code:

for(j=n+1; j<n+1+p1; j++)
dEMAB+=m_aClose[j];

was changed to:

For j = n + 1 To (n + 1 + p1)
dEMAB += m_aClose(j)
Next j

I think the correct is:

For j = n + 1 To (n + p1)
dEMAB += m_aClose(j)
Next j

(notice the "<" in the original for loop)
0

LVL 1

Accepted Solution

s_satheesh earned 2000 total points
ID: 13813021
Hi  johnywhite,
sample code is below

Dim dK, dEMAB As Single
Dim p1 As Integer
Dim n, j, i As Integer
dK = 2.0 / (p1 + 1.0)
dEMAB = 0.0
p1 = 100
n = 10 'Initialize if you need
Dim m_aClose(n + p1), m_aEMA(n) As Single

For j = n + 1 To n + p1
dEMAB += m_aClose(j)
Next
If (p1 > 0) Then dEMAB = dEMAB / p1

For i = n To 0 Step -1

m_aEMA(i) = dEMAB + dK * (m_aClose(i) - dEMAB)
dEMAB = m_aEMA(i)
Next

MsgBox("value =" + dEMAB.ToString, MsgBoxStyle.Information, "Module")

Thx
0

LVL 52

Expert Comment

ID: 13813181
You're correct dttri, my mistake :o)
0

Author Comment

ID: 13818780
Thank you s_satheesh that is exactly what I was looking for.
0

## Featured Post

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.