Inventor General Discussion

Reply
Active Contributor
nikhunter
Posts: 28
Registered: ‎05-05-2011
Message 1 of 20 (298 Views)

Spell a word on VBA

298 Views, 19 Replies
04-04-2013 06:19 AM

Hello to everyone.For on more time i want your help for a problem that i face


I just wanna do the follownig.

 

I want to create a label with a textbox (myabe) in which i will write by my keyboard a word.After that i want to press the "Enter" button and the programm do this simple thing...."SPELL" each letter of my word, an activate a specific command each time and in my case a specific RULE from iLogic.

 

For example, i wanna whrite my name.....NIKOS....and after pressing the ENTER button, firstly my programm read the letter "N" and trigger the Rule1....After a specific time (that i want to defined by myself, probably with a timer) the programm read the right next letter which is "I" and activate the next Rule2...Until the last letter where it will end.

 

I should note here that i already have the code that i can calling as Rule i wish.But i dont know how to use it for my job....

 

The code is the following which I had gotten from someone of here...

 

 

 

Dim iLogicAuto As Object
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub

Dim doc As Document
Set doc = ThisApplication.ActiveDocument

Dim ruleName As String
ruleName = "Rule1"
Dim rule As Object
Set rule = iLogicAuto.GetRule(doc, "Rule1")
If (rule Is Nothing) Then
Call MsgBox("No rule named " & ruleName & " was found in the document.")
Exit Sub
End If

Dim i As Integer
i = iLogicAuto.RunRuleDirect(rule)

 

 

 

 

 

Thanks and i apriciate your help

 

*Expert Elite*
mrattray
Posts: 2,507
Registered: ‎09-13-2011
Message 2 of 20 (278 Views)

Re: Spell a word on VBA

04-04-2013 08:10 AM in reply to: nikhunter

I'm not sure I understand what you're trying to do, but I'll take a shot. This assumes that what you posted works.

 

 

Public Sub readInput

Dim letter As String
Dim word As String

'Creates a prompt for you to type a word into and assigns it to the variable "word".
word = InputBox("Enter your word.", vbOkCancel, "Your Title")

'Loops through each character in the word you entered.
For i = 1 to Len(word)

'Sets the variable "letter" to each character in "word"
letter = Mid(word, i, 1)
'Fires sub "runRule" and feeds it the variable "letter". This will fire once for every character in "word"
runRule(letter)

Next

End Sub

Private Sub runRule (letter As String)

Dim iLogicAuto As Object
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub

Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim rule As Object
Dim ruleName As String
Dim i As Integer

Select Case letter
Case Is = "A"
ruleName = "Rule1"
Case Is = "B"
ruleName = "Rule2"
Case Else
  msgbox("Invalid Entry",vbokonly,"Error")
End Select

Set rule = iLogicAuto.GetRule(doc, ruleName)
If (rule Is Nothing) Then
Call MsgBox("No rule named " & ruleName & " was found in the document.")
Exit Sub
End If

i = iLogicAuto.RunRuleDirect(rule)

End Sub

 

Note that I wrote this in a text file and didn't test it at all or use any references besides my memory... there may be errors. :smileyhappy:

Mike (not Matt) Rattray

Active Contributor
nikhunter
Posts: 28
Registered: ‎05-05-2011
Message 3 of 20 (268 Views)

Re: Spell a word on VBA

04-04-2013 09:19 AM in reply to: nikhunter

First of all thanks for your imidiate response...

 

I must tell you that it works but not completely...The failure is that after of activation of each Rule, i want to see its result....in this case i see only the last result....

 

For example i have a circle...Rule1 cut it in half and Rule2 delete one of the half part....

 

Now.With your code, firstly i see the hole circle and after that i see directly the half....Commonly, the code runs from the back and showing me only the last stage....

 

What I want to do is to watch every stage. I mean firt the hole circle, after that the cutting and finally the half....

But all this its must be doing after pressing the button "OK" automation...I wanna have the picture of each situation...

However thanks for your HELP.It's valuable...

 

*Expert Elite*
mrattray
Posts: 2,507
Registered: ‎09-13-2011
Message 4 of 20 (262 Views)

Re: Spell a word on VBA

04-04-2013 09:28 AM in reply to: nikhunter

If I'm understanding correctly, you want the code to pause in between each rule and wait for the user to click a "continue" button. If I'm right, then this is very easy. Just add the following line to the previous code just before the second End Sub, so this will be the second from very last line in the code.

 

Msgbox("Press OK to continue.",vbokonly,"Continue?")

 

Mike (not Matt) Rattray

Active Contributor
nikhunter
Posts: 28
Registered: ‎05-05-2011
Message 5 of 20 (235 Views)

Re: Spell a word on VBA

04-06-2013 04:00 AM in reply to: nikhunter

Ok i'll try one more last time, and i wish i can give you the point....

 

I actually want to do the last thing you say BUT, without wait the user to click any button...

 

the operation must be gone automation...i press the firstly button "OK" and then the programm read all the letters of my word one by one and activate each Rule corresponds to each letter.

 

I think that my problem is to have a command like "me.refresh" in the loop, which through me out after read any letter, give me the image of my work, and after that puss me back to read the next letter and do the same thing...I try to explain that after each reading some letters I want to have the picture....Ιn my case i just have the last image...I dοnt observe the intermediate stage but only the last one

 

Ι cannot explain better. Anyway i use all of your advise and i hope to fix it out....THANKS again...

*Expert Elite*
mrattray
Posts: 2,507
Registered: ‎09-13-2011
Message 6 of 20 (216 Views)

Re: Spell a word on VBA

04-08-2013 04:16 AM in reply to: nikhunter

I think I understand what you're looking for. I think you're trying to update your display after each rule has been run. If that's correct then you should be able to use this line to accomplish it:

 

 

doc.Update

 

Just insert this in the same spot I suggested inserting the message box earlier, just before the second End Sub. You can combine this with the message box line if you wish (make sure that you put the update line before the message box). This way the user can have a moment to review the results of each rule before continuing.

Mike (not Matt) Rattray

Active Contributor
nikhunter
Posts: 28
Registered: ‎05-05-2011
Message 7 of 20 (194 Views)

Re: Spell a word on VBA

04-09-2013 08:54 AM in reply to: nikhunter

Yeah finally you got the point but it's not still working....

 

At the previous case, and i mean that with the msgbox which placed up to the second "End Sub", everything was ok and the programm run perfect. I had the result you expected from this command....

 

But now, i see again the final stage directly without any intermediate point. I think that's problem about the command "doc.Update"...maybe some other type of command to work.

 

I think i tired you....

*Expert Elite*
mrattray
Posts: 2,507
Registered: ‎09-13-2011
Message 8 of 20 (187 Views)

Re: Spell a word on VBA

04-09-2013 09:28 AM in reply to: nikhunter

It doesn't work even with both lines added? Your code should look like this:

 

Public Sub readInput

Dim letter As String
Dim word As String

'Creates a prompt for you to type a word into and assigns it to the variable "word".
word = InputBox("Enter your word.", vbOkCancel, "Your Title")

'Loops through each character in the word you entered.
For i = 1 to Len(word)

'Sets the variable "letter" to each character in "word"
letter = Mid(word, i, 1)
'Fires sub "runRule" and feeds it the variable "letter". This will fire once for every character in "word"
runRule(letter)

Next

End Sub

Private Sub runRule (letter As String)

Dim iLogicAuto As Object
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub

Dim doc As Document
Set doc = ThisApplication.ActiveDocument
Dim rule As Object
Dim ruleName As String
Dim i As Integer

Select Case letter
Case Is = "A"
ruleName = "Rule1"
Case Is = "B"
ruleName = "Rule2"
Case Else
  msgbox("Invalid Entry",vbokonly,"Error")
End Select

Set rule = iLogicAuto.GetRule(doc, ruleName)
If (rule Is Nothing) Then
Call MsgBox("No rule named " & ruleName & " was found in the document.")
Exit Sub
End If

i = iLogicAuto.RunRuleDirect(rule)

'Check the results
doc.Update
Msgbox("Press OK to continue.",vbokonly,"Continue?")

End Sub

 

This should, after each rule has been run, update the display and wait for OK to be clicked before continuing on to the next rule.

 

I'm not growing tired of you, I'm just having a hard time understanding what you're looking for.

Mike (not Matt) Rattray

Valued Mentor
GSE_Dan_A
Posts: 303
Registered: ‎10-06-2011
Message 9 of 20 (183 Views)

Re: Spell a word on VBA

04-09-2013 09:35 AM in reply to: mrattray

Mike,


I think he wants the rules to fire without having to press OK in between each.  So once OK is initally pressed, the first rule runs, shows the letter. The next rule runs, shows the next letter, and so on, until the complete word is displayed.

GSE Consultants Inc.
Windsor, ON. Canada
Valued Mentor
SeanFarr
Posts: 475
Registered: ‎07-25-2012
Message 10 of 20 (177 Views)

Re: Spell a word on VBA

04-09-2013 09:48 AM in reply to: nikhunter

nikhunter wrote:

 

But now, i see again the final stage directly without any intermediate point. I think that's problem about the command "doc.Update"...maybe some other type of command to work.

 


I think he wants the rule to run with no user input once enter is pressed initially, but the the rules run so fast, there is no pause in between each rule, can you put a timer in between each rule? So that each rule can be seen, 5 seconds or something between each rule ran?

 

I have no VBA knowledge, but this is interesting...

 

Sean

Sean Farr
Product Designer at TESInc.ca

Inventor Professional 2014-Update 2 - AutoCAD Electrical 2014
Win7-x64 | ASUS P8Z77-V | i7 3770 -3.4 GHz | 32GB RAM |
240GB SSD | nVidia GTX 670 4GB - 320.49
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.