Label: adding machine

122 views
Skip to first unread message

Scott Ferguson

unread,
Sep 13, 2012, 5:55:58 PM9/13/12
to
The Label component has many uses, the main one being displaying a static text label. But it can also hold dynamic data that changes in the app.

This exercise uses 2 labels. One label holds the static text of a math problem. The other label holds the answer to that math problem that is calculated by the app. (The dynamic Label).

Create a new project named lrn_lbl_uses 

Screen Designer:
Drag two Label components to the Viewer layout.

Change the text in the first Label to What is 2 + 2? 
Change the text in the second Label to <answer here>

Blocks Editor:

Drag out a Screen1.Initialize event block (this block executes blocks inside it when the app starts)


Drag out a Label2.Text block and drop it inside the Screen1.Initialize block.

Drag out a + block from the Built-In, Math list and attach it to the Label2.Text block.

Drag out 2 123 blocks and insert each one into the + block.

Change the 123 values to 2 so the block reads 2 + 2.

Now test the project in the emulator or connected device. If the output looks similar to this, then well done! You have just created an adding machine :)

END.

Challenge: Try out some of the other math blocks to do different calculations (don't forget to change the static text label also to show what is being calculated)

Just for fun: What happens if you divide by 0? You might be surprised!

lrn_lbl_uses.zip
Reply all
Reply to author
Forward
0 new messages