| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 420 人关注过本帖
标题:在线求教 vb timer控件操作和数据库查询的问题
只看楼主 加入收藏
飞天丫头
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-1-12
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
在线求教 vb timer控件操作和数据库查询的问题
程序代码:
''第一步:用按钮控制 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()内程序是执行完还是停止在中间??
搜索更多相关主题的帖子: 数据库查询 color 在线 
2013-01-12 17:04
Artless
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:4211
专家分:28888
注 册:2009-4-8
收藏
得分:20 
停止滚动时, 5张照片有重复的现象随机?
Timer1.Enabled = False时,Timer1-time()内程序应当执行完.

无知
2013-01-12 20:05
飞天丫头
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-1-12
收藏
得分:0 
回复 楼主 飞天丫头
错误的地方已经找到了,
用print 命令把50组随机数打出来到txt 中,发现有重复,实际原因为产生随机数的循环有问题

   For i = 0 To 4(此行改为:  For i = 1 To 5就没有问题了,若为0-4,又一次不循环检查,可能存在重复了)

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


[ 本帖最后由 飞天丫头 于 2013-1-16 21:55 编辑 ]
2013-01-16 21:53
快速回复:在线求教 vb timer控件操作和数据库查询的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.094182 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved