Purpose Select rows of a table variable according to user input |
Solution The example also shows
Example
The user selects a country in a dropdown list showing all countries contained in the .csv file. We then display the cities belonging to this country:
In a second dropdown list "Order by" you can choose the ordering by city name, population or "North to South", here shown for further countries:
Video
GuiXT Script // country selection dropdwon list -noSort process="cities.select.txt" // display city table title="&V[cities.rowcount] cities" Column "CC" size=3 name="countrycode" -readOnlyColumn "City" size=20 name="city" -pushButton _ process="cities.showflights.txt" Column "Country" size=16 name="country" -readOnly Column "Population" size=12 name="population" -readOnly Column "Latitude" size=10 name="latitude" -readOnly Column "Longitude" size=10 name="longitude" -readOnly // display flight tracking control if activatesd Control (3.7,84.9) (28.4,169.9) _ progID="&V[citiesShowfligthsURL]" _ name="flightradar" -silent -closeOnHide endif // "order by" drop down list DropDownList (30.1,20.2) "orderoptions" width=30 _ refer="V[orderby]" -noSort _ process="cities.sort.txt" InputScript "cities.initialize.txt" // initialize city display // create structure table variables // all cities from .csv file // cities seleced by user (a paricular country or *=all) // load content from .csv file CopyText fromText="cities" toTable=V[allcities] delimiter=";" // sort // build country selection // 1st entry CopyText fromString="line" toText="allcountries" // 2nd entry: all countries CopyText fromString="line" toText="allcountries" -appendLine // build up country dropdown Set V[k] 1label next_city if not V[k>&V[allcities.rowcount]] // new countrycode? if not V[countrycode=&V[allcities.countrycode.&V[k]]] Set V[countrycode] "&V[allcities.countrycode.&V[k]]" Set V[line] "&V[countrycode]=&V[countrycode] &V[allcities.country.&V[k]]" CopyText fromString="line" toText="allcountries" -appendLine endif
Set
V[k]
&V[k]
+ 1 // drop down list for ordering // default ordering: by city name Return
// select cities for a given country // no country selected? return endif // structure for city selection (match= option below) // fill with value to select (country code) // select matching entries in "allcities" and append them to "cities" label next_city// all cities? ReadRow V[cityinfo] table=V[allcities] index=&V[k] else // next matching row ReadRow V[cityinfo] table=V[allcities] fromIndex=&V[k] returnindex="k" match=V[matchcity] endif // matching row found? then append it to "cities" Set V[cityinfo.population] "&V[cityinfo.population]" + 0 groupSeparator="." Set V[cityinfo.latitude] "&V[cityinfo.latitude]" / 10000 decimals=2 Set V[cityinfo.longitude] "&V[cityinfo.longitude]" / 10000 decimals=2 AppendRow V[cityinfo] table=V[cities] Set V[k] &V[k] + 1 goto next_city endif // Now order the result set according to the selected order type
1,2,3 Sort V[cities] orderBy="city" endif if V[orderBy=2]Sort V[cities] orderBy="population" -descending endif if V[orderBy=3]Sort V[cities] orderBy="latitude" -descending endif // scroll table to top // no "flight traffic" display Return
InputScript "cities.sort.txt" // order cities if V[orderBy=1]Sort V[cities] orderBy="city" endif if V[orderBy=2]Sort V[cities] orderBy="population" -descending endif if V[orderBy=3]Sort V[cities] orderBy="latitude" -descending endif // scroll table to top Return
InputScript "cities.showflights.txt" // flight display on // Set coordinates Set V[citiesLongitude] &V[cities.longitude.&V[_tabrowabs]] * 100 Set V[citiesLatitude] &V[cities.latitude.&V[_tabrowabs]] / 100 decimals=2 decimalSeparator="." Set V[citiesLongitude] &V[cities.longitude.&V[_tabrowabs]] / 100 decimals=2 decimalSeparator="." // set flightradar24-URL Return |
Components |