Android Question FindNextTime with dynamic list values

andyr00d

Member
Licensed User
Longtime User
Hello,

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?

B4X:
Dim strTimes As String
strTimes = 12+01/60
Dim strTimes2 As String
strTimes2 = 17+12/60
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"
 

emexes

Expert
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:
B4X:
Dim t As Long = FindNextTime(Array As Double(5, 6.5, 20))
you should try using:
B4X:
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.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

andyr00d

Member
Licensed User
Longtime 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:
B4X:
Dim t As Long = FindNextTime(Array As Double(5, 6.5, 20))
you should try using:
B4X:
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.

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?
 
Upvote 0

emexes

Expert
Licensed User
I am wanting to use the FindNextTime sub mentioned here to pass in values from a list as the parameter
Today is your lucky day, because a list of time values is precisely what:
B4X:
Sub FindNextTime(Times As List) As Long
is expecting! You can either construct a variable (list/array) to pass to it, or you can construct it inline with Array().

:)
 
Upvote 0

emexes

Expert
Licensed User
build up a variable to pass through?

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.

B4X:
Dim TimeList As List
TimeList.Initialize

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
    TimeList.Add(ClassStartTime)
Next

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

Dim t As Long = FindNextTime(TimeList)
 
Upvote 0

andyr00d

Member
Licensed User
Longtime 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.

B4X:
Dim TimeList As List
TimeList.Initialize

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
    TimeList.Add(ClassStartTime)
Next

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

Dim t As Long = FindNextTime(TimeList)

That is great! Appreciate your help :)
 
Upvote 0
Top