Jump to content
Macro Express Forums

Output phrase with proper grammar


Recommended Posts

I am trying to use a multiple choice menu where multiple answers can be selected. I would then like to use these answers to output a phrase that has correct grammar.

 

For example, if the multiple choice options are A, B, C, X, Y, Z... the output could be something like:

"The answer is A, B, and C"

"The answer is Z"

"The answer is B, X, Y, and Z"

 

I can't seem to wrap my head around this problem. Any guidance is much appreciated.

Link to comment
Share on other sites

This will get you fairly close to what you want. It’s not 100 percent but you can work out the bugs. Basically, it extracts one character at a time from the response saved from the menu, and appends the characters to the output message you are building. Mostly it’s a bunch of Variable Modify String commands, and when you get done you will know all about Variable Modify String. :)

 

Use the multiple-choice version of the menu, saving item value(s) in %T1%. (But you knew that)

 

Build the beginning of your response in a text variable: Variable Set String %T99% "The answer is "

Variable Set Integer %N99% from Length of Variable %T1% (how many responses saved from menu)

 

Repeat Until %N99% < 1

 

Variable Modify String: Copy first character of %T1% to %T90%

Variable Modify String: Append %T90% to %T99%

Variable Modify String: Append “,“ to %T99%

Variable Modify Integer: decrement N99 by 1

Variable Modify String: remove first character from %T1% (the one just moved to the output message)

If N99 = 1 (only one character not yet added to output response)

Variable Modify String: Append “ and “ to %T99%

EndIf

 

Repeat End

 

 

Link to comment
Share on other sites

I think I would build the string backward. Assuming you have all these in an array I would first get the upper limit. If there are less than two just join them with a comma. If there are more than combine them backward and on the first iteration combine with comma and "and".

Link to comment
Share on other sites

Here is a sample macro that may get you started. (Download this macro by clicking on the filename below.)

// -----------------------------------
//   Make choices
// -----------------------------------
Multiple Choice Menu: Symptoms
Clear Variables // Clear the variable array, just in case the Symptoms variable is reused
Split String "%Symptoms%" on ", " into %SymptomArray%, starting at 1 // Split each choice into a separate element of an array variable
 
// Loop through each element of the array variable and assemble the output into the Symptoms2 variable
Repeat Start (Repeat 50 times)
  Variable Set Integer %IdxPlus1% to %Idx%
  Variable Modify Integer %IdxPlus1%: Increment
   
  If Variable %SymptomArray[%Idx%]% Does not Equal "" // If this element of the array is not empty
   
    If Variable %Symptoms2% Equals "" // Is Symptoms2 empty?
      Variable Set String %Symptoms2% to "%SymptomArray[%Idx%]%"
    Else
     
      If Variable %SymptomArray[%IdxPlus1%]% Equals "" // If the next element is blank we know the current element is the last one
      // Handle the last item
        Variable Set String %Symptoms2% to "%Symptoms2% and %SymptomArray[%Idx%]%"
        Repeat Exit // Last item processed, exit the repeat loop
      Else
      // Add this item to the list
        Variable Set String %Symptoms2% to "%Symptoms2%, %SymptomArray[%Idx%]%"
      End If
    End If
  End If
End Repeat
 
// -----------------------------------
//   Display result
// -----------------------------------
Text Box Display: Result

Sample-Multiple Choice And.mex

Link to comment
Share on other sites

I think I would build the string backward. Assuming you have all these in an array I would first get the upper limit. If there are less than two just join them with a comma. If there are more than combine them backward and on the first iteration combine with comma and "and".

 

 

I figured left to right might be easier to visualize. But you're correct, right to left is a little simpler.

Thank you both! very helpful

Link to comment
Share on other sites

 

Here is a sample macro that may get you started. (Download this macro by clicking on the filename below.)

// -----------------------------------
//   Make choices
// -----------------------------------
Multiple Choice Menu: Symptoms
Clear Variables // Clear the variable array, just in case the Symptoms variable is reused
Split String "%Symptoms%" on ", " into %SymptomArray%, starting at 1 // Split each choice into a separate element of an array variable
 
// Loop through each element of the array variable and assemble the output into the Symptoms2 variable
Repeat Start (Repeat 50 times)
  Variable Set Integer %IdxPlus1% to %Idx%
  Variable Modify Integer %IdxPlus1%: Increment
   
  If Variable %SymptomArray[%Idx%]% Does not Equal "" // If this element of the array is not empty
   
    If Variable %Symptoms2% Equals "" // Is Symptoms2 empty?
      Variable Set String %Symptoms2% to "%SymptomArray[%Idx%]%"
    Else
     
      If Variable %SymptomArray[%IdxPlus1%]% Equals "" // If the next element is blank we know the current element is the last one
      // Handle the last item
        Variable Set String %Symptoms2% to "%Symptoms2% and %SymptomArray[%Idx%]%"
        Repeat Exit // Last item processed, exit the repeat loop
      Else
      // Add this item to the list
        Variable Set String %Symptoms2% to "%Symptoms2%, %SymptomArray[%Idx%]%"
      End If
    End If
  End If
End Repeat
 
// -----------------------------------
//   Display result
// -----------------------------------
Text Box Display: Result

thank you!

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