Sign in to follow this  
Followers 0
nbala75

Loop confusion

7 posts in this topic

#1 ·  Posted (edited)

Iam pretty poor in loops

for some of u this may be very easy...after some couple of hrs i can only fail

let me know how u guys write a loop for this...

Posted Image

-- 50 rows in this array

-- this is just an eg..array's size may vary

-- period is 25 (can be changed to any number)

-- Bottom up

-- first row in new field in just an average of last field [49] to [25], which is equal to Period of 25

-- rest of the row's formula is given in attached snapshots

Hope some one helps :x

Posted Image

Posted Image

Posted Image

Edited by nbala75

Share this post


Link to post
Share on other sites



nbala75,

Glad to help...what is the question?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

nbala75,

Glad to help...what is the question?

kylomas

Ohh..thank u

I need to populate the right hand side column using the above formulas

The first field of the new array (from bottom) shud be the AVG of <period=25> rows from bottom of TR array (posted as first snapshot)

The rest of rows (from bottom) shud be populated using the given formula in snapshots of excel

plz help me out

Share this post


Link to post
Share on other sites

Not sure what code you need but the loop is easy enough to do

Global $aExample[50]
$aExample[0] = "1"
$aExample[24] = "25"
$aExample[49] = "50"

$n = UBound($aExample) - 1 ; Use UBound to get the size of the Array when it has no index.
ConsoleWrite(@CRLF & "Array Size: " & $n & @CRLF)

; Go from 24-49
ConsoleWrite("Count up from 24 to end of array" & @CRLF)
For $i = 24 To UBound($aExample) - 1
    ConsoleWrite($aExample[$i] & ".")
Next

; Go from 49-24
ConsoleWrite(@CRLF & @CRLF & "Count down from end of array to 24" & @CRLF)
For $i = UBound($aExample) - 1 To 24 Step -1 ; Notice the Step -1
    ConsoleWrite($aExample[$i] & ".")
Next

Share this post


Link to post
Share on other sites

Not sure what code you need but the loop is easy enough to do

Global $aExample[50]
$aExample[0] = "1"
$aExample[24] = "25"
$aExample[49] = "50"

$n = UBound($aExample) - 1 ; Use UBound to get the size of the Array when it has no index.
ConsoleWrite(@CRLF & "Array Size: " & $n & @CRLF)

; Go from 24-49
ConsoleWrite("Count up from 24 to end of array" & @CRLF)
For $i = 24 To UBound($aExample) - 1
    ConsoleWrite($aExample[$i] & ".")
Next

; Go from 49-24
ConsoleWrite(@CRLF & @CRLF & "Count down from end of array to 24" & @CRLF)
For $i = UBound($aExample) - 1 To 24 Step -1 ; Notice the Step -1
    ConsoleWrite($aExample[$i] & ".")
Next

thank u...the size of the first array(no of rows) is dynamic and the period(p=25) is also flexible....can this work with these parameters as well??

let me check this as well...thanx again

Share this post


Link to post
Share on other sites

The size of the array being dynamic is fine (Check out the function UBound that was used in the example in the help file). The starting/ending point needs to be specified one way or another. You can assign it to a variable and set that variable at some point in the loop. The 'To 24 Step -1' section is where it'll stop (the 24)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The size of the array being dynamic is fine (Check out the function UBound that was used in the example in the help file). The starting/ending point needs to be specified one way or another. You can assign it to a variable and set that variable at some point in the loop. The 'To 24 Step -1' section is where it'll stop (the 24)

yeah...that is what i was just expecting someone to write it for me...bcos, i dont have formal edu in programming and i have not come across this type before, so iam finding it difficult to get this across to my mind...some of u guys who have done way above of these simple loops, will be able to do it in ur left hand...and that wud be a starting point for guys like me to learn the tricks in doing this in a simple and better way...

iam sure i cannot write 1 to 24 as numbers in the loop since i do not know whether it is 24 or 20 for that matter. This has to be derived, as u had said abt assigning and setting at some point in the loop.

Edited by nbala75

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0