Lesson 5: Working with Cluster Arrays in Sheerpower
Cluster arrays in Sheerpower are powerful tools that function similarly to in-memory spreadsheets. They allow you to efficiently store, manipulate, and retrieve data in rows and columns, making them ideal for handling information like spreadsheets. In this lesson, we'll explore the main features of cluster arrays and how to use them in Sheerpower.
1. Creating a Cluster Array
Let's start by creating a cluster array called student to hold information about students. Each row in this cluster will represent a different student, and we'll track each student's name, age, and grade level.
Instructions: Click the COPY button above to paste the code into the text area, and then click RUN to execute the code.
4. Iterating Through Cluster Arrays
To operate on each row in a cluster array, you can use the COLLECT and END COLLECT statements. Let's print the name, age, and grade level of each student and calculate their average age.
Instructions: Click the COPY button above to paste the code into the text area, and then click RUN to execute the code.
5. Sorting and Filtering Data
Cluster arrays allow you to sort and filter data efficiently. Let's sort the students by their name and then include only those older than 16.
cluster student: name$, age, level
add cluster student
student->name$ = "Joan Ark"
student->age = 18
student->level = 12
add cluster student
student->name$ = "John Smith"
student->age = 16
student->level = 10
add cluster student
student->name$ = "Desmond Jones"
student->age = 15
student->level = 10
collect cluster student
sort by student->name$
end collect
for each student
print student->name$; ' '; student->age
next student
print
collect cluster student
include student->age > 16
sort by student->name$
end collect
for each student
print student->name$; ' '; student->age
next student
Instructions: Click the COPY button above to paste the code into the text area, and then click RUN to execute the code.
6. Searching Cluster Arrays
Use the FINDROW() function to search for specific data in a cluster array. This function is highly optimized and can perform millions of searches per second.
Instructions: Click the COPY button above to paste the code into the text area, and then click RUN to execute the code.
Summary:
In this lesson, you've learned how to work with
cluster arrays in Sheerpower, including how to create
cluster arrays, add rows, iterate through them, sort and
filter data, and search for specific information. Cluster arrays are a
powerful feature in Sheerpower, offering dynamic and efficient data management.
Keep practicing to master cluster arrays and enhance your Sheerpower programming skills!
Hide Description
Enter or modify the code below, and then click on RUN
Looking for the full power of Sheerpower?
Check out the
Sheerpower website.
Free to download. Free to use.