Hi all well, I'm new to this and I'm doing a basic program, when I press negative subtract -1 and when i press positive adds +1 just want to know how I can put a notice te when the result is 4 saying "lost" in the label 2 I try to add a timer but nothing does not work, I show a photo
Can you zip (from the files menu) and post your code (see manage attachments when posting) so we can see your whole project including what you've done in the designer.
It's better to keep the conversations in the forum so others can see the results, and join in with alternate or more timely solutions.
You don't need a timer to do this, you can call a checking routine after each button click.
B4X:
Sub Button2_Click
label1.Text = label1.Text + 1
CheckScore
End Sub
Sub Button1_Click
label1.Text = label1.Text - 1
CheckScore
End Sub
Sub CheckScore
If label1.Text = "-4.0" Then
Label2.Text = "lost"
End If
End Sub
Also Label1.Text holds a string, so you should compare it with a string "-4.0". It would have worked with a timer too if you had just changed this.
Your entire code should look like this (copy and paste it):
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
'Activity module
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 Label1 As Label
Dim Label2 As Label
' Dim Timer1 As Timer
Dim Button1 As Button
Dim Button2 As Button
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("dada")
'Timer1.Initialize("Timer1",1000)
'Timer1.Enabled = True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button2_Click
Label1.Text = Label1.Text + 1
CheckScore
End Sub
Sub Button1_Click
Label1.Text = Label1.Text - 1
CheckScore
End Sub
Sub CheckScore
Log(Label1.Text)
If Label1.Text = "-4.0" Then
Label2.Text = "lost"
End If
End Sub
Hello again stevel05 , I just wanted to help me make a function, for example in the image where it says 312 , I want every time you push negative or positive 312 down to 311 so successively , when in 312 I want divides 6 the result to the label 1 and when in 260 divide 5 and when in 208 divide 4 ,for example i push positive two times the number 312 decreases to 310 if i push 52 the number 312 decreases to 260 ,when the number is in 260 divide 5 to label 1
I do not think you understood me very well or I did not express myself well, because I'm using a translator, I speak Spanish, I say that every time you click on positive or negative, 312 diminish 1 this way successively up to coming to 260 and this when in 260 the result of the label1 divides 5 , for example in the label 1 the number is 10 and if the label 2 indicates 260 divide automatic 5
Ok No problem, I'm sure your English is infinitely better than my Spanish I'm ashamed to say.
So you want to set Label1.text and Label2.text before you start, then have something like:
B4X:
Button2_Click
Label2.Text = Label2.Text - 1
CheckScore
End Sub
Sub Button1_Click
Label2.Text = Label2.Text - 1
CheckScore
End Sub
Sub CheckScore
If Label2.Text = 312 Then Label1.Text = Label1.Text / 6
If Label2.Text = 260 Then Label1.Text = Label1.Text / 5
If Label2.Text = 208 Then Label1.Text = Label1.Text / 4
End Sub
I'm sorry I'm not sure exactly what you are asking, have a look at page 204 of the beginners guide.pdf 14.2.2 Relational expressions. I think you can download that. It'll help you understand what you need to do. If you get stuck just ask a question with some code examples.