TweetFollow Us on Twitter

Beginning REALBasic

Volume Number: 24 (2008)
Issue Number: 07
Column Tag: REALBasic

Beginning REALBasic

Designing the Application

by Norman Palardy

REALbasic is a Rapid Application Develpment (RAD) tool from REALSoftware. In previous columns we've looked at it briefly and even talked with Geoff Perlmann, the CEO of REAL Software. This month we're continuing our series of articles that aim to get you started with REALbasic and show you how to be productive with it. For this series we're using the latest version of REALbasic; version 2008r1.

Designing the Interface

In this installment we're creating an application that tracks the prices of stocks. This will involve accessing the Internet to grab quotes, graphs and a database. Some of the components required are built in to REALbasic itself, and others will have to come from third parties.

In this installment we'll design the interface, the database and the windows we'll need for adding stocks to track. We'll get started writing the basics that make the whole project come together.

First, start REALbasic so you have a new project to work with.


Figure 1. REALbasic default project

As we saw last month, this default project is a fully functioning program. You could immediately run it by pressing the green Run button.

Let's consider the tasks we'll need to accomplish to make this program work the way we want.

  • We'll need a way to add and remove stocks from the list of ones we're interested in.

  • It should keep quotes for any stocks we currently have, or had an interest in at any time

  • We'll need a way to view the current set of stocks we're interested in and their prices

  • We'll need a way to get the stock prices from a designated source

  • We'll need a way to designate which source we're going to read data from

  • Eventually we'll want a way to graph prices of stocks over time

That's a lot of things to consider so we'll tackle them one at a time. Lets start with how we show our list of stocks of interest.

In the project we created earlier, there should already be a window called Window1. Let's start by editing that window and altering its layout to turn it into one that shows our list of stocks.


Figure 2. Editing a REALbasic window

Down the left hand side is a list of the standard controls that are available in REALbasic. Note that I'm using the Professional version. The Personal version has a smaller set of controls.

In the center is the actual editor where you lay out the look of your window. On the right is the properties palette that displays the properties of the currently selected item.

First, rename this window so that at a glance, you can know which window it is. Click the window so it is selected as shown in Figure 2, and then click on the Name in the property list on the right. Name this window wStocks.

Then add a Listbox control to the window. Rename the listbox lstStocks and position and resize it so your window appears about like the one in Figure 3. Note that Figure 3 shows you the position and size of my listbox in the properties palette on the right hand side.

You'll also notice that the listbox has several lock properties set (LockLeft, LockRight, LockTop, LockBottom). These properties tell REALbasic to keep the listbox "locked" to the respective sides of the window if the window is resized.


Figure 3. Create the stock list window

If you run the project at this point you wont see much except that a window with a large white area shows up. That area is the listbox, which is empty at this point.

The question, then, is how to fill it with data and what data to fill it with.

Every control has a number of "events" that allow you provide custom code when something (an event) occurs. Different controls have different events. The list of events that exist for a control varies depending on what kind of control it is. Simple controls have few events. Timers only have one event. The listbox has a fairly long list of events. For our program let's start with just using the Open event.

This event occurs when the control is about to be shown on a window that is being opened. It occurs only once when the window is initially opened. There are other events that occur more frequently but for the start of this project we'll use this event.

One thing to be aware of is that event ordering is generally not something you want to rely on. You have no idea if the listbox Open event occurs before or after some other controls Open event. The other control may not even exist yet. So you have to be careful about how you use certain events and what you try to do in the code for that event.

If you double-click the listbox you will be shown the code editor. REALbasic also tries to be helpful and selects the most likely event you are going to want to edit. In this case that's the Change event for the list box.


Figure 4. Editing the listbox events in the stock list window

Select the Open event in the left hand pane and then add the following code :

  me.ColumnCount = 3 // change the number of visible columns
  me.HasHeading = true // make the list box have a leading row
  me.Heading(0) = "Symbol" // set the heading for the first column
  me.Heading(1) = "Time" // set the heading for the second column
  me.Heading(2) = "$" // set the heading for the third column

Much of this CAN be done without writing code. If you review figure 3, you'll see that in the right hand properties pane there are settings for ColumnCount, HasHeading and InitialValue. If you set the columnCount property to 3 then the listbox will have 3 columns. If you check HasHeading then the listbox will have a heading and the setting for InitialValue will be used as the column headings. We've done these things in the Open event simply to illustrate that you can change some properties on the fly and they will take effect right away. Being able to alter the number of columns and their headings at run time will be shown in future articles.

If you run the program now, you can see that when the window opens it has 3 columns with the headings we wanted.

Now we have a way to get the display looking like what we want, so now let's see about getting some rows into it that display data.

If you look up ListBox in the built-in Language Reference, you'll see it has numerous events, properties and methods. Again, an event is some piece of code that gets run when something happen; a person selects a row, clicks a button or presses a key. Properties are the "settings" of various aspects of the control; the number of columns, which row is selected, or other display related values like the text font and size.

Methods are behaviors that the listbox will perform. These are actions like adding a row (AddRow), remove a row (RemoveRow), or ways to get data from the listbox (Cell and CellTag).

For our use AddRow is the one we need at present. At the end of the open event add the following code :

  me.AddRow "AAPL" // add one symbol we're interested in watching
  dim newDate as new Date // create a new instance of a Date
  me.cell(me.LastIndex,1) = newDate.ShortDate + " " + newDate.ShortTime // add the date / time stamp
  me.cell(me.LastIndex,2) = format(169.73,"$,#.00") // display Apple's current value

Let's review this code closely.

  me.AddRow "AAPL" // add one symbol we're interested in watching

This line adds the data for the first cell (the left most one also known as column 0) and leaves the other cells empty.

  dim newDate as new Date

For the second column we want the current date and time. In order to get that information we need to create an instance of a Date object, which is conveniently initialized to the date and time from the OS when the instance was created. A Date instance is not a clock and does not automatically count forward.

 me.cell(me.LastIndex,1) = newDate.ShortDate + " " + newDate.ShortTime // add the date / time stamp

Then we fill the middle cell — the one we want to contain the date and time — by using the CELL method to refer to a specific cell. Note that in order to make sure we set the correct cell in the correct row there is a convenient property called "lastIndex" that is the row number that was last added. The code says "set the last rows cell 1 to the short date and short time" which is exactly what we want.

  me.cell(me.LastIndex,2) = format(169.73,"$,#.00")

For the last column, column 2, we want a value. But the listbox only knows how to display strings. So we have to take the current value of Apple's stock, 169.73, which is a number and convert it into a string that the listbox can display. Also, we want to make sure the string that the listbox displays is formatted so it looks just the way we want. To do that we use the FORMAT method which gives us control over how numbers look when they are converted to strings.

Run this now and you'll see we're making headway. We can make the listbox display data, and we can add data to it.

Next time we'll look at how to make the data that we display more dynamic and actually get it from a web based quote service like Yahoo finance.


Norman Palardy has worked with SQL databases since 1992, and has programmed in C, C++, Java, REALbasic and other languages on a wide variety of platforms. In his 15+ years of IT experience, Norman has developed innovative and award-winning applications for TransCanada Pipelines, Minerva Technologies (now XWave), Zymeta Corporation, and the dining and entertainment industry. He holds a BSc from the University of Calgary in Alberta. He's also the Vice President of the Association of REALbasic Professionals (http://www.arbp.org)

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Whitethorn Games combines two completely...
If you have ever gone fishing then you know that it is a lesson in patience, sitting around waiting for a bite that may never come. Well, that's because you have been doing it wrong, since as Whitehorn Games now demonstrates in new release Skate... | Read more »
Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »

Price Scanner via MacPrices.net

Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more
New promo at Visible: Buy a new iPhone, get $...
Switch to Visible, and buy a new iPhone, and Visible will take $10 off their monthly Visible+ service for 24 months. Visible+ is normally $45 per month. With this promotion, the cost of Visible+ is... Read more
B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for $100 off Apple’s new MSRP, only $899. Free 1-2 day delivery is available to most US addresses. Their... Read more
Take advantage of Apple’s steep discounts on...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more

Jobs Board

Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Business Analyst | *Apple* Pay - Banco Popu...
Business Analyst | Apple PayApply now " Apply now + Apply Now + Start applying with LinkedIn Start + Please wait Date:Mar 19, 2024 Location: San Juan-Cupey, PR Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.