Android Question FindNextTime with dynamic list values

Discussion in 'Android Questions' started by andyr00d, Jul 3, 2019.

  1. andyr00d

    andyr00d Member Licensed User


    I am wanting to use the FindNextTime sub mentioned here to pass in values from a list as the parameter (rather than hardcoded values). I tried to give it a string but it won't accept it, how should I do it?

    Dim strTimes As String
    strTimes = 
    Dim strTimes2 As String
    strTimes2 = 
    Dim strFinal As String = strTimes & "," & strTimes2
    Dim t As Long = FindNextTime(strFinal)
    And I'm getting:
    java.lang.NumberFormatException: For input string: "12.016666666666667,17.2"
  2. emexes

    emexes Well-Known Member Licensed User

    Well, for a start you need to pass the times as a list/array, rather combined together into one string.

    Using the example at the top of the post you referred to:
    Dim t As Long = FindNextTime(Array As Double(56.520))
    you should try using:
    Dim t As Long = FindNextTime(Array As Double(strTimes, strTimes2))
    as your last line, where the items strTimes and strTimes2 will be automatically cast from Strings to Doubles.
  3. DonManfred

    DonManfred Expert Licensed User

    Looks like an mistake. Instead of setting a string you are doing some math here
  4. andyr00d

    andyr00d Member Licensed User

    Thanks, but what about a case where the number of parameters (strTimesX) is unknown? I can't see a way to do a loop and build up a variable to pass through?
  5. emexes

    emexes Well-Known Member Licensed User

    Today is your lucky day, because a list of time values is precisely what:
    Sub FindNextTime(Times As ListAs Long
    is expecting! You can either construct a variable (list/array) to pass to it, or you can construct it inline with Array().

  6. emexes

    emexes Well-Known Member Licensed User

    Bear in mind that you can pass either a list or an array to the function.

    An array cannot be extended once Dimmed, so here you'd be better using a list.

    Dim TimeList As List

    Dim ClassStartTime as Double
    For ClassStartTime = 9 to 15+21/60 Step 55/60    'test data = school class start times every 55 minutes from 9am to 3:21pm

    Log(TimeList)    'so we can see what's going on

    Dim t As Long = FindNextTime(TimeList)
    andyr00d likes this.
  7. andyr00d

    andyr00d Member Licensed User

    That is great! Appreciate your help :)
  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