
Quote from sghoshnbu on May 27, 2019, 5:51 amHello,
I have a list box object with this type of content(item) in each lines. 0-10 , 10-20, 20-30 etc. I parsed the string 0-10, 10-20 etc using the delimiter - and kept that in a array variable. Now I want to get the average values of each two parsed values( like (0+10)/2, (10+20)/2 and want to keep that in other array variable.
Please help.
CreateEmptyArray [lstmidval] ArrayLen [listboxitems] [arlen] Loop 1 [arlen] [lp2] Math "[lp2]-1" 0 [lp3] slParseInt "[listboxitems([lp3])]" [hmmm] .StrParse "[listboxitems([lp3])]" "-" [p] ArrayAddItem [lstmidval] [hmm] .ListBoxAddItem "Listbox2" "[listboxitems([lp3])]" "val" Endloop
Hello,
I have a list box object with this type of content(item) in each lines. 0-10 , 10-20, 20-30 etc. I parsed the string 0-10, 10-20 etc using the delimiter - and kept that in a array variable. Now I want to get the average values of each two parsed values( like (0+10)/2, (10+20)/2 and want to keep that in other array variable.
Please help.
CreateEmptyArray [lstmidval] ArrayLen [listboxitems] [arlen] Loop 1 [arlen] [lp2] Math "[lp2]-1" 0 [lp3] slParseInt "[listboxitems([lp3])]" [hmmm] .StrParse "[listboxitems([lp3])]" "-" [p] ArrayAddItem [lstmidval] [hmm] .ListBoxAddItem "Listbox2" "[listboxitems([lp3])]" "val" Endloop
Quote from Gaev on May 27, 2019, 3:52 pm@sghoshnbu:
Try this code ...
... create array of ranges CreateEmptyArray [listboxitems] ArrayAddItem [listboxitems] "0-10" ArrayAddItem [listboxitems] "10-20" ArrayAddItem [listboxitems] "20-30" ... empty array of mid points CreateEmptyArray [listboxmidpoints] ... setup max loop counter ArrayLen [listboxitems] [arraylength] ... arrays start at zero; so subtract 1 Math "[arraylength]-1" 0 "[LoopMax]" ... AlertBox "LoopMax" "[LoopMax]" "" ... now loop through items Loop 0 [LoopMax] [thisLoop] ... AlertBox "thisLoop" "[thisLoop]" "" ... split at - StrParse "[listboxitems([thisLoop])]" "-" [thisItem] ... extract first part SetVar [thisItemPart1] [thisItem(0)] ... convert to number ToNumber "[thisItemPart1]" [thisitemNumber1] ... extract second part SetVar [thisItemPart2] [thisItem(1)] ... convert to number ToNumber "[thisItemPart2]" [thisItemNumber2] ... AlertBox "Parts" "[thisItemNumber1] ... [thisNumber2]" "" ... calculate mid point Math "([thisItemNumber1] + [thisItemNumber2])/2" "0" "[thisResult]" ... AlertBox "midpoint [thisLoop]" "[thisResult]" "" ... add to array of midpoints ArrayAddItem [listboxmidpoints] [thisResult] Endloop ... now verify AlertBox "Mid Points" "[listboxmidpoints(0)] ... [listboxmidpoints(1)] ... [listboxmidpoints(2)]" ""... if you get unexpected results, uncomment AlertBox commands to investigate.
@sghoshnbu:
Try this code ...
... create array of ranges
CreateEmptyArray [listboxitems]
ArrayAddItem [listboxitems] "0-10"
ArrayAddItem [listboxitems] "10-20"
ArrayAddItem [listboxitems] "20-30"
... empty array of mid points
CreateEmptyArray [listboxmidpoints]
... setup max loop counter
ArrayLen [listboxitems] [arraylength]
... arrays start at zero; so subtract 1
Math "[arraylength]-1" 0 "[LoopMax]"
... AlertBox "LoopMax" "[LoopMax]" ""
... now loop through items
Loop 0 [LoopMax] [thisLoop]
... AlertBox "thisLoop" "[thisLoop]" ""
... split at -
StrParse "[listboxitems([thisLoop])]" "-" [thisItem]
... extract first part
SetVar [thisItemPart1] [thisItem(0)]
... convert to number
ToNumber "[thisItemPart1]" [thisitemNumber1]
... extract second part
SetVar [thisItemPart2] [thisItem(1)]
... convert to number
ToNumber "[thisItemPart2]" [thisItemNumber2]
... AlertBox "Parts" "[thisItemNumber1] ... [thisNumber2]" ""
... calculate mid point
Math "([thisItemNumber1] + [thisItemNumber2])/2" "0" "[thisResult]"
... AlertBox "midpoint [thisLoop]" "[thisResult]" ""
... add to array of midpoints
ArrayAddItem [listboxmidpoints] [thisResult]
Endloop
... now verify
AlertBox "Mid Points" "[listboxmidpoints(0)] ... [listboxmidpoints(1)] ... [listboxmidpoints(2)]" ""
... if you get unexpected results, uncomment AlertBox commands to investigate.