Sheerpower Logo

B.1  Variables, Data Types, Database Access, Declaring Variables, and Comments


Get Started with SheerPower

SheerPower is fast and easy. Have fun coding and being productive!

1. Naming Variables

Variable names start with a letter. Use letters, numbers, or "_". They’re not case-sensitive, so "name" = "NAME".

my_age = 42 print my_age

2. Naming Routines

Routines need an "_" in the name, like do_work. Same rules as variables otherwise.

3. Types of Data

SheerPower supports the following data types:

  • REAL: High-precision numbers with decimals. This is the default data type. They can also be declared.
    total = 123456789012345678.9876543210123456 declare real my_total my_total = total
  • STRING: A sequence of characters, typically enclosed in double quotes (e.g., "Anna"). STRING variables can also store binary or byte data. They use the $ suffix or are declared.
    name$ = "Anna" declare string my_name my_name = name$
  • INTEGER: Whole numbers using the % suffix. They can also be declared. Rarely used since the REAL data type is generally more useful.
    count% = 42 declare integer my_count my_count = count%
  • BOOLEAN: Logical values using the ? suffix or are declared.
    done? = true declare boolean my_done my_done = done?
  • DYNAMIC: A flexible type that changes based on usage.
    declare dynamic answer answer = 100 ! INTEGER answer = "yes" ! STRING answer = false ! BOOLEAN answer = 3.14159 ! REAL

The most common data types in SheerPower are REAL, STRING, and BOOLEAN. By default, all numeric variables are assumed to be of type REAL, which is recommended for nearly all numeric operations.


age = 25.99 // REAL number_of_cats% = 3 // integer -- rarely used name$ = "Sam" // STRING is_fun? = true // BOOLEAN

4. Exact Numbers

REAL keeps math perfect. No errors like 0.1 + 0.2 - 0.3.

print (0.1 + 0.2) - 0.3 // Outputs 0.0

Great for payroll or finance.

5. Keeping Types Steady

Once set, a variable’s type can’t change. This avoids mistakes.

a = 18 // a + "9" would fail

6. Using Databases

Get data with table(field), like payroll(salary).

print payroll(salary)

Set data the same way. It saves smartly later.

payroll(salary) = 1234.56

7. Flexible Database Data

Database fields adjust type by use:

  • Math: Becomes a number.
  • Text: Becomes a string.
total = 1.5 * payroll(salary) text$ = "Pay: " + payroll(salary)

This makes coding simpler.

8. Setting Types Clearly

Use declare to pick a type.

declare string home home = "Here"

dynamic lets types shift.

9. Fixed Values

const sets values that won’t change.

const max = 100

10. Pretty Printing

Set a format, like money with $ and 2 decimals.

declare format "$%.2m" cash cash = 123.45 print cash // $123.45

See more formats.

11. Your Own Types

Make custom types with type. They stay consistent.

type money format "$%.2m" declare money refund refund = 50.25 print refund // $50.25

12. Adding Notes

Use ! or // for comments. They’re for you, not the code.

// This is a note print "Hi" ! Another note
Coding tip: If you ever feel stuck while coding, a quick, simple trick is:
  • Write a one-sentence comment first, explaining what the next code block is about.
  • Then write the code.

Key Points

  • Name variables with letters and "_".
  • Use REAL, STRING, BOOLEAN most.
  • Get/set database with table(field).
  • Set types, formats, or notes as needed.

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.