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
5
Medium Priority
?
334 Views
Last Modified: 2010-04-17
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
Comment
Question by:johnywhite
5 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
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

by:dttri
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

by:
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

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

Author Comment

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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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 …
Introduction to Processes

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question