1,216
社区成员
发帖
与我相关
我的任务
分享
Private Sub Command1_Click()
Dim NLD(1 To 4) As String, RS(1 To 4) As Integer '定义了二个数组变量
NLD(1) = "20到29岁"
NLD(2) = "30到39岁"
NLD(3) = "40到49岁"
NLD(4) = "50到59岁"
Adodc1.RecordSource = "Select ID,年龄 From 购车记录"
Adodc1.Refresh
Do While Not Adodc1.Recordset.EOF
If Adodc1.Recordset.Fields("年龄") >= 20 And Adodc1.Recordset.Fields("年龄") < 30 Then
RS(1) = RS(1) + 1
ElseIf Adodc1.Recordset.Fields("年龄") >= 30 And Adodc1.Recordset.Fields("年龄") < 40 Then
RS(2) = RS(2) + 1
ElseIf Adodc1.Recordset.Fields("年龄") >= 40 And Adodc1.Recordset.Fields("年龄") < 50 Then
RS(3) = RS(3) + 1
ElseIf Adodc1.Recordset.Fields("年龄") >= 50 And Adodc1.Recordset.Fields("年龄") < 60 Then
RS(4) = RS(4) + 1
End If
Adodc1.Recordset.MoveNext
Loop
MSHFlexGrid1.Clear
With MSHFlexGrid1
.Cols = 3
.Rows = 5
.TextMatrix(0, 1) = "年龄段"
.TextMatrix(0, 2) = "人数"
.ColWidth(0) = 400
.ColWidth(1) = 1000
.ColWidth(2) = 1000
For I = 1 To 4
.TextMatrix(I, 1) = NLD(I)
.TextMatrix(I, 2) = RS(I)
Next I
End With
End Sub