VBA Extension Commands
AttribValue
VBA Declaration
Function AttribValue (attname As String) As Single
Returns the value of the label named in attname on the current Work Item.
Example
If Signal = "SET: Label 1" Then SetAttribValue "Label 1" , AttribValue("Label 1")*10 End If
AveSize
VBA Declaration
Function AveSize(objectname As String) As Single
Returns the average number of Work Items that have been in the Storage Bin over time.
Example
At the end of the run place the average size of a queue in cell E1.
If Signal = "ENDRUN:" Then Worksheets("Sheet1").Cells(5, 1).value = AveSize("Storage Bin 1") End If
AveTimeIn
VBA Declaration
Function AveTimeIn(objectname As String) As Single
For a Storage Bin returns the average time Work Items have spent in the Storage Bin (for all Work Items that have left the bin/queue). If applied to a Work Exit Point it returns the average time the Work Items that have reached this Work Exit Point have spent in the entire simulation (ie from the point they were created. This is usually at a Work Entry Point, but Work Items can also be created at Work Centers, for example because batching out rules create multiple Work Items).
Example
If Signal = "ENDRUN:" Then Worksheets("Sheet1").Cells(5, 1).value = AveTimeIn("Storage Bin 1") End If
AveTimeInByCategory
VBA Declaration
Function AveTimeInByCategory(objectname As String, Cat As Long) As Single
As AveTimeIn but can retrieve information by segregation category. Set Cat to the desired value of the segregation category. Cat = Zero returns value for all categories (exactly the same value as AveTimeIn).
Example
If Signal = "ENDRUN:" Then Worksheets("Sheet1").Cells(5, 3).value = AveTimeInByCategory("Storage Bin 1",3) End If
AddWItoQueue
VBA Declaration
Sub AddWItoQueue (witypename As String, qname As String)
Creates a new Work Item (of type witypename) and adds it to the back of queue qname. The Work Item created becomes the “Current Work Item”
Example
If Signal = "RESET:" Then For n = 1 To 20 AddWItoQueue "Work Item Type 1", "Storage Bin 1" SetAttribValue "Label 1", n Next n End If
AdjustRoutePercent
VBA Declaration
Sub AdjustRoutePercent (ByVal fromname$)
Pro-rata adjust all route-out percentages after a series of call to SETROUTEPERCENT
Example
If Signal = "TIMECHECK" Then Day = SimTime() Mod (8*60) If Day = 1 Then SetRoutePercent "Work Center 1" , 10 , "Storage Bin 1" SetRoutePercent "Work Center 1" , 10 , "Storage Bin 2" SetRoutePercent "Work Center 1" , 80 , "Storage Bin 3" AdjustRoutePercent "Work Center 1" Else SetRoutePercent "Work Center 1" , 80 , "Storage Bin 1" SetRoutePercent "Work Center 1" , 20 , "Storage Bin 2" SetRoutePercent "Work Center 1" , 0 , "Storage Bin 3" AdjustRoutePercent "Work Center 1" End If End If
BreakDown
VBA Declaration
Sub BreakDown (Wname As String, tt As Single)
Stops a Work Center for tt time units. If tt ⇐ 0 then the Work Center will not restart until you call BreakRestart.
IMPORTANT: Simul8's own breakdown facility must be enabled for a Work Center before you can use this breakdown call for the Work Center. Enable this by creating any breakdown (with a repair time of zero if you do not really want any automatic breakdowns).
If you call breakdown while the Work Center is already broken down then that breakdown will be canceled and the new one substituted.
Example
If Signal = "TIMECHECK" Then If (SimTime() Mod (8*60)) = (2*60) Then 'Note: It is 10am BreakDown "Work Center 1" , 60 End If End If
BreakRestart
VBA Declaration
Sub BreakRestart (Wname As String)
End a breakdown on Work Center Wname
Example
If Signal = "TIMECHECK" Then If QueueSize("Storage Bin 1") <5 Then BreakDown "Work Center 1" , 0 ElseIf QueueSize("Storage Bin 1")> 10 Then BreakRestart "Work Center 1" End If End If
ClearAllResourcesRequired
VBA Declaration
Sub ClearAllResourcesRequired (ByVal wcname$)
Sets all resource requirements at a Work Center to zero (ie no Resources required). Normally used prior to a series of calls to SetResourcesRequired
CollectComplete
VBA Declaration
Sub CollectComplete (Wname As String)
The named Work Center will not wait for any more products. (This only applies to Work Centers using “Collect” routing-in.)
ConnectSimul8
VBA Declaration
Sub ConnectSimul8()
Connects your Excel macros or Visual Basic code to Simul8.
Always use this when your simulation is loaded to ensure that Excel knows which simulation it is operating on. (If you get a message like “Mistake in use of Simul8 Library - Work Center 1 does not exist” - when Work Center 1 does exist, this is usually because you have forgotten to call ConnectSimul8).
Example
If left$(Signal,7) = "LOADED:" then 'Check first 7 characters only 'OK the simulation is now loaded ConnectSimul8 'Ensure Simul8 is ready for parameter changes End If
EmptyQueue
VBA Declaration
Sub Empty Queue (qname As String)
Removes (and throws away) all Work Items in the named queue.
Example
If Signal = "TIMECHECK" Then If (SimTime() Mod (8*60)) = 0 Then 'End of Shift' Empty Queue "Queue for Work Center 1" CollectComplete "Work Center 1" End If End If
ExitSimul8
Example
Including saving the simulation.
Sub ExitSimul8 () Closes Simul8
Get_WI_Held_Resource_Count
VBA Declaration
Get_WI_Held_Resource_Count
Example
If Signal = "DISTRIB: Distrib1" Then N = Get_WI_Held_Resource_Count("Resource 1") SetDistribution "Distrib1" , 10 + (15/N) , 0 , 0 , 0 , "FIXED" End If
MinAveMax
VBA Declaration
Sub MinAveMax (objectname As String, srmin As Single, srave As Single, srmax As Single)
Retrieves results information from a Storage Bin
Example
Dim a min As Single, aave As Single, amax As Single If Signal = “ENDRUN:” Then
MinAveMax "Queue for Work Complete 1", amin, aave, amax Worksheets("Sheet1").Cells(2, 1).value = amin Worksheets("Sheet1").Cells(2, 2).value = aave Worksheets("Sheet1").Cells(2, 3).value = amax
End If
QueueSize
VBA Declaration
Function QueueSize (qname As String) As Long
Returns the current number of Work Items in the queue (Storage Bin) that has the name qname.
Also works with most other Simul8 Objects
Example
If Signal = "SET: Label 1" Then If QueueSize("Storage Bin 1") <10 Then SetAttribValue "Label 1" , 1 ElseIf SetAttribValue "Label 1" , 2 End If End If
ResetSimulation
VBA Declaration
Sub ReSetsimulation (ByVal randnumberstream As Single)
Reset the clock back to the start of the simulation run and change to random number stream: randnumberstream. If randnumberstream is zero then the random number stream is not changed.
Use Stopsimulation first to ensure the simulation is not running.
Example
Resetsimulation Example At the end of the simulation run put the number of completed Work Items in column A in the spreadsheet and run the simulation again using a new random number stream. Dim RunNumb As Integer 'Needs for be above Simul8_Signal If Signal = "ENDRUN:" then RunNumb = RunNumb + 1 Worksheets("Sheet1").Cells(RunNumb, 1).value = QueueSize("Work Complete 1") If RunNumb <10 then Resetsimulation RunNumb Runsimulation 10000 End If End If
RunSimulation
VBA Declaration
Sub Runsimulation (ByVal endttime As Single)
Set the simulation running until endtime.
Example
If left$(Signal,7) = "LOADED:" then 'Check first 7 characters only 'OK the simulation is now loaded ConnectSimul8 'Ensure Simul8 is ready for parameter changes BreakDown "Work Center 1" , 0 Runsimulation End If
SaveSimulation
VBA Declaration
Sub Savesimulation(ByVal fromname$)
Save the simulation to disk filename
Example
Dim RunNumb As Integer 'Needs for be above Simul8_Signal
If Signal = "ENDRUN:" then RunNumb = RunNumb + 1 Worksheets("Sheet1").Cells(RunNumb, 1).value = QueueSize("Work Complete 1") If RunNumb <10 then Resetsimulation RunNumb Runsimulation 10000 If RunNumb> 1 then simulationSpeed 100 Else Resetsimulation 1 Savesimulation "C:\APPS\S8\simulationS\MYsimulation.S8" ExitSimul8 End If End If
SelectWI_In_Object
VBA Declaration
Sub SelectWI_in_Object(ByVal Object_Name As String, ByVal Pos_in_Object As Long)
Change the current Work Item to be the Work Item at a position in an object.
Example
SelectWI_in_Object Example Make speed relative to the number of urgent jobs in the queue. If Signal = "DISTRIB: Distrib1" Then U = 1 For N = 1 to QueueSize("Storage Bin 1") SelectWI_in_Object "Storage Bin 1" , N If AttribValue("Label 1") = 1 then U = U + 1 Next N SetDistribution "Distrib1", 100/U , 5 , 0 , 0 , "NORMAL" End If
SetAttribValue
VBA Declaration
Sub SetAttribValue (attname As String, value As Single)
Sets the value of a label in the current Work Item.
Example
If Signal = "RESET:" Then For n = 1 To 20 AddWItoQueue "Work Item Type 1", "Storage Bin 1" SetAttribValue "Label 1", n Next n End If
SetCollect
VBA Declaration
Sub SetCollect (ByVal fromname$, ByVal number As Integer, ByVal toname$)
Change the number of items required by Work Center TONAME from Work Center FROMNAME
SetConveyor
VBA Declaration
Sub SetConveyor (cname As String, Speed as single, Length as single))
Changes the speed and / or the length of the Conveyor cname. If a value (speed or length) is not to be changed set its value to zero.
Example
Dim RunNumb As Integer 'Needs for be above Simul8_Signal If Signal = "RESET:" Then RunNumb = RunNumb + 1 Speed = Worksheets("Sheet1").Cells(RunNumb, 1).value Length = Worksheets("Sheet1").Cells(RunNumb, 2).value SetConveyor "Conveyor 1" , Speed , Length End If
SetDistribution
VBA Declaration
Sub SetDistribution (distname As String, p1, p2, p3, p4 As Single, disttype As String)
Change the parameters of a “named” distribution. P1, P2, P3 and P4 refer to the 1-4 boxes that appear in the named distribution dialog box. (for example, in the case of a NORMAL distribution, P1 is the average, P2 is the Standard Deviation).
disttype should be one of the following:
* FIXED
- AVERAGE
- NORMAL
- NEGEXP
- UNIFORM
- ERLANG
- LOGNORMAL
- WEIBULL
- BETA
- GAMMA
- TRIANGLE
- PEARSONV
- PEARSONVI
If the disttype parameter is left blank (“ ”) then the distribution type will not be changed.
The above spellings should be used - and only capital letters should appear.
Example
mean = Worksheets("Sheet1").Cells(1, 1).value sd = Worksheets("Sheet1").Cells(1, 2).value SetDistribution "Distrib1" , mean , sd , 0 , 0 , "NORMAL"
SetLabelBatchSize
VBA Declaration
Sub SetLabelBatchSize(rname As String, minvalue As Single, maxvalue As Single)
Change a Work Center's routing-in label batch size parameters.
Example
\\ In this example label 1 contains a product code and we are only prepared to accept products of code 1, 2 or 5. The Work Center is set to batch in on label 1. \\ \\ This code gets the Work Center to take in all items up to but excluding the first Work Item that does not have one of the above product codes. \\ \\ If Signal = "ROUTE_IN_BEFORE: Work Center 1" then \\ MX = 0 \\ For N = 1 to QueueSize("Storage Bin 1") \\ SelectWI_in_Object "Storage Bin 1" , N \\ PC = AttribValue("Label 1") \\ If PC = 1 or PC = 2 or PC = 5 Then MX = MX + PC \\ Else Exit For \\ Next N \\ SetLabelBatchSize "Work Center 1" , MX , MX \\ End If \\ \\ \\
SetMaxLevel
VBA Declaration
Sub SetMaxLevel (rname As String, value As Single)
Change the maximum size of a queue (or similar parameter for other Simul8 objects).
Example
If Signal = "TIMECHECK" Then If SimTime()> 2400 Then 'Week 2' SetMaxLevel "Resource 1" , 20 'More people in second week End If End If
SetResourcesRequired
VBA Declaration
Sub SetResourcesRequired (ByVal resname$, ByVal req As Integer, ByVal wcname$)
Change the number of a particular Resource that are required per ta.
SetPriority
VBA Declaration
Sub SetPriority (ByVal WCname$, ByVal Pri As Integer)
Change a Work Center's priority (assuming at is set to use “Fixed” Priorities).
Example
If Signal = "TIMECHECK" Then If QueueSize("Queue for Work Center 1")> 5 then SetPriority "Work Center 1" , 60 ElseIf SetPriority "Work Center 1" , 40 End If End If
SetRouteMode
VBA Declaration
Sub SetRouteMode(objectname As String, rm As Long)
Set routing out discipline for a Work Center.
The variable rm should be set to one of the following:
Circulate_Route
Uniform_Route
Percent_Route
Priority_Route
Label_Route
Shortest_Route
Example
\\ In this example telephone calls are distributed to a number of call centers using a priority system during the period 8am - 5 pm. Outside this time a uniform rule is used. \\ \\ If Signal = "TIMECHECK" Then \\ Hour = ((SimTime()/60) Mod 24) \\ If Hour>= 8 and Hour <17 Then \\ SetRouteMode "Work Center 1" , Priority_Route \\ Else \\ SetRouteMode "Work Center 1" , Uniform_Route \\ End If \\ End If \\ \\ \\
SetRoutePercent
VBA Declaration
Sub SetRoutePercent (ByVal fromname$, ByVal PC As Single, ByVal toname$)
Changes the routing out percentages from Work Center FROMNAME to Work Center TONAME to percentage PC.
Valid PC values range from 0 to 100. You do not have to check they add to 100% because, after a series of calls to SetRoutePercent you can call AdjustRoutePercent
Example
If Signal = "TIMECHECK" Then Day = SimTime() Mod (8*60) If Day = 1 Then SetRoutePercent "Work Center 1" , 10 , "Storage Bin 1" SetRoutePercent "Work Center 1" , 10 , "Storage Bin 2" SetRoutePercent "Work Center 1" , 80 , "Storage Bin 3" AdjustRoutePercent "Work Center 1" Else SetRoutePercent "Work Center 1" , 80 , "Storage Bin 1" SetRoutePercent "Work Center 1" , 20 , "Storage Bin 2" SetRoutePercent "Work Center 1" , 0 , "Storage Bin 3" AdjustRoutePercent "Work Center 1" End If End If
SetWarmUpPeriod
VBA Declaration
Sub SetWarmUpPeriod(ByVal warm As Single)
Changes the warm up period to warm time units.
Example
\\ Having loaded the simulation, set the warm up period to the value in cell E5 and run the simulation. \\ \\ If left$(Signal,7) = "LOADED:" then \\ SetWarmUpPeriod Worksheets("Sheet1").Cells(5 , 5).value \\ Runsimulation 10000 \\ End If \\ \\ \\
SetWITypeLength
VBA Declaration
Sub SetWITypeLength(witname As String, wilength As Single)
Changes the length of a Work Item type of name witname to length wilength.
SimTime
VBA Declaration
Function SimTime () As Single
Returns the current simulation time in “time units” (as specified in the Clock/ Format dialog in Simul8).
This is a real number that is set to zero when the “reset clock to start” button is pressed.
Example
In this example SimTime is used to discover if people may be away at lunch.
IMPORTANT: Note the use of the variable Hour below. Obviously you can use just about any name here but Excel/VB gets confused if you use Time as a variable name.
Hour = (SimTime()/60) Mod 24 '"Mod 24" causes Hour to be a number from 0 to 23 If Hour>= 12 or Hour <24 Then 'It could be lunch
SimulationSpeed
VBA Declaration
Sub simulationSpeed(ByVal et As Single)
Adjust the position of the speed scroll bar - and thus change the speed of the simulation.
Setting speed zero will stop the simulation. Speed 100 switches off all graphics and runs the clock in high-speed mode.
Example
Dim RunNumb As Integer 'Needs for be above Simul8_Signal If Signal = "ENDRUN:" then RunNumb = RunNumb + 1 Worksheets("Sheet1").Cells(RunNumb, 1).value = QueueSize("Work Complete 1") If RunNumb <10 then Resetsimulation RunNumb Runsimulation 10000 If RunNumb> 1 then simulationSpeed 100 End If End If
StepSimulation
VBA Declaration
Sub Stepsimulation ( )
Causes a simulation to move forward in time by one internal simulation event. For a discussion of how much the simulation will move see Simulation Monitor.
S8_Signal_Done
VBA Declaration
Sub S8_Signal_Done ()
A call to this routine is inserted automatically at the correct place in your Simul8_Signals macro by the Extensions / Excel / Autocreate feature in Simul8. It should be called once and once only every time Simul8_Signals is used.
It tells Simul8 to resume processing of the simulation run. This must be called at the end of your Simul8_Signals VBA macro. Once Simul8 has signaled EXCEL to start your Simul8_Signals macro, Simul8 enters a suspense mode that causes EXCEL to obtain maximum possible use of the PCs processor (to maximize speed of your simulation) and also ensures Simul8 does not process the simulation until EXCEL has made any changes required to the simulation (for example changes to label values etc).
If you fail to call S8_Signal_Done Simul8 will continue waiting and your simulation will not proceed. To ensure the system does not lock up there is a maximum wait period used by Simul8. By default, if Simul8 does not hear back from EXCEL (via S8_Signal_Done) then after 5 seconds Simul8 will resume processing. This means every signal to EXCEL will take 5 seconds causing your simulation to run very very slowly!
If some aspects of your VBA code are intentionally likely to take longer than 5 seconds then you must tell Simul8 to extend its default wait time. For example, in processing a RESET signal you might do a great deal of processing of VBA code to copy initial values into spreadsheet cells and set up initial stocks in Simul8 Storage Bins.
To change the default place the following line in the [STARTUP] section of the S8.INI file in your Simul8 directory.
DDETimeOut=milliseconds
For example
DDETimeOut=60000 will enable Simul8 to wait for up to 1 minute.
Example
Sub Simul8_Signal() Dim Signal As String Signal = GetSignal() If Signal = "DISTRIB: Distrib1" Then SetDistribution "Distrib1", Worksheets("Sheet1").Cells(1,2).value, 0, 0, 0, "NEGEXP" End If S8_Signal_Done End Sub
StopSimulation
VBA Declaration
Sub Stopsimulation ( )
Causes a running simulation to stop.
Example
Dim RowNumb As Integer 'Needs for be above Simul8_Signal
If Signal = “TIMECHECK” then
If QueueSize("Work Complete 1")>= 100 Then Stopsimulation RowNumb = RowNumb + 1 Worksheets("Sheet1").Cells(RowNumb, 1).value = SimTime() End If End If
StopTask
VBA Declaration
Sub StopTask (Wname As String)
A currently active Work Item at the named Work Center will proceed as if its tasked ended immediately (its scheduled time to finish work is brought forward to the current time).
Example
If Signal = "TIMECHECK" Then \\ If (SimTime Mod (8*60)) = 0 Then 'End of Shift' \\ EmptyQueue "Queue for Work Center 1" \\ StopTask "Work Center 1" \\ End If \\ End If \\ \\ \\
Utilization
VBA Declaration
Function Utilization(objectname As String) As Single
Return the percentage utilization of the named object.
Example
At the end of the run place the utilization of a Resource in cell E1.
If Signal = "ENDRUN:" Then Worksheets("Sheet1").Cells(5, 1).value = Utilization("Resource 1") End If