[VBA ] 有人可以幫我看一下這段程式碼嗎?

看板Visual_Basic作者 (moz)時間9年前 (2015/02/08 09:45), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
各位好小弟因為學校的關係接觸到機械手臂 在他的控制程式中看到這些程式碼 因為小弟我沒學過VB 不知道是否有人願意幫我解析一下這程式碼 謝謝 Peripheral mySer As ServoRunnerA @ 0 #DEFINE ID0 0 #DEFINE ID1 1 #DEFINE ID2 2 #DEFINE ID3 3 #DEFINE ID4 4 Dim x,y,z,xx,zz,yy As Byte Dim ID As Byte Dim Pos As Word Sub MAIN() RunFrame(0) Pause 800 Do renew() Select Case x Case 0 RunFrame(0) Pause 800 Case 1 RunFrame(1) Pause 800 Case 2 RunFrame(2) Pause 800 Case 3 RunFrame(3) Pause 800 Pause 800 Case 4 RunFrame(4) Pause 800 Case 5 RunFrame(5) Pause 800 Pause 800 Case 6 RunFrame(6) Pause 800 Case 7 RunFrame(7) Pause 800 Case 8 RunFrame(8) Pause 800 Case 9 RunFrame(9) Pause 800 Case 10 RunFrame(10) Pause 800 Case 11 RunFrame(11) Pause 800 Case 12 RunFrame(12) Pause 800 Case 13 RunFrame(13) Pause 800 Case 14 RunFrame(14) Pause 800 Case 15 Debug "MM",CR MM() End Select Pause 500 Debug CLS Loop End Sub Sub MM() Debug "手動模式",CR ID = 0 Debug "ID=0",CR MA: renew() Select Case x Case 1 Debug "向前或夾",CR forward() Case 2 Debug "向後或鬆",CR Rever() Case 8 ID=0 Debug "ID=0",CR Case 9 ID=1 Debug "ID=1",CR Case 10 ID=2 Debug "ID=2",CR Case 11 ID=3 Debug "ID=3",CR End Select If x<>15 Then Goto MA End If Debug "自動模式",CR End Sub Sub forward() FR: Select Case ID Case 0 Myser.GetNowPos(ID0,Pos) ' Pos = Pos - 100 myser.SetPosTimeAndRun(ID0,Pos,800) ' Pause 800 Case 1 Myser.GetNowPos(ID1,Pos) ' Pos = Pos - 100 myser.SetPosTimeAndRun(ID1,Pos,800) ' Pause 800 Case 2 Myser.GetNowPos(ID2,Pos) ' Pos = Pos + 100 myser.SetPosTimeAndRun(ID2,Pos,800) ' Pause 800 Case 3 Myser.GetNowPos(ID3,Pos) ' Pos = Pos + 100 myser.SetPosTimeAndRun(ID3,Pos,800) ' Myser.GetNowPos(ID4,Pos) ' Pos = Pos - 100 myser.SetPosTimeAndRun(ID4,Pos,800) ' Pause 800 End Select Debug "ID=",ID,CR Debug "Pos=",pOS,CR renew2() If xx=1 Then Goto FR End If End Sub Sub Rever() RE: Select Case ID Case 0 Myser.GetNowPos(ID0,Pos) Pos = Pos + 100 myser.SetPosTimeAndRun(ID0,Pos,800) ' Pause 800 Case 1 Myser.GetNowPos(ID1,Pos) Pos = Pos + 100 myser.SetPosTimeAndRun(ID1,Pos,800) ' Pause 800 Case 2 Myser.GetNowPos(ID2,Pos) Pos = Pos - 100 myser.SetPosTimeAndRun(ID2,Pos,800) ' Pause 800 Case 3 Myser.GetNowPos(ID3,Pos) Pos = Pos - 100 myser.SetPosTimeAndRun(ID3,Pos,800) ' Myser.GetNowPos(ID4,Pos) ' Pos = Pos + 100 myser.SetPosTimeAndRun(ID4,Pos,800) ' Pause 800 End Select Debug "ID=",ID,CR Debug "Pos=",pOS,CR renew2() If xx=2 Then Goto RE End If End Sub Sub RunFrame(ID As Byte) Myser.LoadFrame(ID) Myser.Runallservo() End Sub Sub renew() A0: z=2 A1: x = Readport0 x = x And 15 Debug CSRXY(1,1), %BIN8 x If y=x Then Goto A0 End If Pause 100 z=z-1 If z<>0 Then Goto A1 End If y = x End Sub Sub renew2() B0: zz=0 B1: xx = Readport0 xx = xx And 15 Debug CSRXY(1,2), %BIN8 xx If zz=2 Then Goto B2 End If If yy=xx Then zz=zz+1 Pause 10 Goto B1 End If yy=xx Goto B0 B2: End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.215.154.48 ※ 文章網址: https://www.ptt.cc/bbs/Visual_Basic/M.1423359956.A.02F.html

02/08 14:55, , 1F
洽code_job版
02/08 14:55, 1F
文章代碼(AID): #1Krh_K0l (Visual_Basic)
文章代碼(AID): #1Krh_K0l (Visual_Basic)