Jump to content
Macro Express Forums
James534

macro with a list

Recommended Posts

I was wondering if the following is possible. 

I would like to use a Variable set string to prompt the user for a response. With the response %answer[1]% , I  would like to see if that response contains a certain phrase which is defined by a list , for example from the list below , if the first item answer contains htn, I would like the response to be "patient has hypertension."

I would like the if then statment to look through the list for the item and then print the repsonse.

I was able to do this by using multiple if then statements, but is is more cumbersone to change them when I need to. I was looking for a way to maintaine a list , so I can change the response periodically. 

I was also looking for a way to keep the data in Macro Express with out having to reference an outside file if possible.


Variable Set String %answer[1]%

if %answer[1]% = "htn"
  text type %response[1]% 
end if

if %answer[1]% = "cough"
  text type %response[1]% 
end if


list 

answer  \  response

htn     \ patient has hypertension
cough   \ patient has a cough


Thanks for any suggestions,

James

Share this post


Link to post
Share on other sites

I would use a loop with two arrays. One would be Input and the other Response. The index of each input would correspond to a response. Start with a pointer of 1 and go up to the number of elements in the array. When the  %answer[1]% matches an Input value then use that same index to type out the corresponding response. 

You can populate these arrays in the macro if you don't want an external file. 

Share this post


Link to post
Share on other sites

The ability to use lists to hold data is built-into some macro languages, but not others. Macro Express doesn't have it, while Dragon Professional (formerly NaturallySpeaking Professional) does. I use lists a lot when developing voice commands, and I rely on them to save time and trouble, and simplify maintenance.

It's probably possible to create a list-like capability in MEP, and that would be a very good thing. Or at least to find an easier way to edit a script. One approach might be to copy the script from the Direct Editor and paste it into a text editor, modify the script there, and then paste the script back into the Direct Editor.

Despite MEP not having lists, there are likely many ways to get this done.

Share this post


Link to post
Share on other sites

Thanks for your responses , I am still trying to figure out a solution.

I was able to use a text file to bring in data in to a variable %text[1]% but it pulls the entire line into the variable by using text file process

I am trying to do the following in the text file:

This is the question 1 , This is the answer 1

This is the question 2, This is the answer 2

Is there a way to do the following?

Import the first half up to the comma into a %text[1]% and then the second half to %answer[1]%

I saw the variable split string, but it states it places the resulting strings into an array, is there a way to split it into two separate arrays?

Thanks

James

 

Share this post


Link to post
Share on other sites

I think I figured this out using the split string command , using

split string using "\" as a divider to the string , the result will go in a separate variable in an index of 1 and 2

 

Share this post


Link to post
Share on other sites

Split will only ever go to one array. Create a temporary array for the split and then do what you want. 

Often I will have file contents and what I do is to read the un-parsed lines into array A then when I split them write back to A for the first one and the second one to the same element in B. I often build quasi-tables this way. Or a quasi-2 dimensional array. 

You can also split on the newline character set (CrLf) at first to stick all them all in one array. But I've found that Text File Process or ASCII File Process command is simpler.

Share this post


Link to post
Share on other sites

I'm late to the thread but if it helps here's a section for your macro. It takes a 'combined' list of the format you specified earlier today and delivers two arrays for use in the rest of the macro.

List
AAA , abdominal aortic aneurysm
AAD , antibiotic-associated diarrhea
AAI , acute arterial insufficiency
AAPMC , antibiotic-associated pseudomembranous colitis
ABCD , airway, breathing, circulation, disability
ABE , acute bacterial endocarditis
ABG , arterial blood gas
ABI , acquired brain injury
ABMT , autologous bone marrow transplantation
ABPA , allergic broncho-pulmonary aspergillosis
ACPO , acute colonic pseudo-obstruction
ACS , altered conscious state
AD , Alzheimer's disease
ADD , attention deficit disorder
ADHD , attention deficit hyperactivity disorder
ADHF , acute decompensated heart failure
ADR , adverse drug reaction
AFL , atrial flutter
BD , bipolar disorder
DIIK , darned if I know

Macro

Text File Begin Process: D:\\ListMedical.txt
  Variable Modify Integer %nIndex%: Increment
  Split String "%tLine%" on " , " into %tBoth%, starting at 1
  Variable Set String %tInput[%nIndex%]% to "%tBoth[1]%"
  Variable Set String %tOutput[%nIndex%]% to "%tBoth[2]%"
  Text Box Display:  // Delete/Disable after testing
Text File End Process
Text Box Display: Result

Code
 

<TEXT FILE BEGIN PROCESS Filename="D:\\\\ListMedical.txt" Start_Record="1" Process_All="TRUE" Records="1" Variable="%tLine%"/>
<VARIABLE MODIFY INTEGER Option="\x07" Destination="%nIndex%"/>
<SPLIT STRING Source="%tLine%" SplitChar=" , " Dest="%tBoth%" Index="1"/>
<VARIABLE SET STRING Option="\x00" Destination="%tInput[%nIndex%]%" Value="%tBoth[1]%" NoEmbeddedVars="FALSE"/>
<VARIABLE SET STRING Option="\x00" Destination="%tOutput[%nIndex%]%" Value="%tBoth[2]%" NoEmbeddedVars="FALSE"/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 nIndex\\f1  = \\f0 %nIndex%\r\n\\par tLine\\f1  = \\f0 %tLine%\r\n\\par tBoth[1]\\f1  = \\f0 %tBoth[1]%\r\n\\par tBoth[\\f1 2\\f0 ]\\f1  = \\f0 %tBoth[\\f1 2\\f0 ]%\r\n\\par tInput[%nIndex%]\\f1  = \\f0 %tInput[%nIndex%]%\r\n\\par t\\f1 Ou\\f0 put[%nIndex%]\\f1  = \\f0 %t\\f1 Out\\f0 put[%nIndex%]%\r\n\\par \r\n\\par \r\n\\par \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" _ENABLED="FALSE" _COMMENT="Delete/Disable after testing"/>
<TEXT FILE END PROCESS/>
<TEXT BOX DISPLAY Title="Result" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\b\\f0\\fs20 %tInput[\\f1 1\\f0 ]%\\f1  = \\f0 %t\\f1 Out\\f0 put[\\f1 1\\f0 ]%\r\n\\par %tInput[\\f1 2\\f0 ]%\\f1  = \\f0 %t\\f1 Out\\f0 put[\\f1 2\\f0 ]%\r\n\\par %tInput[\\f1 3\\f0 ]%\\f1  = \\f0 %t\\f1 Out\\f0 put[\\f1 3\\f0 ]%\r\n\\par \\f1 \r\n\\par etc\\f0 \r\n\\par \r\n\\par %tInput[\\f1 20\\f0 ]%\\f1  = \\f0 %t\\f1 Out\\f0 put[\\f1 20\\f0 ]%\r\n\\par \\b0 \r\n\\par \r\n\\par \r\n\\par \r\n\\par }\r\n" Left="622" Top="485" Width="434" Height="240" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

 

Result and macro file below

Terry, East Grinstead, UK

MedicalList-James.mex

ListMedicalTwoArrays-Result.jpg

Share this post


Link to post
Share on other sites

Terry, this looked like an interesting macro I could use to learn more about arrays and also to possibly use to build other macros but I keep getting an error on Line 2 of an undefined variable or the variable is the wrong type. 

 

Thanks,

 

Mark

Share this post


Link to post
Share on other sites

Hi Mark,

Sounds odd if you’ve simply imported my macro as I exported it.

Does variable nIndex exist in the list under the Variables tab? Is it an integer variable as it should be?

if still having a problem please show us your macro.

Terry, UK

Share this post


Link to post
Share on other sites

Hello Terry,

To pickup where Mark left off. Yes, the nIndex does exist in the Variables tab as an integer variable, but the macro is still throwing the same error:

Undefined variable or the variable is the wrong type "%nindex%"

Macro Name: MedicalList-James

Line Number: 4

Share this post


Link to post
Share on other sites

Hi,

Long while since I worked on that macro! I’ll try to take a look but to ensure there’s no ambiguity could you first upload your macro please.

Share this post


Link to post
Share on other sites

I think I figured it out. nIndex was defined as an integer array and not a single value integer. Once I changed that it works great! Fantastic macro by the way, thanks for sharing! 

Share this post


Link to post
Share on other sites

Pleased to hear you sorted it. And saved me some time this morning!

Thanks for reporting back, disappointingly rare here.

Terry, UK

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×