Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I found a piece of code online, here is the original version, which works perfectly:
Dim oRuleName As String = "Trip Wire" Dim oTxtFileName As String = "C:\Users\Jesse\Desktop\Sandbox\Jesse's Wonder Emporium\iLogic\Assets\Trip Wire.txt" Dim oRuleText As String = IO.File.ReadAllText(oTxtFileName) Dim oDoc As Document = ThisApplication.ActiveEditDocument Dim oRuleExists As Boolean = False Dim iLogicAuto As IiLogicAutomation = iLogicVb.Automation iLogicAuto.RulesEnabled = True iLogicAuto.RulesOnEventsEnabled = True Dim oRule As iLogicRule Try oRule = iLogicAuto.GetRule(oDoc, oRuleName) oAns = MsgBox("A Rule named '" & oRuleName & "' already exists." & vbCrLf & "Its Text = " & vbCrLf & oRule.Text & vbCrLf & "Do you want to replace its text?", vbYesNo + vbQuestion,"") If oAns = vbNo Then Return '(or Exit Sub) Catch oRule = iLogicAuto.AddRule(oDoc, oRuleName, "") End Try oRule.Text = oRuleText iLogicVb.DocumentUpdate oDoc.Save
I made a few changes (commented out several lines) to fit our needs:
Dim oRuleName As String = "Trip Wire" Dim oTxtFileName As String = "C:\Users\Jesse\Desktop\Sandbox\Jesse's Wonder Emporium\iLogic\Assets\Trip Wire.txt" Dim oRuleText As String = IO.File.ReadAllText(oTxtFileName) Dim oDoc As Document = ThisApplication.ActiveEditDocument 'Dim oRuleExists As Boolean = False Dim iLogicAuto As IiLogicAutomation = iLogicVb.Automation iLogicAuto.RulesEnabled = True iLogicAuto.RulesOnEventsEnabled = True Dim oRule As iLogicRule Try oRule = iLogicAuto.GetRule(oDoc, oRuleName) ' oAns = MsgBox("A Rule named '" & oRuleName & "' already exists." & vbCrLf & ' "Its Text = " & vbCrLf & ' oRule.Text & vbCrLf & ' "Do you want to replace its text?", vbYesNo + vbQuestion,"") ' If oAns = vbNo Then Return '(or Exit Sub) Catch oRule = iLogicAuto.AddRule(oDoc, oRuleName, "") End Try oRule.Text = oRuleText iLogicVb.DocumentUpdate 'oDoc.Save
Now I get an error "Object reference not set to an instance of an object." which points to this line:
oRule.Text = oRuleText
Where did I go wrong? I don't see any reason that removing the message box portion should affect my object definition..
Solved! Go to Solution.