VB FOR 循环语句 问题
Dimi,j,cAsIntegerDima,bAsStringc=0Adodc1.RecordSource="select*frominfwhere下单时间between...
Dim i, j, c As Integer
Dim a, b As String
c = 0
Adodc1.RecordSource = " select * from inf where 下单时间 between #" & DTP1.Value & "# and #" & DTP2.Value & "# "
Adodc1.Refresh
For j = 0 To Combo1.ListCount - 1
b = Combo1.List(j)
For i = 0 To Adodc1.Recordset.RecordCount - 1
a = Adodc1.Recordset.Fields(15).Value
If b = a Then
c = 1 + c
End If
Next i
Text8.Text = Combo1.List(j) + "共" + Str(c) + "记录"
Next j
这里面有一个COMBOBOX控件里面有几个省份的名称(不重复), 一个表中的字段(也就是Fields(15))也有省份名称(有重复),现在想统计 这段时间内 表中字段(Fields(15)中)几个省份的名称,结果显示在Text8.text里! 如:河南共8条记录,内蒙共3条记录,河南共9条记录…… 展开
Dim a, b As String
c = 0
Adodc1.RecordSource = " select * from inf where 下单时间 between #" & DTP1.Value & "# and #" & DTP2.Value & "# "
Adodc1.Refresh
For j = 0 To Combo1.ListCount - 1
b = Combo1.List(j)
For i = 0 To Adodc1.Recordset.RecordCount - 1
a = Adodc1.Recordset.Fields(15).Value
If b = a Then
c = 1 + c
End If
Next i
Text8.Text = Combo1.List(j) + "共" + Str(c) + "记录"
Next j
这里面有一个COMBOBOX控件里面有几个省份的名称(不重复), 一个表中的字段(也就是Fields(15))也有省份名称(有重复),现在想统计 这段时间内 表中字段(Fields(15)中)几个省份的名称,结果显示在Text8.text里! 如:河南共8条记录,内蒙共3条记录,河南共9条记录…… 展开
2个回答
展开全部
用count,否则的话,如果记录太多,你将不停地MoveNext,不停地判断b=a。
Dim i As Integer, n As Long, s As String
Text8 = ""
Adodc1.RecordSource = " select 字段15的名称,count(*) from inf where 下单时间 between #" & DTP1.Value & "# and #" & DTP2.Value & "# group by 字段15的名称"
Adodc1.Refresh
For i = 0 To Combo1.ListCount - 1
s = Combo1.List(i)
n = 0
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
If Adodc1.Recordset.Fields(0) = s Then n = Adodc1.Recordset.Fields(1): Exit Do
Adodc1.Recordset.MoveNext
Loop
Text8 = Text8 & "," & s & "共" & n & "条记录"
Next
将上述语句中的“字段15的名称”修改为你数据库中inf表的第16个字段的字段名称。
Dim i As Integer, n As Long, s As String
Text8 = ""
Adodc1.RecordSource = " select 字段15的名称,count(*) from inf where 下单时间 between #" & DTP1.Value & "# and #" & DTP2.Value & "# group by 字段15的名称"
Adodc1.Refresh
For i = 0 To Combo1.ListCount - 1
s = Combo1.List(i)
n = 0
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
If Adodc1.Recordset.Fields(0) = s Then n = Adodc1.Recordset.Fields(1): Exit Do
Adodc1.Recordset.MoveNext
Loop
Text8 = Text8 & "," & s & "共" & n & "条记录"
Next
将上述语句中的“字段15的名称”修改为你数据库中inf表的第16个字段的字段名称。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Recordset要从头到尾要循环一次。
Dim i, j, c As Integer
Dim a, b As String
c = 0
Adodc1.RecordSource = " select * from inf where 下单时间 between #" & DTP1.Value & "# and #" & DTP2.Value & "# "
Adodc1.Refresh
For j = 0 To Combo1.ListCount - 1
b = Combo1.List(j)
Adodc1.Recordset.MoveFirst
For i = 0 To Adodc1.Recordset.RecordCount - 1
a = Adodc1.Recordset.Fields(15).Value
If b = a Then
c = 1 + c
End If
Adodc1.Recordset.MoveNext
Next i
Text8.Text = Combo1.List(j) + "共" + Str(c) + "记录"
Next j
Dim i, j, c As Integer
Dim a, b As String
c = 0
Adodc1.RecordSource = " select * from inf where 下单时间 between #" & DTP1.Value & "# and #" & DTP2.Value & "# "
Adodc1.Refresh
For j = 0 To Combo1.ListCount - 1
b = Combo1.List(j)
Adodc1.Recordset.MoveFirst
For i = 0 To Adodc1.Recordset.RecordCount - 1
a = Adodc1.Recordset.Fields(15).Value
If b = a Then
c = 1 + c
End If
Adodc1.Recordset.MoveNext
Next i
Text8.Text = Combo1.List(j) + "共" + Str(c) + "记录"
Next j
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询