Chapter 2: Starting to code

In this chapter, we'll start by showing how to begin coding a very simple app from scratch, and learn to use the basic functions of Basic 4 Android, to create a screen for your app, and to start working out how to use the built in tools to solve problems.

  • 36 An introduction to Android Views
    Discover the basic building blocks of an Android app
  • 40 Create your first app with Basic4Android
    It's simpler than you think to build an app from scratch
  • 44 STEP BY STEP: Compile and install your first app
    Follow our guide, and you'll have your first real app in no time
  • 48 Finding bugs in Basic4Android
    Don't panic when things go wrong - use the built in tools to squash bugs fast
  • 52 Using the logs
    Find out how your device's logs can help you make a better app

Page 43: Temperature converter

In this article, which starts on page 40, we start to create a simple app. This is the code for the ctof_Click. Remember you'll need to modify it for the other button:

Sub ctof_Click
     Dim result as Float
     result = (( temperature.Text +40 ) * 9 / 5 ) -40 )
     MsgBox( NumberFormat(result,1,2),"The value in Fahrenheit is")
End Sub

Page 46, step by step

The code in step 10 for this workshop is the same as that shown above.

Page 57, step 7

After editing the code in this step by step, you should have something that looks like this:

Sub ctof_Click
 Dim result as Float

  If IsNumber(temperature.Text) then
   result = (( temperature.Text +40 ) * 9 / 5 ) -40 )
   temperature.Text = "The value in Fahrenheit is "  & NumberFormat(result,1,2)
  Else
    answer.Text = "You must enter a number"
 End if

 temperature.Text = ""       
End Sub

Remember you'll need to add a label called 'answer' to your app's layout, too, for this code to work, rather than using the MsgBox as in the previous snippet.