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

Discussion in 'Android Questions' started by kostakost, Aug 5, 2018.

  1. kostakost

    kostakost Member

    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:
    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
  2. klaus

    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 &.:
    BillMeyer, kostakost and Erel like this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    You should always post the error message.

    Label1.Text = $"${4 - (DateTime.GetHour(DateTime.Now) - DriveStartHour)}h ${30 - (DateTime.GetMinute(DateTime.Now) - DriveStartMin)} min remaining"$
    BillMeyer and kostakost like this.
  4. kostakost

    kostakost Member

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

    klaus Expert Licensed User

    In Logs Tab at the right of the IDE you will see the errors.

    kostakost and Erel like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice