B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=9.85
@EndOfDesignText@
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
	Private Root As B4XView
	Private xui As XUI
	Private btnAction, btn0 As B4XView
	Private lblResult As B4XView
	Private lblComments As B4XView
	Private lblMathSign As B4XView
	Private lblNumber1 As B4XView
	Private lblNumber2 As B4XView
	
	Private Number1, Number2 As Int
End Sub

Public Sub Initialize
'	B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
	Root = Root1
	Root.LoadLayout("MainPage")
	
	B4XPages.SetTitle(Me, "Calc trainer")
	
	NewProblem
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub NewProblem
	Number1 = Rnd(1, 10)		' Generates a random number between 1 and 9
	Number2 = Rnd(1, 10)		' Generates a random number between 1 and 9
	lblNumber1.Text = Number1	' Displays Number1 in label lblNumber1
	lblNumber2.Text = Number2	' Displays Number2 in label lblNumber2
	lblComments.Text = "Enter the result" & CRLF & "and click on OK"
	lblComments.Color = xui.Color_RGB(255,235,128)	' yellow color
	lblResult.Text = ""		' Sets lblResult.Text to empty
	btn0.Visible = False
End Sub

Private Sub btnAction_Click
	If btnAction.Text = "O K" Then
		If lblResult.Text="" Then
			lblComments.Text = "No result entered" & CRLF & "Enter a result" & CRLF & "and click on OK"
		Else
			CheckResult
		End If
	Else
		NewProblem
		btnAction.Text = "O K"
	End If
End Sub

Private Sub CheckResult
	If lblResult.Text = Number1 + Number2 Then
		lblComments.Text = "G O O D  result" & CRLF & "Click on NEW"
		lblComments.Color = xui.Color_RGB(128,255,128)	' light green color
		btnAction.Text = "N E W"
	Else
		lblComments.Text = "W R O N G  result" & CRLF & "Enter a new result" & CRLF & "and click OK"
		lblComments.Color = xui.Color_RGB(255,128,128)	' light red color
	End If
End Sub

Sub btnEvent_Click
	Private btnSender As Button
	
	btnSender = Sender
	
	Select btnSender.Tag
		Case "BS"
			If lblResult.Text.Length >0 Then
				lblResult.Text = lblResult.Text.SubString2(0,lblResult.Text.Length - 1)
			End If
		Case Else
			lblResult.Text = lblResult.Text & btnSender.Tag
	End Select

	If lblResult.Text.Length = 0 Then
		btn0.Visible = False
	Else
		btn0.Visible = True
	End If
End Sub
