來自SPEL+的使用者事件

您可從SPEL+程式讓事件在.NET應用程式中發生。例如,您可以將連續循環通知給.NET應用程序。這種方法比在控制器中從.NET使用變數值輪詢要來得好。若要從SPEL+將事件引發至Visual Basic,請在SPEL+程式陳述式中使用「SPELCom_Event」命令。
範例:(Visual Basic)

SPELCom_Event 1000, cycNum, lot$, cycTime  

「SPELCom_Event」命令類似於「Print」命令。您可指定一或多個要傳送至.NET應用程式的資料。關於「SPELCom_Event」的詳細資訊, 請參閲以下內容。
SPELCom_Event
在接收事件之前,您必須使用WithEvents子句宣告Spel類別變數。

Public WithEvents m_spel As RCAPINet.Spel  

針對Spel類別執行個體攔截EventReceived常式中的事件。若要編輯此常式,請在宣告Spel類別的模組中,從類別名稱清單選擇「m_spel」,並從程序清單選擇「EventReceived」。

以下是發生事件時更新部分標籤的EventReceived常式中之程式碼範例。

VB 例:

Sub m_spel_EventReceived (ByVal sender As Object, _  
ByVal e As RCAPINet.SpelEventArgs) _  
Handles m_spel.EventReceived  
    Dim tokens() As String  
    Select Case e.Event  
        Case 2000  
           tokens = e.Message.Split(New [Char]() {" "c}, _  
System.StringSplitOptions.RemoveEmptyEntries)  
           lblCycCount.Text = tokens(0)  
           lblLotNumber.Text = tokens(1)  
           lblCycTime.Text = tokens(2)  
    End Select  
End Sub  

C# 例:

void m_spel_EventReceived(object sender, SpelEventArgs e)  
{  
string[] tokens = new string[3];  
switch(e.Event)  
  {  
   case 2000:  
            tokens = e.Message.Split(' ');  
            lblCycCount.Text = tokens(0);  
            lblLotNumber.Text = tokens(1);  
            lblCycTime.Text = tokens(2);  
            break;  
   default:  
            break;  
    }  
}