cjacobs 2 Posted September 4, 2018 Report Share Posted September 4, 2018 Hi, Wondering if anyone could help me with a problem I am having. I am wanting to loop through a table and only scrape Cities if their latitude number (Column 5) is +2.00 more than the row (City) my app is currently on. So in the table below my original position (#row) is 0 (Adak with has a latitude of 51.88), and I want to scrape the next cities that have a latitude number up to 53.88 which in this case would be:Adak, Atka, Attu Station, Nikolski, Unalaska <img src="https://imgur.com/a/PUrFojF"> I can't figure out what I need to qualify (comparison, eval etc) and extract the cities needed. set(#tableloop,0,"Global") clear list(%NearbyCities) loop($table total rows(&data)) { set(#Plus2,$table cell(&data,#row,5),"Global") if($comparison($table cell(&data,#tableloop,5),"> Greater than",#Plus2)) { then { add item to list(%NearbyCities,$table cell(&data,#tableloop,0),"Don\'t Delete","Global") } else { } } increment(#tableloop) } Any ideas? Quote Link to post Share on other sites
HelloInsomnia 1103 Posted September 4, 2018 Report Share Posted September 4, 2018 Can't you just add 2 like so set(#Plus2,$add($table cell(&data,#row,5),2),"Global") Quote Link to post Share on other sites
Sanjeev 46 Posted September 4, 2018 Report Share Posted September 4, 2018 create table from file("C:\\ubot sample scripts\\sampletable.txt",&cityElevation)clear list(%nearby_cities)set(#max_elevation,$add($table cell(&cityElevation,0,5),2),"Global")set(#current_row,0,"Global")loop($table total rows(&cityElevation)) { if($comparison($table cell(&cityElevation,#current_row,5),"<= Less than or equal to",#max_elevation)) { then { add item to list(%nearby_cities,$table cell(&cityElevation,#current_row,0),"Don\'t Delete","Global") increment(#current_row) } else { } }} this was the table I used - adak,alaska,ak,adak,ak,51.88atka,alaska,ak,atka,ak,52.19611attu station,alaska,ak,attu staion,ak,52.880nikolski,alaska,ak,nikolski,ak,52.938unlaska,alaska,ak,aualaska,ak,53.87akutan,alaska,ak,akutan,ak,54.13false pass,alaska,ak,false pass,ak,54.85King cove,alaska,ak,King cove,ak,55.85 ----------------------------------------------------------------I am assuming you want to scrape the city name only? the logic is as follows - ---------------------------------------We set a variable to = 51.88 + 2 set(#max_elevation,$add($table cell(&cityElevation,0,5),2),"Global") Then we look at the 'column 5' value of each row - and assert - that it's value should be less than 53.88 or equal to 53.88 if($comparison($table cell(&cityElevation,#current_row,5),"<= Less than or equal to",#max_elevation)) if yes - add city name - 'column 0' in this case of the current row to list. add item to list(%nearby_cities,$table cell(&cityElevation,#current_row,0),"Don\'t Delete","Global") 1 Quote Link to post Share on other sites
cjacobs 2 Posted September 5, 2018 Author Report Share Posted September 5, 2018 Thanks for your input guys! Got it working using Sanjeev's code. Is there a way to set a maximum number of results it will return? Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted September 6, 2018 Report Share Posted September 6, 2018 if $list total is => #max results: stop script something like that 1 Quote Link to post Share on other sites
cjacobs 2 Posted September 6, 2018 Author Report Share Posted September 6, 2018 if $list total is => #max results: stop script something like thatThis almost got me there but the Stop Script of course stops the primary loop. I need it to exit this 2nd loop if the condition (#maxresults) is met.Any ideas? Quote Link to post Share on other sites
Sanjeev 46 Posted September 6, 2018 Report Share Posted September 6, 2018 not sure if this is what you are looking for - create table from file("C:\\Users\\ubot sample scripts\\sampletable.txt",&cityElevation)set(#list total,0,"Global")set(#max_results,3,"Global")clear list(%nearby_cities)set(#max_elevation,$add($table cell(&cityElevation,0,5),2),"Global")set(#current_row,0,"Global")loop($table total rows(&cityElevation)) { if($both($comparison(#list total,"< Less than",#max_results),$comparison($table cell(&cityElevation,#current_row,5),"<= Less than or equal to",#max_elevation))) { then { add item to list(%nearby_cities,$table cell(&cityElevation,#current_row,0),"Don\'t Delete","Global") increment(#list total) increment(#current_row) } else { increment(#current_row) } }} Quote Link to post Share on other sites
HelloInsomnia 1103 Posted September 6, 2018 Report Share Posted September 6, 2018 This almost got me there but the Stop Script of course stops the primary loop. I need it to exit this 2nd loop if the condition (#maxresults) is met.Any ideas? Throw it in a command and use the return command to exit that custom command. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.