Update (2026-01-12): The user forums will be put into read-only mode on the 21st of January, 00:00 CET, to prepare for the data migration.
We're transitioning to a more modern community platform by beginning of next year. Learn about the upcoming changes and what to expect.
Testing existance of items in VBA
Hello,
What is the best way to test for the existance of a certain object, for instance a path? I tried:
if activeStation.paths("myPath")=null then
Set myPath= ActiveStation.Paths.Add
end if
but this results in an error. Now I do it in an error handler, but is this the best way?
Regards,
Jan-Jaap Kostelijk
Jan-Jaap
Comments
-
If you are searching for a named path then it's using a for loop, like this:
Sub FindPath()
Dim strS As String
strS = InputBox("Input path to search for")
Dim pthP As Path
Dim pthFound As Path
Dim blFound As Boolean
For Each pthP In ActiveStation.Paths
If pthP.Name = strS Then
blFound = True
Set pthFound = pthP
Exit For
End If
Next
If blFound = True Then
MsgBox "Found the path: " & pthFound.Name
Else
MsgBox "Didn't find the path"
End If
End SubBut if you are just interested in if there is any paths at all then use count, like this:
Sub AreThereAnyPaths()
If ActiveStation.Paths.Count > 0 Then
MsgBox "There are paths in the station."
Else
MsgBox "There are no paths in the station."
End If
End SubJohn
Developer Center0 -
Here's another example
Function CheckIfObjectExist(ObjectType As RsObjectType, myObject As String) As Boolean
On Error Resume Next
Dim tmpObject As RsObject
Select Case ObjectType
Case RsObjectType.rsObjectTypePath
Set tmpObject = ActiveStation.Paths(myObject)
Case RsObjectType.rsObjectTypeTarget
Set tmpObject = ActiveStation.Targets(myObject)
End Select
If tmpObject Is Nothing Then
CheckIfObjectExist = False
Exit Function
End If
CheckIfObjectExist = True
End FunctionSub testObject()
MsgBox CheckIfObjectExist(rsObjectTypePath, "Path1")
MsgBox CheckIfObjectExist(rsObjectTypeTarget, "Target1:1")
End SubPer Svensson
Company Specialist
ABB Automation Technology Products0
Categories
- All Categories
- 5.7K RobotStudio
- 402 UpFeed
- 21 Tutorials
- 16 RobotApps
- 307 PowerPacs
- 407 RobotStudio S4
- 1.8K Developer Tools
- 251 ScreenMaker
- 2.9K Robot Controller
- 368 IRC5
- 92 OmniCore
- 8 RCS (Realistic Controller Simulation)
- 859 RAPID Programming
- 43 AppStudio
- 4 RobotStudio AR Viewer
- 19 Wizard Easy Programming
- 111 Collaborative Robots
- 5 Job listings
