Jump to content
Macro Express Forums

Using % in variable value


Recommended Posts

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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]%

 

 

Link to comment
Share on other sites

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"/>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
 

Link to comment
Share on other sites

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:D

This thread can be closed as resolved.

Regards

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...
 Share

×
×
  • Create New...