tips
[Top] [All Lists]

REALbasic Tip: Create and loop through arrays with less code

To: REALbasic-tips at lists dot realsoftware dot com
Subject: REALbasic Tip: Create and loop through arrays with less code
From: Geoff Perlman <geoff at realsoftware dot com>
Date: Thu, 28 Oct 2004 15:03:21 -0500
Cc:
Delivered-to: REALbasic-tips at lists dot realsoftware dot com
In REALbasic 5.5 we made it easier to create arrays in code. Rather than having to do this:

Dim months(11) as String
months(0) = "Jan"
months(1) = "Feb"

etc., now you can do this:

Dim months() as String
months = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

And if you need to loop through an array, you can even do this:

  dim month as String
for each month in Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

    next

As you can see, the array function can save many lines of code and make your code easier to read.

He doesn't know it, but this tip was inspired by Will Leshner and suggested by Matt Quagliana.
--
Geoff Perlman
President and CEO
REAL Software, Inc.

REAL World 2005 - The REALbasic User Conference
March 23rd - 25th, 2005, Austin, Texas
<http://www.realsoftware.com/realworld>

<Prev in Thread] Current Thread [Next in Thread>
  • REALbasic Tip: Create and loop through arrays with less code, Geoff Perlman <=