首页 > 代码库 > 学起来很简单!MyFirst_B4A_Program

学起来很简单!MyFirst_B4A_Program

#Region  Project Attributes 	#ApplicationLabel: MyFirstProgram	#VersionCode: 1	#VersionName: 	‘SupportedOrientations possible values: unspecified, landscape or portrait.	#SupportedOrientations: unspecified	#CanInstallToExternalStorage: False	#End Region#Region  Activity Attributes 	#FullScreen: False	#IncludeTitle: True#End RegionSub Process_Globals	‘These global variables will be declared once when the application starts.	‘These variables can be accessed from all modules.End SubSub Globals	‘These global variables will be redeclared each time the activity is created.	‘These variables can only be accessed from this module.	Dim btnAction As Button	Dim edtResult As EditText	Dim lblComments As Label	Dim lblMathSign As Label	Dim lblNumber1 As Label	Dim lblNumber2 As Label	Dim Number1, Number2 As IntEnd SubSub Activity_Create(FirstTime As Boolean)	‘Do not forget to load the layout file created with the visual designer. For example:	‘Activity.LoadLayout("Layout1")	Activity.LoadLayout("Main")	New End SubSub Activity_ResumeEnd SubSub Activity_Pause (UserClosed As Boolean)End SubSub New	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"	edtResult.Text = ""			‘ Sets edtResult.Text to emptyEnd SubSub btnAction_Click	If btnAction.Text = "O K" Then		If edtResult.Text="" Then			Msgbox("No result entered","E R R O R")		Else			CheckResult		End If	Else		New		btnAction.Text = "O K"	End IfEnd SubSub CheckResult	If edtResult.Text = Number1 + Number2 Then		lblComments.Text = "G O O D  result" & CRLF & "Click on NEW"		btnAction.Text = "N E W"	Else		lblComments.Text = "W R O N G  result" & CRLF & "Enter a new result" & CRLF & "and click OK"	End IfEnd Sub