Advanced Delphi

Moderators: None (Apply to moderate this forum)
Number of threads: 331
Number of posts: 741

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Convert code 2 VB.NET or C# Posted by chushu on 22 Mar 2009 at 12:36 AM
Dears,
Need your help to convert the following code to Dot.net
thanks in advcance

function TsimpleFunctionSet.dsSineWeightedMoveAverage(DataArray: IDataStream;Periods: Integer): TExprData;
var I: Integer;
ExprData: TExprData;
Num, Denum: Double;
SinVal: Double;

begin
Result.value := 0;
Result.isNull := False;
if Periods < 1 then
Result.isNull := True
else
begin
Num := 0;
DeNum := 0;
for I := 0 to Periods - 1 do
begin
ExprData := DataArray.GetPrev(I);
if ExprData.isNull then
begin
Result.isNull := True;
Break;
end;
SinVal := Sin(DegToRad((I + 1) * 180 / 6));
Num := Num + SinVal * ExprData.value;
DeNum := DeNum + SinVal;
end;
if DeNum <> 0 then
begin
if not Result.IsNull then
Result.Value := Num / DeNum;
//end if
end //if
else
result.isNull := True;
//end else
end;
end;

function TsimpleFunctionSet.dsEndPointMoveAverage(DataArray: IDataStream;
Periods: Integer): TExprData;
var
ExprData: TExprData;
// Sum: Double;
S1, S2: Double;
I: Integer;
begin
Result.value := 0;
Result.isNull := False;
if Periods < 1 then
Result.isNull := True
else
begin
S1 := 0;
S2 := 0;
for I := 0 to Periods - 1 do
begin
if i = 0 then
ExprData := DataArray.getCurrent
else
ExprData := DataArray.GetPrev(I);
//end if

if ExprData.isNull then
begin
Result.isNull := True;
Break;
end;

S1 := S1 + (2 * Periods - (1 + i * 3)) * ExprData.value;
S2 := S2 + (2 * Periods - (1 + i * 3));
end; //for
if not Result.isNull then
Result.value := S1 / S2;
end;
end;

Thread Tree
chushu Convert code 2 VB.NET or C# on 22 Mar 2009 at 12:36 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.