Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

VBScript

Jan 24, 2006 7:06PM PST

Hello everybody,

I am trying to divide students into tutor groups, the number of students in each tutor group must not be more than 20 but can be less than 20. I r=tried to devive an algorithm but it does not fully work. e.g for 75 students it is giving me 3 groups instead of 4. This is the code I have. Is there anything wrong with it?

Private Sub Tutor_Group_no_Click()
Dim NoG, NoS
Dim rstut As New ADODB.Recordset
rstut.Open ("select * from tblTutor_Group"), CurrentProject.Connection, adOpenKeyset, adLockOptimistic

NoS = DCount("Student_Id", "Query_Computing_and_Information_Systems")

NoG = 1

Do Until (NoS / NoG) <= 20

If (NoS / NoG) > 20 Then
NoG = NoG + 1
rstut.AddNew
rstut("Course_Id") = 1
rstut.Update
End If

Loop

MsgBox "Done"

End Sub

Please can anybody help ?

Discussion is locked

- Collapse -
Re: VBScript
Jan 25, 2006 5:30PM PST

Niranalayo,

Let's follow the code.

You state about the number of groups. That seems like NoG, but it isn't. As an example, take a situation with 2 students. Coding starts with NoG = 1. Until-oop is executed at least once. If-condition, however, isn't true: 2/1 = 2 < 20. So NoG stays 1 and there is no record put into the recordset. But there is a group. In fact, there seems to always be one record less than the value of NoG. The solution could be to write one record outside the loop. Unless, of course, NoS = 0: no students, no group. Your current code doesn't make a difference between 0 and 1, and that seems wrong to me.

Seems like you have to redo the logic a little bit.


Hope this helps.


Kees

- Collapse -
VB
Jan 25, 2006 10:26PM PST

Thanks kees for the tip, I am quite new to VB and I cant think of any logic to apply can u help?

Thank you 4 your response,I am thinking about what u have suggested and will be trying it out.

- Collapse -
(NT) (NT) Elementary math: NoG = integer ((NoS + 19) / 20)
Jan 27, 2006 2:53AM PST
- Collapse -
Thanks a Million !!!
Jan 27, 2006 6:52PM PST

Thanks very much. i did not think of it that way. You are a saver. i cant believe it could be that simple.I guess you are a very good thinker.

Cheers and once again,

Thank you.

- Collapse -
(NT) (NT) You're welcome.
Jan 28, 2006 8:55PM PST