B4J Tutorial GuessMyNumber - Very simple example

Discussion in 'B4J Tutorials' started by Erel, Nov 18, 2013.

  1. Erel

    Erel Administrator Staff Member Licensed User


    The computer chooses a number and you need to find the correct number.
    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
    "Layout1"'Load the layout file.
       myNumber = 
       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."
         Label1.Text = 
    "Well done!!!"
    End If
    End Sub
    Sub txtGuess_Action
    End Sub
    Note that the TextField font cannot be set with a "standard" API. It is set as an inline CSS sytle:

    Attached Files:

  2. Domingo

    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?
  3. Erel

    Erel Administrator Staff Member Licensed User

    Add this line to btnTry_Action:
  4. Domingo

    Domingo Member Licensed User

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice