Jump to content
Macro Express Forums

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

Link to comment
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. 

Link to comment
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.

Link to comment
Share on other sites

  • 5 weeks later...

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

 

Link to comment
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.

Link to comment
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

Link to comment
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

Link to comment
Share on other sites

  • 1 month later...

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

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