Amerifax-Bob Posted June 20, 2012 Report Share Posted June 20, 2012 I have a line of text that I am copying to Variable %T[90]%. I have a few different scenarios that I need to check that line of text for in order to run the proper macro. I am processing a text file into variables but I need to determine which line I am on within the text file, in order to run the proper macro against that line. I though and IF state would be best. I am familiar with If Statements but somewhere must be missing something. If my variable contains the text: "BLD Info Update" I want to run Macro - Builder "SqFt" I want to run Macro - Model "Picture" I want to run Macro - Picture "Hours" I want to run Macro - Hours I have tried so many different ways and I am just not getting it right. Can't I say: If contains... run macro a or if contains... run macro b or if contains... run macro c I was running into a problem with my End Ifs. I just can't quite see what I am doing wrong. Any help is always appreciated. Heather Quote Link to comment Share on other sites More sharing options...
Cory Posted June 20, 2012 Report Share Posted June 20, 2012 You're on the right track but assuming there's one macro per condition you want something like this below. If contains Ted Run Macro A Endif If contains Fred Run Macro B Endif If contains Tom Run Macro C Endif Caveat being if the text being compared matches multiple If Contains. Otherwise you need to nest the condition with Elses. Also you might want to consider using Switch Case. It often is more elegant and flexible Quote Link to comment Share on other sites More sharing options...
Amerifax-Bob Posted June 20, 2012 Author Report Share Posted June 20, 2012 The text that it contains is unique to the line. I did check out the Switch Case, but I got the understanding it wouldn't work with a "contains" situation but rather an exact equal situation...I could be wrong. (Its been known to happen from time to time...lol) I also need a Macro Return at the bottom of each of the Macros that I am calling right? Also how would be the best way to repeat the Macro? Thanks again Cory!!! Quote Link to comment Share on other sites More sharing options...
acantor Posted June 21, 2012 Report Share Posted June 21, 2012 You could use nested if-else statements, but these get complicated fast... If %X% contains "aaa" // Do this Else If %X% contains "bbb" // Do that Else If %X% contains "ccc" // Do something else End if End if End if // Do this always Not sure whether or not you need to use the Macro Return. I don't think I have ever used it. Experiment with and without it. But I have found that including a Macro Stop statement in a called macro halts the calling macro, so be careful! Quote Link to comment Share on other sites More sharing options...
Cory Posted June 21, 2012 Report Share Posted June 21, 2012 I think you're correct about Switch Case and If Contains. In that case my example stands. If unique you do not need to nest which makes it a lot easier to read. Quote Link to comment Share on other sites More sharing options...
Amerifax-Bob Posted June 21, 2012 Author Report Share Posted June 21, 2012 OK. Maybe I wasn't nesting properly. I will give it another try. I can definitely see how it gets complicated fast though. Thanks for your help. I will let you know how it goes. Heather Quote Link to comment Share on other sites More sharing options...
Amerifax-Bob Posted June 21, 2012 Author Report Share Posted June 21, 2012 Cory, This is the Macro I am using. Now I am having a different problem. The text is not being saved into the Variable. I have tried every which way. The text is in the buffer or clipboard but is not being carried into the Variable. I don't think I have done anything wrong but... I tested up to Line 7 and its not working that far or at least the copy to variable which throws off the rest. Can you see what I am doing wrong?? Window Activate: work - Boxer Text Editor - * Repeat Until %T[90]% Contains "STOP HERE" Clipboard Empty Text Type (Simulate Keystrokes): <SHIFT><END> Clipboard Copy Delay: 465 milliseconds Variable Set String %T[90]% from the clipboard contents // Test for Value If Variable %T[90]% Contains "BLD Info Update" Macro Run: Builder // Run Macro for BUILDER Else If Variable %T[90]% Contains "SqFt" Macro Run: Model // Run Macro for MODEL Else If Variable %T[90]% Contains "Picture" Macro Run: Picture // Run Macro for PICTURE Else If Variable %T[90]% Contains "Hours-" Macro Run: Hours // Run Macro for HOURS Else If Variable %T[90]% Contains "STOP HERE" End If End If End If End If End If Text Type (Simulate Keystrokes): <ARROW DOWN><HOME> End Repeat Quote Link to comment Share on other sites More sharing options...
acantor Posted June 22, 2012 Report Share Posted June 22, 2012 It sometimes takes time for a variable to receive data from the clipboard. Add a delay after the clipboard copy. Add a delay after this line. Variable Set String %T[90]% from the clipboard contents // Test for Value When debugging macros, long delays are your friends. Add delays liberally; you can always remove them later. Quote Link to comment Share on other sites More sharing options...
Amerifax-Bob Posted June 22, 2012 Author Report Share Posted June 22, 2012 Alan, Thanks for the help. I was able to get it to run through. I am still not exactly sure what was causing the problem with getting the text from the clipboard to the variable, but it is working. I am getting occasional problems but I think once I add a few delays all will be fine. Thanks again for the help. Heather Quote Link to comment Share on other sites More sharing options...
Cory Posted June 22, 2012 Report Share Posted June 22, 2012 Heather you don't need to nest. You can do like in my sample. Each works it's just that nested is a little uglier. The clipboard commands take time I believe because MEP is doing some checking and processing. And sometimes the delay is considerable and sometimes very quick. If I want my code to run fast I create a loop with a 100mS delay and set the variable to the clipboard contents. Then I add a condition that when the variable does not equal nothing to break out of the loop. That way if it's working quick I only pay a 100mS penalty. But in the rare occasion that it needs more time it still is accommodated. Sometimes it's better to use CTRL+C instead of the MEP Clipboard Copy command. Always quicker and I don't think I have ever seen a negative side effect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.