Sign in to follow this  
Followers 0
seesoe

loop for that runs a function

9 posts in this topic

hello,

i have data coming into my script that is dynamic

<x#xx>

let say $item holds that string, (string example - <5#23><2#24><5#25>)

how can i create a loop that will run the function done($qty,$id) for each set of <> that is in the string?

Share this post


Link to post
Share on other sites



Use string split to get an array. Then use a for loop and the array.length attribute. Try to use "" around strings so it is clearer.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

can you explain that a little bit more please

i found this in the help file under for but i don't get it

For $i = 5 to 1 Step -1

MsgBox(0, "Count down!", $i)

Next

i found StringRegExp, that looks like something i should use, how do i use it?

Edited by seesoe

Share this post


Link to post
Share on other sites

The for loops adds the step (in this case -1) to the variable (in this case $i) each iteration. If no step is specified 1 is used.

Share this post


Link to post
Share on other sites

so the stopping var in this case would be how much elements are in the array, so wheres array.length from?

Share this post


Link to post
Share on other sites

eh? code post plz.

Share this post


Link to post
Share on other sites

$list_1 = "<2#4>,<4#5>"

$list_2 = StringSplit($list_1,",")

$list_3 = StringTrimLeft($list_2[1],1)

$list = StringTrimRight($list_3,1)

$item = StringSplit($list,"#")

done($item[1],$item[2])

but this of course will only do the first set of <>

how can i make the FOR do it for how ever much sets of <> there are?

Share this post


Link to post
Share on other sites

gaz was telling you to use a for loop. Like this:

$list_1 = "<2#4>,<4#5>,<1#5>,<2#5>"

$list_2 = StringSplit($list_1,",")
For $i=1 To $list_2[0]
$list_3 = StringTrimLeft($list_2[$i],1)
$list = StringTrimRight($list_3,1)
$item = StringSplit($list,"#")
done($item[1],$item[2])
Next

Share this post


Link to post
Share on other sites

perfect thanks

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