Integers are displaying as a double

Quinncunx

Member
Hi, I am quite new to this android developing business (have worked with VB a fair bit) which is why I was drawn to b4a. At the minute, we're looking at converting one of our existing applications to mobile devices starting with android, thus considering purchasing the B4A software, I have been using the trial software to look into whether it will work for what it is we want to achieve ect.

/preamble.

The problem I am having is 2 fold.

  1. Integers are displaying as doubles
  2. Consquently I believe it is not reading the code correctly and causing my "if" statements to not be read i.e
    B4X:
     If dSecs.Text = 60 Then 
    DMins.Text = + 1
    End If

    That is not updating the minutes counter, when the seconds timer display dSecs hits 60

    I believe this is because 60 is being displayed as 60.0
I am not sure if that is the correct diagnosis of the issue, though I suspect it is. Anyway, my code is below and would welcome any sort of prod in the right direction be it either to resources or someone slapping me and saying "You fool this is what you have done wrong"

B4X:
Sub Globals


   Dim bStart As Button
   Dim bStop As Button
   Dim DISMins As Label
   Dim DisSecs As Label
   Dim DMins As Label
   Dim dSecs As Label
   Dim pbRest As ProgressBar
   Dim tmrtimer As Timer
   Dim a As Int
   Dim b As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
a = "0"
Activity.LoadLayout("OSCEMain.bal")
 tmrtimer.Initialize ("tmrtimer", 1000)
 dSecs.Text = a
 DMins.Text = a 
End Sub
Sub tmrtimer_Tick 
b = "1"
a = "0"
dSecs.Text = dSecs.Text + b
If dSecs.Text = 60 Then
DMins.Text = DMins.Text + 1
End If
If dSecs.Text = 60 Then 
dSecs.Text = a
End If

End Sub


Sub bStart_Click
tmrtimer.enabled = True

End Sub

Sub bStop_Click
tmrtimer.enabled = False
dSecs.text = 0

End Sub

Thanks in advance.

Q
 
Last edited:

klaus

Expert
Licensed User
Longtime User
You are mixing up Strings and Integers.
You define b as Int, but why do you try to assign it a string variable ?
b = "1"
it should be
b = 1
a = 0

You should also define the counters as Integers and assign these values to the label text properties.
dSecs.Text = dSecs.Text + b
will not work.

but if you define ISecs as Int
ISecs = ISecs + b
then you can set dSecs.Text = ISecs

Best regards.
 
Upvote 0

Quinncunx

Member
Thanks, that was kinda a stupid mistake on my part and the addition you suggested worked. Though when I then repeat this for a second "hidden" timer and label I am getting the error "Unknown Member : text" I remove .text after the label name and then it tells me the operator is not known I am really confused, am I limited to how many labels/timers I can have per application/gui/window?

B4X:
Sub tmrRest_Tick
b = 1
a = 0
ISecs = ISecs + b
ndRest.Text = ISecs 
If ndRest.Text = a Then 
tmrRest.Enabled = False
End If
End Sub

This part is NOT working whilst this is
B4X:
Sub tmrtimer_Tick 
b = 1
a = 0
ISecs = ISecs + b

dSecs.Text = ISecs
If dSecs.Text = Mins Then
DMins.Text = ISecs
End If
If dSecs.Text = Mins Then 
dSecs.Text = a
End If
If ndRest.Text = Mins Then 
tmrtimer.Enabled = True
End If
End Sub

I just don't understand.
 
Upvote 0

sheriffporter

Member
Licensed User
Longtime User
I'm a newbie too... with some VB experience. It looks to me like maybe you did not DIM the variable in the sub_globals, so id is not recognizing the assigned name in another sub. It will only recognize "objects" that are dimmed in the same sub, or in sub_globals.
 
Upvote 0

blablabla

Member
Licensed User
Longtime User
You can put as label as you want...
I think you should post your entire code to be sure we correctly understand your issues...
 
Upvote 0

Quinncunx

Member
Code as a whole, is going to be something silly and stupid that I am missing

B4X:
Sub Process_Globals   
   
   

End Sub

Sub Globals
   Dim bStart As Button
   Dim bStop As Button
   Dim DISMins As Label
   Dim DisSecs As Label
   Dim DMins As Label
   Dim dSecs As Label
   Dim pbRest As ProgressBar
   Dim tmrtimer As Timer
   Dim tmrrest As Timer
   Dim bell As MediaPlayer
   Dim a As Int
   Dim b As Int
   Dim ISecs As Int
   Dim Mins As Int
   Dim ndrest As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
a = 0
Activity.LoadLayout("OSCEMain.bal")
 tmrtimer.Initialize ("tmrtimer", 1000)
 tmrrest.Initialize ("tmrRest", 1000)
 dSecs.Text = a
 DMins.Text = a 
 ndrest.Text = a
End Sub
Sub tmrtimer_Tick 
b = 1
a = 0
ISecs = ISecs + b

dSecs.Text = ISecs
If dSecs.Text = Mins Then
DMins.Text = ISecs
End If
If dSecs.Text = Mins Then 
dSecs.Text = a
End If
If ndrest.Text = Mins Then 
tmrtimer.Enabled = True
End If
End Sub

Sub tmrrest_Tick
b = 1
a = 0
ISecs = ISecs + b
ndrest.Text = ISecs 
If ndrest.Text = a Then 
tmrrest.Enabled = False
End If
End Sub

Sub ndrest
Mins = 60

If ndrest.Text = Mins Then 
ndrest.Text = a
End If
End Sub
Sub bStart_Click
tmrrest.Enabled = True
End Sub

Sub bStop_Click
tmrtimer.enabled = False
tmrrest.Enabled = False
dSecs.text = a

End Sub

Thanks to everyone for posting
 
Upvote 0

blablabla

Member
Licensed User
Longtime User
ndrest is not unique, you named the same a label and a sub... it's not possible
You should rename the sub
Besides this, you never call the sub "ndrest", so you never do what you put in it
I think you don't need this sub, but if you want to use it, first rename it and remember you should call a sub to make it start
You also don't need 2 identical "if" in a row, you should use only one "if" and put all the instruction in it...
Hope this helps...
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, but I don't understand your logic nor what you want to do.
Besides the comments in the previous post you nerver reinitialize ISecs.
tmrTimer is never enabled, what is it for ?
Below you find a modified code according to what I understood, but as we don't have the whole code it's almost impossible to give you a concrete andwer and we cannot test it.
It would also be much easier to help if you explained what you want to do.
B4X:
Sub Process_Globals    

End Sub

Sub Globals
    Dim bStart As Button
    Dim bStop As Button
    Dim DISMins As Label
    Dim DisSecs As Label
    Dim DMins As Label
    Dim dSecs As Label
    Dim pbRest As ProgressBar
    Dim tmrTimer As Timer
    Dim tmrRest As Timer
    Dim bell As MediaPlayer
    Dim a As Int
    Dim b As Int
    Dim ISecs As Int
    Dim Mins As Int
    Dim ndrest As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    a = 0
    b = 1
    Mins = 60
    
    Activity.LoadLayout("OSCEMain.bal")
    tmrTimer.Initialize ("tmrTimer", 1000)
    tmrRest.Initialize ("tmrRest", 1000)
    ISecs = a
    dSecs.Text = a
    DMins.Text = a 
    ndrest.Text = a
End Sub

Sub tmrTimer_Tick 
    ISecs = ISecs + b
    If ISecs.Text = Mins Then
        DMins.Text = ISecs        '????
        ISecs = a
    End If
    dSecs.Text = ISecs

' when you are in this timer it is already Enabled  
' I don't understand what you want to do  
' this line is wrong you compare a String with an Int
' as I don't know what you want to I  don't how it should be chaged
'    If ndrest.Text = Mins Then 
    If ISecs = Mins Then  ' ????
        tmrTimer.Enabled = True
    End If
End Sub

Sub tmrRest_Tick
    ISecs = ISecs + b
    ndrest.Text = ISecs 
    If ISecs = a Then 
        tmrRest.Enabled = False
    End If
End Sub

' this routine is never called
'Sub ndrest
'    If ndrest.Text = Mins Then ' this line is wrong String and Int
'        ndrest.Text = a
'    End If
'End Sub

Sub bStart_Click
    tmrRest.Enabled = True
End Sub

Sub bStop_Click
    tmrTimer.Enabled = False
    tmrRest.Enabled = False
    dSecs.text = a
    ISecs = a
End Sub
Best regards.
 
Upvote 0

Quinncunx

Member
Thank you for you patience Klaus.

The application (currently used in windows) is a timer used to simulate an exam station for medical students as part of their clinical/communication skills exams.

The timer as a whole lasts 7 minutes with the option to loop, there are 2 phases to the timer.

Phase 1 (tmrrest) is the rest timer, which lasts 60 seconds upon reaching that time it should reset sound a bell, and start the phase 2 timer. The time is not displayed for this timer but rather has a horizontal progress bar to show the time remaining before phase 2 starts.

Phase 2 (tmrtimer) is the main body of application, and lasts 6 minutes with bells that chime at 4 mins, 5 mins and on completion. tmrtimer displays the time in minutes and seconds as to how long the phase as lasted.

For the loop (in the desktop version of the application) I have used a third timer which is activated when a checkbox is selected and runs in the background, once the timer has fired 420 ticks it resets the phase 1 & 2 timers (including itself) and starts the whole process again.

This is what I am trying to achieve with B4A, Obviously I am not as experienced in vb and .net as I had thought, I suspect this is because visual studio does a lot of things for you that you just don't realize (like naming subs correctly)

I hope this explanation is useful and I can provide a link to the desktop app download if seeing that in action would help.

Thanks in advance.

Q
 
Upvote 0

Quinncunx

Member
In essence that is the program that I am looking for.

I have looked at the code, I am not really sure I understand it, looks nothing like I have seen in VB before (feels inexperienced)

However, thank you ever so much for your wisdom, I will study the code and attempt to replicate what you have done without doing a copy and paste job.

Many thanks.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…