#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 Region Sub Process_Globals ‘These global variables will be declared once when the application starts. ‘These variables can be accessed from all modules. End Sub Sub 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 Int End Sub Sub 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 Sub Sub Activity_Resume End Sub Sub Activity_Pause (UserClosed As Boolean) End Sub Sub 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 empty End Sub Sub 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 If End Sub Sub 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 If End Sub
学起来很简单!MyFirst_B4A_Program
时间: 2024-10-13 08:19:26