Solved

# Convert to VB.NET

Posted on 2005-04-18
260 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

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

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

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

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

Author Comment

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

## Featured Post

### Suggested Solutions

zeroFront challenge 7 58
FizzBuzz challenge 9 64
Enhanced For loop vs ForEach Loop 4 42
array11 challenge 16 40
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…