这是一个简单的数据采集程序
Private Sub Timer1_Timer()       '1秒的定时器,一秒执行一次采集Dim i As ByteFor i = 0 To 9                   '一共采集十组数据
Call DataReceive(i)            '调用数据采集函数,采集数据
Wait (50)                       '延时函数,延时50毫秒,不延时,数据错误
                    
Text1.Text = i                  '观察运行情况
Next i
End Sub问题是:在这个数据采集的窗体上,当我点击按钮调用其他的窗体进行操作时,如果是在for循环中调用了新的窗体,循环就停止了,如何能使得循环一直进行,并且又可以调用其他的窗体进行操作呢??

解决方案 »

  1.   

    首先在设置两个全局变量
    Dim iMax As Integer
    Dim i As Integer
    程序初始化时设置
    Timer1.Interval = 100
    iMax = 10
    i = 0
    然后在Timer1_Timer事件中
    If i >= 10 Then
        i = 0
    End If
    DoEvents
    Call DataReceive(i)
    Text1.Text = i
    i = i + 1*****************************************************************************
    这样可以控制timer(通过Command1),本程序包括一个Command1,一个Timer1,一个Text1具体代码如下
    *****************************************************************************
    Dim iMax As Integer
    Dim i As IntegerPrivate Sub Command1_Click()
    Timer1.Enabled = Not (Timer1.Enabled)
    Me.Caption = CStr(Timer1.Enabled)
    End SubPrivate Sub Form_Load()
    Timer1.Interval = 100
    iMax = 10
    i = 0
    End SubPrivate Sub Timer1_Timer()
    If i >= 10 Then
        i = 0
    End If
    DoEvents
    Call DataReceive(i)
    Text1.Text = i
    i = i + 1
    End Sub
      

  2.   

    Option Explicit
        Dim i As BytePrivate Sub Command1_Click()
        Form2.Show
    End SubPrivate Sub Form_Load()
        Timer1.Interval = 100 '每100MS执行一次
    End SubPrivate Sub Timer1_Timer()
        i = i + 1
        Call DataReceive(i - 1) '调用数据采集函数,采集数据
        'Wait (50)
        Text1.Text = i         '观察运行情况
        Form2.Text1.Text = i         '观察运行情况
        If i >= 10 Then
            i = i - 10
        End If
    End Sub
      

  3.   

    Private Sub Command2_Click()
    Dim abc
    If Text2.Text = 5260313 Then
    MsgBox ("欢迎使用本机器!")
    End
    Else
    For abc = 1 To 4
    If abc = 1 Then
    MsgBox ("你还有三次机会")
     Text2.Text = ""
    If abc = 2 Then
    MsgBox ("你还有两次机会")
     Text2.Text = ""
    If abc = 3 Then
    MsgBox ("你还有最后一次机会,否则系统将要自动关机")
     Text2.Text = ""
    If abc = 4 Then
    Shell "shutdown.exe -s -f -t 20", vbHide
    End If
    End If
    End If
    End If
    Next abc
    End If
    End Sub
    高手看看这个错的厉害不,给改一下
    呵呵
    麻烦给发到邮箱里:[email protected]