如何自动将'multiple values'存入'multiple variables'?
How to store 'multiple values' in 'multiple variables' automatically?
我想知道是否可以通过其他任何方式简单地提交以下内容。我将 table“moncal”中的多个值插入 table“累积”(计算学生所有科目的平均出勤率)。 Moncal table 具有 totlec(总讲座)和 totpre(学生在场的总讲座)值,据此,我正在计算所有学生的平均出勤率。因此,在从 'moncal' 获取值时,我将为特定的“rollno”获取多个值,这些值将存储在变量 a1、a2..... 和 b1、b2.... 所以,是有任何方法可以简单地自动声明变量。
这是我使用的代码:
Dim avg As Double
Set p1 = New ADODB.Recordset
p1.Open "select distinct(rollno) from moncal order by rollno asc", conn()
For rollno = 1 To p1.RecordCount
Set p2 = New ADODB.Recordset
p2.Open "select totpre,subcode from moncal where rollno = " & p1.Fields(0) & " order by subcode asc ", conn()
tot1 = 0
tot2 = 0
'avg = 0
a1 = 0
a2 = 0
a3 = 0
a4 = 0
a5 = 0
a6 = 0
a7 = 0
a8 = 0
a9 = 0
a10 = 0
a11 = 0
a12 = 0
a13 = 0
a14 = 0
a15 = 0
b1 = 0
b2 = 0
b3 = 0
b4 = 0
b5 = 0
b6 = 0
b7 = 0
b8 = 0
b9 = 0
b10 = 0
b11 = 0
b12 = 0
b13 = 0
b14 = 0
b15 = 0
For x = 1 To p2.RecordCount
If x = 1 Then
a1 = p2.Fields(0)
ElseIf x = 2 Then
a2 = p2.Fields(0)
ElseIf x = 3 Then
a3 = p2.Fields(0)
ElseIf x = 4 Then
a4 = p2.Fields(0)
ElseIf x = 5 Then
a5 = p2.Fields(0)
ElseIf x = 6 Then
a6 = p2.Fields(0)
ElseIf x = 7 Then
a7 = p2.Fields(0)
ElseIf x = 8 Then
a8 = p2.Fields(0)
ElseIf x = 9 Then
a9 = p2.Fields(0)
ElseIf x = 10 Then
a10 = p2.Fields(0)
ElseIf x = 11 Then
a11 = p2.Fields(0)
ElseIf x = 12 Then
a12 = p2.Fields(0)
ElseIf x = 13 Then
a13 = p2.Fields(0)
ElseIf x = 14 Then
a14 = p2.Fields(0)
ElseIf x = 15 Then
a15 = p2.Fields(0)
ElseIf x = 16 Then
a16 = p2.Fields(0)
ElseIf x = 17 Then
a17 = p2.Fields(0)
ElseIf x = 18 Then
a18 = p2.Fields(0)
ElseIf x = 19 Then
a19 = p2.Fields(0)
ElseIf x = 20 Then
a20 = p2.Fields(0)
Else
Exit For
p2.MoveNext
Next
Set p3 = New ADODB.Recordset
p3.Open "select totlec,subcode from moncal where rollno = " & p1.Fields(0) & " order by subcode asc ", conn()
For y = 1 To p3.RecordCount
If y = 1 Then
b1 = p3.Fields(0)
ElseIf y = 2 Then
b2 = p3.Fields(0)
ElseIf y = 3 Then
b3 = p3.Fields(0)
ElseIf y = 4 Then
b4 = p3.Fields(0)
ElseIf y = 5 Then
b5 = p3.Fields(0)
ElseIf y = 6 Then
b6 = p3.Fields(0)
ElseIf y = 7 Then
b7 = p3.Fields(0)
ElseIf y = 8 Then
b8 = p3.Fields(0)
ElseIf y = 9 Then
b9 = p3.Fields(0)
ElseIf y = 10 Then
b10 = p3.Fields(0)
ElseIf y = 11 Then
b11 = p3.Fields(0)
ElseIf y = 12 Then
b12 = p3.Fields(0)
ElseIf y = 13 Then
b13 = p3.Fields(0)
ElseIf y = 14 Then
b14 = p3.Fields(0)
ElseIf y = 15 Then
b15 = p3.Fields(0)
ElseIf y = 16 Then
b16 = p3.Fields(0)
ElseIf y = 17 Then
b17 = p3.Fields(0)
ElseIf y = 18 Then
b18 = p3.Fields(0)
ElseIf y = 19 Then
b19 = p3.Fields(0)
ElseIf y = 20 Then
b20 = p3.Fields(0)
Else
Exit For
End If
p3.MoveNext
Next
roll = p1.Fields(0)
tot1 = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15 + a16 + a17 + a18 + a19 + a20
tot2 = b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8 + b9 + b10 + b11 + b12 + b13 + b14 + b15 + b16 + b17 + b18 + b19 + b20
avg = tot1 / tot2 * 100
提前致谢。
如果目的只是对值求和,则不需要所有这些变量...
Dim avg As Double
Set p1 = New ADODB.Recordset
p1.Open "select distinct(rollno) from moncal order by rollno asc", conn()
For rollno = 1 To p1.RecordCount
roll = p1.Fields(0)
Set p2 = New ADODB.Recordset
p2.Open "select totpre,totlec,subcode from moncal where rollno = " & roll & " order by subcode asc ", conn()
tot1 = 0
tot2 = 0
For x = 1 To p2.RecordCount
tot1 = tot1 + p2.Fields(0).Value
tot2 = tot2 + p2.Fields(1).Value
If x = 20 Then Exit For
p2.MoveNext
Next
avg = tot1 / tot2 * 100
Debug.Print rollno, avg
Next rollno
我想知道是否可以通过其他任何方式简单地提交以下内容。我将 table“moncal”中的多个值插入 table“累积”(计算学生所有科目的平均出勤率)。 Moncal table 具有 totlec(总讲座)和 totpre(学生在场的总讲座)值,据此,我正在计算所有学生的平均出勤率。因此,在从 'moncal' 获取值时,我将为特定的“rollno”获取多个值,这些值将存储在变量 a1、a2..... 和 b1、b2.... 所以,是有任何方法可以简单地自动声明变量。
这是我使用的代码:
Dim avg As Double
Set p1 = New ADODB.Recordset
p1.Open "select distinct(rollno) from moncal order by rollno asc", conn()
For rollno = 1 To p1.RecordCount
Set p2 = New ADODB.Recordset
p2.Open "select totpre,subcode from moncal where rollno = " & p1.Fields(0) & " order by subcode asc ", conn()
tot1 = 0
tot2 = 0
'avg = 0
a1 = 0
a2 = 0
a3 = 0
a4 = 0
a5 = 0
a6 = 0
a7 = 0
a8 = 0
a9 = 0
a10 = 0
a11 = 0
a12 = 0
a13 = 0
a14 = 0
a15 = 0
b1 = 0
b2 = 0
b3 = 0
b4 = 0
b5 = 0
b6 = 0
b7 = 0
b8 = 0
b9 = 0
b10 = 0
b11 = 0
b12 = 0
b13 = 0
b14 = 0
b15 = 0
For x = 1 To p2.RecordCount
If x = 1 Then
a1 = p2.Fields(0)
ElseIf x = 2 Then
a2 = p2.Fields(0)
ElseIf x = 3 Then
a3 = p2.Fields(0)
ElseIf x = 4 Then
a4 = p2.Fields(0)
ElseIf x = 5 Then
a5 = p2.Fields(0)
ElseIf x = 6 Then
a6 = p2.Fields(0)
ElseIf x = 7 Then
a7 = p2.Fields(0)
ElseIf x = 8 Then
a8 = p2.Fields(0)
ElseIf x = 9 Then
a9 = p2.Fields(0)
ElseIf x = 10 Then
a10 = p2.Fields(0)
ElseIf x = 11 Then
a11 = p2.Fields(0)
ElseIf x = 12 Then
a12 = p2.Fields(0)
ElseIf x = 13 Then
a13 = p2.Fields(0)
ElseIf x = 14 Then
a14 = p2.Fields(0)
ElseIf x = 15 Then
a15 = p2.Fields(0)
ElseIf x = 16 Then
a16 = p2.Fields(0)
ElseIf x = 17 Then
a17 = p2.Fields(0)
ElseIf x = 18 Then
a18 = p2.Fields(0)
ElseIf x = 19 Then
a19 = p2.Fields(0)
ElseIf x = 20 Then
a20 = p2.Fields(0)
Else
Exit For
p2.MoveNext
Next
Set p3 = New ADODB.Recordset
p3.Open "select totlec,subcode from moncal where rollno = " & p1.Fields(0) & " order by subcode asc ", conn()
For y = 1 To p3.RecordCount
If y = 1 Then
b1 = p3.Fields(0)
ElseIf y = 2 Then
b2 = p3.Fields(0)
ElseIf y = 3 Then
b3 = p3.Fields(0)
ElseIf y = 4 Then
b4 = p3.Fields(0)
ElseIf y = 5 Then
b5 = p3.Fields(0)
ElseIf y = 6 Then
b6 = p3.Fields(0)
ElseIf y = 7 Then
b7 = p3.Fields(0)
ElseIf y = 8 Then
b8 = p3.Fields(0)
ElseIf y = 9 Then
b9 = p3.Fields(0)
ElseIf y = 10 Then
b10 = p3.Fields(0)
ElseIf y = 11 Then
b11 = p3.Fields(0)
ElseIf y = 12 Then
b12 = p3.Fields(0)
ElseIf y = 13 Then
b13 = p3.Fields(0)
ElseIf y = 14 Then
b14 = p3.Fields(0)
ElseIf y = 15 Then
b15 = p3.Fields(0)
ElseIf y = 16 Then
b16 = p3.Fields(0)
ElseIf y = 17 Then
b17 = p3.Fields(0)
ElseIf y = 18 Then
b18 = p3.Fields(0)
ElseIf y = 19 Then
b19 = p3.Fields(0)
ElseIf y = 20 Then
b20 = p3.Fields(0)
Else
Exit For
End If
p3.MoveNext
Next
roll = p1.Fields(0)
tot1 = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15 + a16 + a17 + a18 + a19 + a20
tot2 = b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8 + b9 + b10 + b11 + b12 + b13 + b14 + b15 + b16 + b17 + b18 + b19 + b20
avg = tot1 / tot2 * 100
提前致谢。
如果目的只是对值求和,则不需要所有这些变量...
Dim avg As Double
Set p1 = New ADODB.Recordset
p1.Open "select distinct(rollno) from moncal order by rollno asc", conn()
For rollno = 1 To p1.RecordCount
roll = p1.Fields(0)
Set p2 = New ADODB.Recordset
p2.Open "select totpre,totlec,subcode from moncal where rollno = " & roll & " order by subcode asc ", conn()
tot1 = 0
tot2 = 0
For x = 1 To p2.RecordCount
tot1 = tot1 + p2.Fields(0).Value
tot2 = tot2 + p2.Fields(1).Value
If x = 20 Then Exit For
p2.MoveNext
Next
avg = tot1 / tot2 * 100
Debug.Print rollno, avg
Next rollno