Jump to content
Macro Express Forums

Display Command Line Number in Text Box Display


Recommended Posts

I have some macros that call other macro and depending, other macros may be called. In case of an error or in certain situations I'll have a text box display pop up. I like to have the name of the macro and the line number. That way in case of an error I can go directly to the text box display in the script editor and make adjustments. Otherwise, when your dealing with multiple macros finding that particular text box display can be difficult.

I can use the variable set from the name of the current macro, but it would be nice if I could set the current line number as a variable or just display it somehow. As it is now I just manually put the line number in. If code gets added or deleted though, that line number is just a general area of where the the text display box might be. So, the question is, is there a way to display the line number in a text box display or a complex pause?

 

Link to comment
Share on other sites

I don't think it's possible to capture the line number in a variable. But perhaps dividing the script into sections might accomplish something similar:

 

Variable Set From Misc:  "Name of Current Macro" into %CurrentMacro%
 
Variable Set Integer %Section% to 1
If Window "Macro Express Pro" is focused
  Text Box Display: Check %CurrentMacro% at Section %Section%
End If
 
// Do something
Variable Modify Integer %Section%: Increment
If Window "Macro Express Pro" is focused
  Text Box Display: Check %CurrentMacro% at Section %Section%
End If
 
// Do something
Variable Modify Integer %Section%: Increment
If Window "Macro Express Pro" is focused
  Text Box Display: Check %CurrentMacro% at Section %Section%
End If
 
// Do something
Variable Modify Integer %Section%: Increment
If Window "Macro Express Pro" is focused
  Text Box Display: Check %CurrentMacro% at Section %Section%
End If

 

Link to comment
Share on other sites

Here's a variation on acantor's idea: Insert a "Label" statement just before or after the Text Box Display, and include the label name in the header and/or text of the box.  No matter how much macro code is added or removed, you can find the label using the Script Editor. 

 

//  
:abc          // Label abc
Text Box Display: abc
//  

 

label.JPG

Link to comment
Share on other sites

Here's another possibility:

 

When running a macro, if there's an unrecoverable error, Macro Express displays a dialog box that looks something like this:

 

Quote

Date: 05-Mar-2024 11:16:03 a.m.

The following error was encountered:

Control does not exist

Macro Name: tmp

Line Number: 51

 

The last line shows the line number.

 

Press Ctrl + C when this dialog box has focus. This hotkey will copy the text to the clipboard.

 

Create a new macro. Choose "Clipboard" as its activation.

 

Choose to activate when the clipboard "contains" unique text from the error message. A good choice is "Line Number:" but another option is "The following error was encountered:"

 

This script should extract the line number, place the value in a variable, and display it.

 

Variable Set String %Clip% from the clipboard contents
 
Variable Set Integer %ClipLength% to the length of variable %Clip%
Variable Set Integer %TargetPosition% to the position of "Line Number:" in %Clip%
Variable Modify Integer: %TargetPosition% = %TargetPosition% + 13
Variable Modify Integer: %CharactersToCopy% = %ClipLength% - %TargetPosition%
Variable Modify String: Copy part of text in %Clip% starting at %TargetPosition% and %CharactersToCopy% characters long to %LineNumber%
Variable Modify String %LineNumber%: Trim
 
Text Box Display: Line Number = %LineNumber%

<VARIABLE SET STRING Option="\x02" Destination="%Clip%" NoEmbeddedVars="FALSE"/>
<COMMENT/>
<VARIABLE SET INTEGER Option="\x0D" Destination="%ClipLength%" Text_Variable="%Clip%"/>
<VARIABLE SET INTEGER Option="\x0E" Destination="%TargetPosition%" Text_Variable="%Clip%" Text="Line Number:" Ignore_Case="FALSE"/>
<VARIABLE MODIFY INTEGER Option="\x00" Destination="%TargetPosition%" Value1="%TargetPosition%" Value2="13"/>
<VARIABLE MODIFY INTEGER Option="\x01" Destination="%CharactersToCopy%" Value1="%ClipLength%" Value2="%TargetPosition%"/>
<VARIABLE MODIFY STRING Option="\x09" Destination="%LineNumber%" Variable="%Clip%" Start="%TargetPosition%" Count="%CharactersToCopy%" NoEmbeddedVars="FALSE"/>
<VARIABLE MODIFY STRING Option="\x00" Destination="%LineNumber%"/>
<COMMENT/>
<TEXT BOX DISPLAY Title="Line Number = %LineNumber%" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs14 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

 

Link to comment
Share on other sites

You guys have some really good ideas here, I like them and it also gives me couple other ideas. One is you could number the text boxes. If you have 5 total, you could number them 1-5 then use Control-f to find the location later. You could also set a variable before the text box like the label idea and have the text box display it. It kind of combines the label/ section idea/ text box number idea. You could even use an integer and have it increase by one for each text box display.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...