Entrance and exit in Arena Visual Basic

Asked

Viewed 103 times

2

I’m having trouble with input and output data between the simulation of Rockwell Arena software and their native Visual Basic. Basically what I want is to receive simulation data for Visual Basic, process it and return the result to the simulation. I started with something very simple, I’m trying to make the variable "Target" always be 5, but using VBA, so every time an entity enters the VBA block, this variable must be set to 5, then go through the decision block and go to "Dispose 5"as shown in the attached image.

I wrote that code

Option Explicit

Dim m As Arena.Model

Dim S As Arena.SIMAN

Private Sub ModelLogic_RunBeginSimulation()

    Set m = ThisDocument.Model

    Set S = m.SIMAN

End Sub

Private Sub VBA_Block_1_Fire()

    Dim Destino As Integer

    S.VariableArrayValue(S.SymbolNumber("Destino")) = 5

End Sub

But on the line S.VariableArrayValue(S.SymbolNumber("Destino")) = 5 the following error message appears: "Run-time error '91': Object variable or with block variable not set" inserir a descrição da imagem aqui

  • Can you add the full code? Make sure you are being called the method ModelLogic_RunBeginSimulation before the VBA_Block_1_Fire.

  • This is already the complete code, I believe that the Arena already takes care of calling the routines in the correct order. Another thing, "Destination" is the variable that controls the block decides, had not made it clear when I asked the question.

  • By the error message it seems that S was not created, ie received a new. Add a Breakpoint run the code step by step and see if S is not Is Nothing.

  • I put some IF’s and found that the S is not Is Nothing

1 answer

0

With the help of the channel guy called "Fayad" I was able to find a solution, however using other functions, and the code was like this:

Option Explicit

Dim m As Arena.Model

Dim s As Arena.SIMAN

Private Sub ModelLogic_RunBeginSimulation()

Set m = ThisDocument.Model

Set s = m.SIMAN

End Sub

Private Sub VBA_Block_1_Fire()

Dim s As SIMAN
Set s = ThisDocument.Model.SIMAN


s.EntityAttribute(s.ActiveEntity, s.SymbolNumber("Destino")) = 5
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.