Hi there. I am working on a feature in my study app where it will build a list of study sessions and disperse the articles for students to read on various dates. The total number of study sessions will differ as I am using a method to calculate the number of study days between today and the student’s test date, and including in a factor of the user choosing which days of the week he/she plans on studying. This part works and is here for reference
What I am trying to accomplish now is divvying up the articles of X number for each day of study and also accounting for the remainder of articles left. Let me paint a picture:
- User selects 2021-12-01 as the test date and chooses 3 days per week to study
- This equates to 28 study days until the student’s test date using the method in the link above
- There are currently 334 articles in the database table. Using RowCount of 334 / NumberStudyDays of 28, this yields 11.9 topics per day
- But 11 X 28 = 308 (short), and 12 X 28 = 336 (over)
- For testing purposes, I am joining the IDs from the table in a string, and when they reach a threshold of TopicsPerDay, the string is added to an array, which later is used to display in a listbox
Here is a peek at the code. I know this is not best practices, and each string is beginning with a comma, but I’ll clean this up and deal with it later:
dim sessionIDs() as String
dim joinString as String
dim i as Integer = 0
while not rs.AfterLastRow
joinString = joinString + "," + rs.Column("ID").StringValue
i = i + 1
if i = topicsPerDay then
sessionIDs.Add joinString
joinString = ""
i = 0
end if
rs.MoveToNextRow
wend
for j as Integer = 0 to sessionIDs.LastIndex
Listbox2.AddRow sessionIDs(j)
next
I know there is an issue with the if…then part in the loop since the last portion of IDs are not being added to the array since the threshold is not met. This is where I am stuck. Is there a way to loop through a RowSet in increments (11 or 12 in this example) without going out of scope? If so, is that the better way to handle this?