Book Image

LiveCode Mobile Development Cookbook

By : Dr. Edward Lavieri
Book Image

LiveCode Mobile Development Cookbook

By: Dr. Edward Lavieri

Overview of this book

Table of Contents (17 chapters)
LiveCode Mobile Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Sorting text


LiveCode provides us with the ability to easily sort data in both ascending and descending order. In this recipe, we will sort a list of US states in ascending order.

How to do it...

Follow the steps in the recipe to sort text:

  1. Create a new main stack in LiveCode.

  2. Add a button to the card with the following properties:

    • Name: btnSort

    • Label: Sort

    • foregroundColor: Black

    • backgroundColor: White

    • borderWidth: 0

  3. Add the following code to the btnSort button:

    on mouseUp
      local someStates
      put "Connecticut" into line 1 of someStates
      put "California" into line 2 of someStates
      put "Washington" into line 3 of someStates
      put "Florida" into line 4 of someStates
      put "Rhode Island" into line 5 of someStates
      sort lines of someStates ascending text
      answer someStates titled "Sorted" 
    end mouseUp
  4. Run the app in the mobile simulator. As illustrated in the following screenshot, the states have been properly sorted in ascending order:

How it works...

We used the sort command to sort the lines of...