Android Question App crashes when trying to change a label's text

kostakost

Member
Hello!
I'm new to this forum (and generally in B4A and Android programming) and this is my first post.
I have a problem with the app I'm developing.
This is the code causing the crash, but I don't know how to fix it:
B4X:
Private DriveStartHour As Int = -1
Private DriveStartMin As Int = -1

Label1.Text = 4 - (DateTime.GetHour(DateTime.Now) - DriveStartHour) + "h  " + 30 - (DateTime.GetMinute(DateTime.Now) - DriveStartMin) + "  min remaining"
Could you please help me solve this problem?
Thank you
 

klaus

Expert
Licensed User
Try this:
Label1.Text = (4 - (DateTime.GetHour(DateTime.Now) - DriveStartHour)) & "h " & (30 - (DateTime.GetMinute(DateTime.Now) - DriveStartMin)) & " min remaining"
Calculations must be between brackets and the + sign musi be replaced by &.:
 

kostakost

Member
Hello!
Thanks for replying! Sorry for not posting an error message, but I could not find it.
The code you wrote above works! :)
Thank you!
 
Top