Android Question Beginner's problem with MyFirstProgram

JMW

Member
Licensed User
Longtime User
I'm working through the Beginners Guide, creating the MyFirstProgram.
Compiled, loaded onto device (connected via USB), and I'm getting 'wrong' answer. See attached screenshot. I've double-checked the code, and it all seems right. What am I missing?
B4X:
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
 

Attachments

  • Screenshot_MyFirstProg.png
    Screenshot_MyFirstProg.png
    37.9 KB · Views: 241

JMW

Member
Licensed User
Longtime User
That fixed it, but I'm curious why the default values on those two labels aren't read when I enter 10 and hit OK?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Because the numbers are defined in New.
This works too:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    Number1 = 5
    Number2 = 5
'    New
End Sub
Or this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Main")
   Number1 = lblNumber1.Text
   Number2 = lblNumber2.Text
'   New
End Sub
But I prefer New.
 
Upvote 0
Top