Hari Posted January 9, 2019 Report Share Posted January 9, 2019 I have a scenario where I need to use % as part of the variable value. For example %T[1]% = "CASH%001". When using the value like this, the variable T[1] is not taking the value correctly and macro is stopped at the line where the string is modified. Thanks in advance for your suggestions. Quote Link to comment Share on other sites More sharing options...
Cory Posted January 9, 2019 Report Share Posted January 9, 2019 I'm headed to bed now so not much time. We have discussed that before in this forum. Please check in here. I'm sure there was a resolution. I just don't remember it off the top of my head. Quote Link to comment Share on other sites More sharing options...
Hari Posted January 9, 2019 Author Report Share Posted January 9, 2019 Thanks Cory for the quick response. I have searched the forum before logging this. But could not find a resolution. Any member's help in providing the link to the resolution is welcome:-) Quote Link to comment Share on other sites More sharing options...
rberq Posted January 9, 2019 Report Share Posted January 9, 2019 Can you show the failing lines of macro code? The following seems to work fine: Variable Set String %T[1]% to "cash%001" Text Box Display: %T[1]% These lines also work for me: Variable Set String %T[1]% to "cash" Variable Modify String %T[1]%: Append Text (%) Variable Modify String %T[1]%: Append Text (001) Text Box Display: %T[1]% Quote Link to comment Share on other sites More sharing options...
acantor Posted January 9, 2019 Report Share Posted January 9, 2019 I'm not sure what the problem is. This script works as expected: // Assign the variable Variable Set String %T[1]% to " CASH%001" // Modify the variable three times Variable Modify String %T[1]%: Left Trim Variable Modify String %T[1]%: Append Text (Hello) Variable Modify String: Replace "Hello" in %T[1]% with "" // Output the variable Text Box Display: Value = ***%T[1]%*** <COMMENT Value="Assign the variable"/> <VARIABLE SET STRING Option="\x00" Destination="%T[1]%" Value=" CASH%001" NoEmbeddedVars="FALSE"/> <COMMENT/> <COMMENT Value="Modify the variable three times"/> <VARIABLE MODIFY STRING Option="\x01" Destination="%T[1]%"/> <VARIABLE MODIFY STRING Option="\x06" Destination="%T[1]%" Value="Hello" NoEmbeddedVars="FALSE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%T[1]%" ToReplace="Hello" All="FALSE" IgnoreCase="FALSE" NoEmbeddedVars="FALSE"/> <COMMENT/> <COMMENT Value="Output the variable"/> <TEXT BOX DISPLAY Title="Value = ***%T[1]%***" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> Quote Link to comment Share on other sites More sharing options...
Hari Posted January 9, 2019 Author Report Share Posted January 9, 2019 Thanks to both of you for your clarification.. Actually I am copying a cell value from Excel to NewCellVal and then applying Trim. it is failing at the code where I am doing "trim" function. the error is Line30: Debug error : Undefined variable or the variable is the wrong type. However if I replace "%" with "-" and then run the same code, there is no error. So I thought the problem may be due to using % in the variable value. I am using version ME Pro 4.8.1.1 Text Type (Simulate Keystrokes): <CTRLD>c<CTRLU> Delay: 300 milliseconds Variable Set String %NewCellval% from the clipboard contents Delay: 300 milliseconds Variable Modify String %NewCellVal%: Trim Delay: 300 milliseconds thanks again for your contribution. Quote Link to comment Share on other sites More sharing options...
rberq Posted January 9, 2019 Report Share Posted January 9, 2019 In Variable Set String, the variable name has lower case v. In the trim command, it is upper case V. Oops! Sorry! Dumb answer. When I tested, lower/upper case in the variable name made no difference. 🙁 Quote Link to comment Share on other sites More sharing options...
Cory Posted January 9, 2019 Report Share Posted January 9, 2019 I was thinking back and I'm pretty sure that was fixed long ago. I did the code below with the sample text in a cell in Excel and copied to the clipboard. I had no error. Variable Set String %Test% from the clipboard contents Variable Modify String %Test%: Trim Quote Link to comment Share on other sites More sharing options...
Cory Posted January 9, 2019 Report Share Posted January 9, 2019 I forgot to mention my version is 6.0.0.1 Quote Link to comment Share on other sites More sharing options...
acantor Posted January 9, 2019 Report Share Posted January 9, 2019 What happens if you put a checkbox in "Don't process embedded variables"? Quote Link to comment Share on other sites More sharing options...
Hari Posted January 10, 2019 Author Report Share Posted January 10, 2019 Dear All, Apologies for not specifying the scenario correctly. After your comments tried to test the scenario again. the result is 1) when I use only one % in the variable value, it is working for me also. No problem. 2) But if I use two % for ex (CASH%CGR%USD) in the value, I am facing the undefined variable error. Unfortunately, I have to use two or more "%" in the value. Though I am using a workaround to solve this issue, it would be better if we can find a straight solution. Thanks again for your efforts. Quote Link to comment Share on other sites More sharing options...
terrypin Posted January 10, 2019 Report Share Posted January 10, 2019 Hi, Joe came up with a solution to this sort of problem about a decade ago. It replaces the percent sign with its ASCII equivalent. Here's my version of it for your issue, which I run after copying the problem cell to the clipboard: Variable Set to ASCII Char 37 to %tPercentSign% Variable Set String %tFromExcel% from the clipboard contents Variable Modify String: Replace "%" in %tFromExcel% with "%tPercentSign%" Text Box Display: Before Trim Variable Modify String %tFromExcel%: Trim Text Box Display: After Trim <VARIABLE SET TO ASCII CHAR Value="37" Destination="%tPercentSign%"/> <VARIABLE SET STRING Option="\x02" Destination="%tFromExcel%" NoEmbeddedVars="TRUE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%tFromExcel%" ToReplace="%" ReplaceWith="%tPercentSign%" All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE"/> <TEXT BOX DISPLAY Title="Before Trim" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 tFromExcel\\f1 = \\f0 %tFromExcel%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <VARIABLE MODIFY STRING Option="\x00" Destination="%tFromExcel%"/> <TEXT BOX DISPLAY Title="After Trim" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 tFromExcel\\f1 = \\f0 %tFromExcel%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Hari Posted January 10, 2019 Author Report Share Posted January 10, 2019 Dear Terry, Thanks for your suggestion. But unfortunately it is not working. Facing the same error. see below code used...It is failing at the same function : trim. Both the text box displays are showing the same value. Variable Set to ASCII Char 37 to %tPerSign% Variable Set String %NewCellVal% from the clipboard contents Delay: 300 milliseconds Text Box Display: New Cell Value Delay: 300 milliseconds Variable Modify String: Replace "%" in %NewCellVal% with "%tPerSign%" Delay: 300 milliseconds Text Box Display: New Cell Value Variable Modify String %NewCellVal%: Trim Quote Link to comment Share on other sites More sharing options...
terrypin Posted January 10, 2019 Report Share Posted January 10, 2019 That's odd. Did you first successfully run my macro exactly as it stands? Please post your code, (not just the command text), so that I don't have to type it all again. Terry, UK Quote Link to comment Share on other sites More sharing options...
Hari Posted January 10, 2019 Author Report Share Posted January 10, 2019 Dear Terry, When I was testing your code, I did not select the option "do not process embedded variables". My mistake. I think this is why your method was failing when I tested it. Now I am able to run the task even after using % in the variable value after replacing % with ASCII Char 37. Thank you very much for the help This thread can be closed as resolved. Regards Quote Link to comment Share on other sites More sharing options...
terrypin Posted January 10, 2019 Report Share Posted January 10, 2019 That would explain it - pleased to hear you have it working! I'm curious how your mistake with my code arose. Did you not copy/paste the code directly, as intended? Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Hari Posted January 10, 2019 Author Report Share Posted January 10, 2019 No Terry. I went by the text and rewrote it and missed that option. After your second post, I understood I missed something and went by the code carefully. 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.