S Basic Programming for Palm OS
Total Page:16
File Type:pdf, Size:1020Kb
S Basic Programming for Palm OS - Third Edition - The easiest way to program your Palm! Michael J. Verive 2 NS Basic Programming for Palm OS NS Basic Programming for Palm OS 3 Table of Contents Chapter I – Introduction .......................................................................... 9 Why Basic? ........................................................................................... 10 Installing NS Basic ................................................................................ 11 Chapter II - What I meant to say was... ................................................ 13 Abbreviations, terms, and mnemonics .................................................. 13 Conventions used in this book .............................................................. 16 Chapter III - Important Concepts ......................................................... 19 Palm OS and NS Basic-specific programming ..................................... 19 Object-Oriented vs. Top-Down Programming ...................................... 21 Structured Programming ....................................................................... 22 The Palm OS is "Event-driven" ............................................................ 24 Prototyping - know your audience! ....................................................... 24 Debugging/alpha/beta testing ................................................................ 25 When it’s time to scrap it and start over................................................ 25 Chapter IV - Your first project - "Hello, World!" .............................. 27 Chapter V – Constants, Literals, Variables and Arrays ..................... 31 Constants and Literals ........................................................................... 31 Variables................................................................................................ 32 Arrays .................................................................................................... 36 Chapter VI - Programming Elements ................................................... 39 Statements ............................................................................................. 39 Comments.............................................................................................. 40 Subroutines and Code Modules............................................................. 41 Functions ............................................................................................... 44 Controlling program flow...................................................................... 45 Running external applications ............................................................... 60 Ending your NS Basic application ........................................................ 63 Chapter VII - Projects and Forms ......................................................... 65 The NS Basic Project ............................................................................ 66 Forms ..................................................................................................... 67 Chapter VIII - Screen Graphics ............................................................ 75 Graphics Windows ................................................................................ 75 Drawing Graphics ................................................................................. 79 Chapter IX - S Basic Objects .............................................................. 93 Bitmap ................................................................................................... 93 Button .................................................................................................... 95 CheckBox .............................................................................................. 97 Field ..................................................................................................... 101 Gadget ................................................................................................. 105 4 NS Basic Programming for Palm OS Grid...................................................................................................... 110 Label .................................................................................................... 116 List ....................................................................................................... 118 PopUp .................................................................................................. 126 PushButton .......................................................................................... 133 Repeater ............................................................................................... 136 ScrollBar.............................................................................................. 138 Selector ................................................................................................ 140 Slider ................................................................................................... 143 Shift Indicator ...................................................................................... 145 Chapter X - umeric functions ............................................................ 147 Standard Mathematical Functions ....................................................... 147 Exponents, Powers and Logs .............................................................. 158 Chapter XI - String Handling .............................................................. 163 Conversions ......................................................................................... 163 Concatenation, Extraction and Truncation .......................................... 168 Searching Strings – using InStr ........................................................... 176 Chapter XII – Date and Time functions ............................................. 179 Date Functions..................................................................................... 180 Time Functions .................................................................................... 187 Chapter XIII - Database Management ................................................ 195 Creating Databases .............................................................................. 197 Opening Databases .............................................................................. 200 Closing and Erasing Databases ........................................................... 201 Data Access – a Parting of the Ways .................................................. 203 Safely mixing keyed and non-keyed methods..................................... 222 Writing to MemoPad ........................................................................... 226 Chapter XIV – Menus ........................................................................... 231 Creating Menus ................................................................................... 232 Chapter XV - Interacting with your user ............................................ 237 Interacting Visually - Message and Alert Boxes ................................. 237 Interacting Audibly - Beep, Sound and PlaySound............................. 241 Trapping user actions .......................................................................... 244 Chapter XVI - Serial Input/Output (I/O) ........................................... 249 Chapter XVII - Extending S Basic .................................................... 261 Accessing the Palm OS API ................................................................ 261 Shared Libraries .................................................................................. 265 Chapter XVIII - Special Topics ........................................................... 271 Control Arrays ..................................................................................... 271 Printing in NS Basic ............................................................................ 272 String parsing ...................................................................................... 277 NS Basic Programming for Palm OS 5 Data Encryption................................................................................... 279 Sorting Data......................................................................................... 281 Running HotSync from NS Basic ....................................................... 283 Soundex ............................................................................................... 284 Staying Alive ....................................................................................... 284 Saving State ......................................................................................... 285 System Info ......................................................................................... 285 SysInfoSet ........................................................................................... 286 Real Estate - location, location, location! ........................................... 287 Optimizing applications for speed....................................................... 287 Appendix A. Palm OS sort (string comparison) order. ...................... 293 Appendix B. Palm OS Fonts .............................................................. 295 Appendix C. Accessory Programs ...................................................... 301 Appendix D. Running POSE ............................................................... 309 Index .......................................................................................................