1、开始发送命令: result& = MMC_sendCommand("MN,MA873813"),目的是让仪器运动。
2、接着要获取运动位置(Label17.Caption是显示位置信息):   result& = MMC_getPos
                                                           Label17.Caption = result& / 145635.5328
3、判断:如果Label17.Caption的信息不变,继续发送1的命令;如果Label17.Caption的值大于0以及Label17.Caption的值不变,停止发送1的命令。如果发送1的命令发送了5次,Label17.Caption的位置信息还是不变,即为0,提示“重启VB”。
4、下步接着干其他的事

解决方案 »

  1.   

    Private Sub Command1_Click()
        Dim k1 As Byte
        Dim temp As Single
        Dim flg As Boolean
        
        Do
          result& = MMC_sendCommand("MN,MA873813") '发送命令
          result& = MMC_getPos '获取运动位置(Label17.Caption是显示位置信息):
          Label17.Caption = result& / 145635.5328 '给Label17.Caption赋值
          If Val(Label17.Caption) = 0 Then '如果Label17.Caption的信息不变
             i = i + 1          '累计发送次数
             If i = 5 Then      '不到5次继续发送命令
                MsgBox "重启VB" '到了5次
                End
             End If
          ElseIf Val(Label17.Caption) > 0 Then '如果Label17.Caption的值大于0
             If Not flg Then
                temp = Val(Label17.Caption) '记录第一个值
                flg = True
             Else
                If temp = Val(Label17.Caption) Then '和第二个值比较
                   Exit Do '没有变化,停止发送1的命令
                End If
             End If
          End If
        Loop
    End Sub
      

  2.   

    Dim k1 As Byte 
    改成
    dim i as integer
      

  3.   

    回chinaboyzyq(猴哥) :
    我按照你的思路运行,怎么VB就运行不起来呢 !设置断点就是在这里程序跑不过去。程序倒是没有报错!也没有提示我"重启VB"。    Dim zjx As Integer
        Dim Temp15 As Single
        Dim flg0 As Boolean
        Do
          DoEvents
          result& = MMC_sendCommand("MN,MA873813") '发送到正极限命令
          result& = MMC_getPos '获取运动位置(Label17.Caption是显示位置信息):
          Label17.Caption = result& / 145635.5328 '给Label17.Caption赋值
          If Val(Label17.Caption) = 0 Then '如果Label17.Caption的信息不变
            zjx = zjx + 1          '累计发送到正极限命令次数
            If zjx = 5 Then      '不到5次继续发送到正极限命令
                MsgBox "重启VB" '到了5次
                End
            End If
          ElseIf Val(Label17.Caption) > 0 Then '如果Label17.Caption的值大于0
            If Not flg0 Then
                Temp15 = Val(Label17.Caption) '记录第一个值
                flg0 = True
            Else
                If Temp15 = Val(Label17.Caption) Then '和第二个值比较
                  Exit Do '没有变化,停止发送到正极限的命令
                End If
            End If
          End If
        Loop
      

  4.   

    还是按照5楼的程序 发现      If Val(Label17.Caption) = 0 Then '如果Label17.Caption的信息不变 这个判断语句就没有起作用 。
    会一直发送result& = MMC_sendCommand("MN,MA873813") '发送到正极限命令