
B4X Booklets
B4X Getting started
Copyright: © 2022 Anywhere Software Edition 2.4
Last update: 2022.08.15

Table of contents 2 B4X Getting started
1 B4X platforms .............................................................................................................................. 6
1.1 B4A Android ....................................................................................................................... 6
1.2 B4i Apple iOS ..................................................................................................................... 7
1.3 B4J Java / Windows / Mac / Linux / Raspberry PI ............................................................. 8
1.4 B4R Arduino / ESP8266 ..................................................................................................... 8
1.5 B4XPages ............................................................................................................................. 8
2 Getting started .............................................................................................................................. 9
2.1 Installation of the platforms ................................................................................................. 9
2.1.1 B4A .................................................................................................................................. 9
2.1.2 B4i .................................................................................................................................... 9
2.1.3 B4J ................................................................................................................................... 9
2.2 Setup for Additional Libraries ........................................................................................... 10
2.3 Configure paths .................................................................................................................. 11
2.3.1 B4J ................................................................................................................................. 11
2.3.2 B4A ................................................................................................................................ 12
2.3.3 B4i .................................................................................................................................. 12
2.4 Select the IDE language ..................................................................................................... 13
2.5 Connect to a real device ..................................................................................................... 13
3 My first program ........................................................................................................................ 14
3.1 Project setup ....................................................................................................................... 15
3.2 B4J version ......................................................................................................................... 18
3.2.1 Set the Package Name .................................................................................................... 18
3.2.2 Set the Form size ............................................................................................................ 19
3.2.3 Create the layout ............................................................................................................ 20
3.2.4 Write the code ................................................................................................................ 33
3.3 B4A version ....................................................................................................................... 38
3.3.1 Set the ApplicationLabel ................................................................................................ 39
3.3.2 Set the Package name ..................................................................................................... 40
3.3.3 Create the layout ............................................................................................................ 41
3.4 B4i version ......................................................................................................................... 47
3.4.1 Set the ApplicationLabel ................................................................................................ 47
3.4.2 Set the Package name ..................................................................................................... 48
3.4.3 Create the layout ............................................................................................................ 49
4 SecondProgram .......................................................................................................................... 55
4.1 B4A version ....................................................................................................................... 56
4.2 B4i version ......................................................................................................................... 72
4.3 B4J version ......................................................................................................................... 76
5 Getting started B4A................................................................................................................... 80
5.1 Installing B4A and Android SDK ...................................................................................... 80
5.2 B4A Configure Paths in the IDE ........................................................................................ 80
5.2.1 Configure Additional libraries folder ............................................................................. 81
5.3 B4A Choice of the language .............................................................................................. 82
5.4 B4A Connecting a real device............................................................................................ 83
5.4.1 Connection via USB ....................................................................................................... 83
5.4.2 Conneting via B4A-Bridge ............................................................................................ 84
5.4.2.1 Getting started with B4A-Bridge ........................................................................... 84
5.4.2.2 Run B4A-Bridge on your device............................................................................ 85
5.4.2.3 Wireless connection ............................................................................................... 86
5.5 My first B4A program (MyFirstProgram.b4a).................................................................. 88
5.6 Second B4A program (SecondProgram.b4a) .................................................................. 112
6 Getting started B4i .................................................................................................................. 127
6.1 Installing B4i .................................................................................................................... 128
6.1.1 Installing B4i ................................................................................................................ 128

Table of contents 3 B4X Getting started
6.1.2 Mac Builder installation ............................................................................................... 129
6.1.3 Hosted Mac builder service (optional) ......................................................................... 130
6.2 Configure Paths in the IDE .............................................................................................. 131
6.2.1 Configure Additional libraries folder ........................................................................... 132
6.3 Creating a certificate and provisioning profile................................................................. 133
6.3.1 UDID ............................................................................................................................ 133
6.3.2 Certificate and Provisioning Profile ............................................................................. 134
6.4 Installing B4i-Bridge and debugging first app ................................................................. 135
6.5 Install the B4I certificate .................................................................................................. 135
6.6 Install Build B4i-Bridge ................................................................................................... 135
6.6.1 Load B4i-Bridge........................................................................................................... 136
6.6.2 Install B4i-Bridge and run it ........................................................................................ 136
6.7 My first B4i program (MyFirstProgram.b4i) ................................................................... 137
6.8 Second B4i program (SecondProgram.b4i) .................................................................... 161
7 Getting started B4J .................................................................................................................. 176
7.1 Installing B4J ................................................................................................................... 177
7.1.1 Installing B4J ............................................................................................................... 177
7.1.2 B4JPackager11 ............................................................................................................. 177
7.2 Configure Paths in the IDE .............................................................................................. 178
7.2.1 Configure Additional libraries folder ........................................................................... 179
7.3 My first B4J program (MyFirstProgram.b4j) .................................................................. 180
7.4 Second B4J program (SecondProgram.b4j) .................................................................... 204
8 Getting started B4R ................................................................................................................. 220
8.1 Installing Arduino IDE ..................................................................................................... 220
8.2 Install Microsoft .Net Framework .................................................................................... 220
8.3 Install and configure B4R ................................................................................................ 221
8.4 Connecting a board .......................................................................................................... 223
8.5 Select a Board .................................................................................................................. 223
8.6 Arduino UNO board ......................................................................................................... 225
8.6.1 Power supply ................................................................................................................ 226
8.6.2 Pins ............................................................................................................................... 226
8.6.3 Power pins .................................................................................................................... 226
8.6.3.1 Digital Input / Output pins ................................................................................... 227
8.6.3.2 Analog input pins ................................................................................................. 227
8.6.4 Input modes INPUT / INPUT_PULLUP .................................................................... 227
8.6.5 Basic Pin functions ....................................................................................................... 228
8.6.5.1 Initialize................................................................................................................ 228
8.6.5.2 DigitalRead .......................................................................................................... 229
8.6.5.3 DigitalWrite.......................................................................................................... 229
8.6.5.4 AnalogRead .......................................................................................................... 229
8.6.5.5 AnalogWrite ......................................................................................................... 230
8.7 First example programs .................................................................................................... 231
8.7.1 Button.b4r .................................................................................................................... 232
8.7.1.1 Sketch ................................................................................................................... 232
8.7.1.2 Code ..................................................................................................................... 233
8.7.2 LedGreen.b4r ............................................................................................................... 234
8.7.2.1 Sketch ................................................................................................................... 234
8.7.2.2 Code ..................................................................................................................... 235
8.7.3 LedGreenNoSwitchBounce.b4r ................................................................................... 236
8.7.3.1 Sketch ................................................................................................................... 237
8.7.3.2 Code ..................................................................................................................... 238
8.7.4 TraficLight.b4r ............................................................................................................. 239
8.7.4.1 Sketch ................................................................................................................... 239

Table of contents 5 B4X Getting started
Main contributors: Klaus Christl (klaus), Erel Uziel (Erel)
To search for a given word or sentence use the Search function in the Edit menu.
All the source code and files needed (layouts, images etc.) of the example projects in this booklet
are included in the SourceCode folder.
For each program there are three folders.
SourceCode
MyFirstProgram
B4A
MyFirstProgram.b4a
B4i
MyFirstProgram.b4i
B4J
MyFirstProgram.b4j
Both programs MyFirstProgram and SecondProgram are almost the same for B4A, B4i and B4J.
Updated for following versions:
B4A version 11.80
B4i version 8.00
B4J version 9.80
B4R version 3.90
B4X Booklets:
B4X Getting Started
B4X B4X Language
B4X IDE Integrated Development Environment
B4X Visual Designer
B4X Help tools
B4XPages Cross-platform projects
B4X CustomViews
B4X Graphics
B4X XUI B4X User Interface
B4X SQLite Database
B4X JavaObject NativeObject
B4R Example Projects
You can consult these booklets online in this link [B4X] Documentation Booklets.
Be aware that external links don’t work in the online display.