![]() |
#2
Artless2013-01-12 20:05
|

''第一步:用按钮控制 Timer控制的启停
Private Sub cmdBegin_Click()
If cmdBegin.Caption = "开始" Then
timeflag = True
Timer1.Enabled = True
cmdBegin.Caption = "停止"
cmdBegin.SetFocus
Else
cmdBegin.Caption = "开始"
Timer1.Enabled = False
timeflag = False
end if
end sub
''''第二步想要得到5个随机数字,并作为序号查询到相应的照片
Private Sub Timer1_Timer()
Dim sql1, sql2, sql3, sql4, sql5 As String
Dim newno1, newno2, newno3, newno4, newno5 As Integer
Dim linshi As String
Dim msgtext As String
Dim mrcs1, mrcs2, mrcs3, mrcs4, mrcs5 As ADODB.Recordset
Dim i, j, k As Integer
Dim a(49, 4) As String
Dim b(4) As String
sql1 = ""
sql2 = ""
sql3 = ""
sql4 = ""
sql5 = ""
For k = 0 To 49
For i = 0 To 4
a(k, i) = ""
Next i
Next k
For k = 0 To 4
'a(k, i) = " "
Picture1(k).Picture = Nothing
Text11(k).Text = ""
Next k
'End If
'If timeflag = True Then
For k = 0 To 49
For i = 0 To 4
Randomize
l:
a(k, i) = Int(Rnd * 12)
For j = 1 To i - 1
If a(k, j) = a(k, i) Then GoTo l
Next j
' Print a(i)
Next i
Next k
m = Int(50 * Rnd)
sql1 = "select 人员照片 from 重排 where 人员编号='" & Trim(a(m, 0)) & "' "
sql2 = "select 人员照片 from 重排 where 人员编号='" & Trim(a(m, 1)) & "' "
sql3 = "select 人员照片 from 重排 where 人员编号='" & Trim(a(m, 2)) & "' "
sql4 = "select 人员照片 from 重排 where 人员编号='" & Trim(a(m, 3)) & "' "
sql5 = "select 人员照片 from 重排 where 人员编号='" & Trim(a(m, 4)) & "' "
Set mrcs1 = ExecuteSQL(sql1, msgtext)
'Text10(0).Text = a(0)
Picture1(0).Picture = LoadPicture(mrcs1.Fields(0))
Text11(0).Text = mrcs1.Fields(0)
sql1 = ""
'mrcs1.Close
Set mrcs2 = ExecuteSQL(sql2, msgtext)
' Text10(1).Text = a(1)
Picture1(1).Picture = LoadPicture(mrcs2.Fields(0))
Text11(1).Text = mrcs2.Fields(0)
sql2 = ""
'mrcs2.Close
Set mrcs3 = ExecuteSQL(sql3, msgtext)
' Text10(2).Text = a(2)
Picture1(2).Picture = LoadPicture(mrcs3.Fields(0))
Text11(2).Text = mrcs3.Fields(0)
sql3 = ""
'mrcs3.Close
' Next j
Set mrcs4 = ExecuteSQL(sql4, msgtext)
'Text10(3).Text = a(3)
Picture1(3).Picture = LoadPicture(mrcs4.Fields(0))
Text11(3).Text = mrcs4.Fields(0)
'mrcs4.Close
sql4 = ""
Set mrcs5 = ExecuteSQL(sql5, msgtext)
' Text10(4).Text = a(4)
Picture1(4).Picture = LoadPicture(mrcs5.Fields(0))
Text11(4).Text = mrcs5.Fields(0)
' mrcs5.Close
sql5 = ""
' Else
' If timeflag = False Then
' Exit Sub
' End If
' End If
mrcs1.Close
mrcs2.Close
mrcs3.Close
mrcs4.Close
mrcs5.Close
End Sub
问题是在按 停止滚动时, 5张照片有重复的现象,
问是否Timer1.Enabled = False时,Timer1-time()内程序是执行完还是停止在中间??
Private Sub cmdBegin_Click()
If cmdBegin.Caption = "开始" Then
timeflag = True
Timer1.Enabled = True
cmdBegin.Caption = "停止"
cmdBegin.SetFocus
Else
cmdBegin.Caption = "开始"
Timer1.Enabled = False
timeflag = False
end if
end sub
''''第二步想要得到5个随机数字,并作为序号查询到相应的照片
Private Sub Timer1_Timer()
Dim sql1, sql2, sql3, sql4, sql5 As String
Dim newno1, newno2, newno3, newno4, newno5 As Integer
Dim linshi As String
Dim msgtext As String
Dim mrcs1, mrcs2, mrcs3, mrcs4, mrcs5 As ADODB.Recordset
Dim i, j, k As Integer
Dim a(49, 4) As String
Dim b(4) As String
sql1 = ""
sql2 = ""
sql3 = ""
sql4 = ""
sql5 = ""
For k = 0 To 49
For i = 0 To 4
a(k, i) = ""
Next i
Next k
For k = 0 To 4
'a(k, i) = " "
Picture1(k).Picture = Nothing
Text11(k).Text = ""
Next k
'End If
'If timeflag = True Then
For k = 0 To 49
For i = 0 To 4
Randomize
l:
a(k, i) = Int(Rnd * 12)
For j = 1 To i - 1
If a(k, j) = a(k, i) Then GoTo l
Next j
' Print a(i)
Next i
Next k
m = Int(50 * Rnd)
sql1 = "select 人员照片 from 重排 where 人员编号='" & Trim(a(m, 0)) & "' "
sql2 = "select 人员照片 from 重排 where 人员编号='" & Trim(a(m, 1)) & "' "
sql3 = "select 人员照片 from 重排 where 人员编号='" & Trim(a(m, 2)) & "' "
sql4 = "select 人员照片 from 重排 where 人员编号='" & Trim(a(m, 3)) & "' "
sql5 = "select 人员照片 from 重排 where 人员编号='" & Trim(a(m, 4)) & "' "
Set mrcs1 = ExecuteSQL(sql1, msgtext)
'Text10(0).Text = a(0)
Picture1(0).Picture = LoadPicture(mrcs1.Fields(0))
Text11(0).Text = mrcs1.Fields(0)
sql1 = ""
'mrcs1.Close
Set mrcs2 = ExecuteSQL(sql2, msgtext)
' Text10(1).Text = a(1)
Picture1(1).Picture = LoadPicture(mrcs2.Fields(0))
Text11(1).Text = mrcs2.Fields(0)
sql2 = ""
'mrcs2.Close
Set mrcs3 = ExecuteSQL(sql3, msgtext)
' Text10(2).Text = a(2)
Picture1(2).Picture = LoadPicture(mrcs3.Fields(0))
Text11(2).Text = mrcs3.Fields(0)
sql3 = ""
'mrcs3.Close
' Next j
Set mrcs4 = ExecuteSQL(sql4, msgtext)
'Text10(3).Text = a(3)
Picture1(3).Picture = LoadPicture(mrcs4.Fields(0))
Text11(3).Text = mrcs4.Fields(0)
'mrcs4.Close
sql4 = ""
Set mrcs5 = ExecuteSQL(sql5, msgtext)
' Text10(4).Text = a(4)
Picture1(4).Picture = LoadPicture(mrcs5.Fields(0))
Text11(4).Text = mrcs5.Fields(0)
' mrcs5.Close
sql5 = ""
' Else
' If timeflag = False Then
' Exit Sub
' End If
' End If
mrcs1.Close
mrcs2.Close
mrcs3.Close
mrcs4.Close
mrcs5.Close
End Sub
问题是在按 停止滚动时, 5张照片有重复的现象,
问是否Timer1.Enabled = False时,Timer1-time()内程序是执行完还是停止在中间??