B4J Tutorial GuessMyNumber - Very simple example

Erel

Administrator
Staff member
Licensed User


The computer chooses a number and you need to find the correct number.
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private txtGuess As TextField
   Private Label1 As Label
   Private myNumber As Int
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
   MainForm.Show
   myNumber = Rnd(1, 101)
   MainForm.BackColor = fx.Colors.White
   MainForm.Title = "Guess my number"
End Sub
Sub btnTry_Action
   If IsNumber(txtGuess.Text) = False Then
     Label1.Text = "Please enter a valid number."
   Else If myNumber > txtGuess.Text Then
     Label1.Text = "My number is larger."
   Else If myNumber < txtGuess.Text Then
     Label1.Text = "My number is smaller."
   Else
     Label1.Text = "Well done!!!"
   End If
   txtGuess.SelectAll
End Sub
Sub txtGuess_Action
   btnTry_Action
End Sub
Note that the TextField font cannot be set with a "standard" API. It is set as an inline CSS sytle:
 

Attachments

Domingo

Member
Licensed User
The txtGuess.SelectAll only work when go trought txtGuess_Action, but not work from btnTry_Action
How is it posible to do too from btnTry_Action?
 
Top