Basic reading and googling skills get you a long way.
shakeNbake444 wrote:
Doing it exactly how you shown I get:
Error on Line 11 : 'oSubOccurrence1' is not declared. It may be inaccessible due to its protection level.
So if i try to declare it with the following code:
oCompDef = ThisDoc.Document.ComponentDefinition
oAssyOccurrences = ThisDoc.Document.ComponentDefinition.Occurrences
iLogicVb.RunRule("DescriptionEditor")
Dim oSubOccurrence1 As ComponentOccurrence
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAssyOccurrences
If oSubOccurrence1.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
iLogicVb.RunExternalRule("DescriptionEditor")
End If
Next
From a dictionary:
"declare: openly or formally asserted or announced."
Hmmm. So based off the definition given above, and using linguistic skills, it's saying "I don't know what SubOccurrence1 is".
Now if we look at the code for the places that occurs, we see it's given a type with this line:
Dim oSubOccurrence1 As ComponentOccurrence
K. That's all cool. Variable is explicitly declared (given a type). Maybe the error statement is a bit of a misnomer. But it still implies the issue is with SubOccurrence1.
The next occurrence of SubOccurrence1 is:
If oSubOccurrence1.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Hmm. Interesting. We are accessing a property/method of suboccurrence1, but do we know what it is/where it came from? NOPE!
Just like in english, if I'm talking to a group of people and say "You, grab that phone!", no one would have a clue of who I am talking to unless I somehow indicate who. Same thing applies in programming. SubOccurrence1 is the 'same' as "you"; it's obviously a thing, but we have no clue of who it is.
How do we fix it? We tell it who SubOccurrence one is.
So if in english, I say
"Each Person In the crowd, Go Touch that phone"
or in pseudocode:
For Each PERSON in CROWD
Person.TouchThePhone
Next PERSON
we know that we will go through every person. The translation from that into this situation is:
For Each oOccurrence In oAssyOccurrences
If oOccurrence.DefinitionDocumentType ........
Next
OR
For Each oSubOccurrence1 In oAssyOccurrences
If oSubOccurrence1.DefinitionDocumentType ........
Next
Again, a little bit of reading and a little bit of learning will get you a long way.....
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.