Jump to content
Macro Express Forums

How To: Multiple Field Input Form Example

Recommended Posts

Getting input from a user in Macro Express is done through prompting or picking choices from a menu. It is a linear process. Ask a question. Get an answer. Ask the next question. Get the next answer. And so it goes. For example, if you want to get a user's first name, last name, and email address, you would prompt three different times, once for each bit of information. It would be nice if all three fields could be placed on a single form for the user to fill in but there is nothing in native Macro Express that will allow this.


You can, however, use Macro Express to generate and power a multiple-field form built from a script. Here is an example. The form is actually an HTA file, which stands for HTML Application Host. It is essentially a web page without all the baggage and is a feature built directly into Windows. If you look in your system folder you will see a file named mshta.exe, which is used to run HTAs.




The attached example macro is self-contained. It is all you need to run the example because it actually generates the HTA file, which in turn writes string variables back to the macro. You only need to import the attached playable (.mxe) file into any Macro Express library (.mex) file. Nothing else is required. There are no external files to deal with. And it cleans up after itself. Any temporary files that are created in your system temp folder are erased before the macro terminates.


The example form contains:

  • Text fields
  • Radio buttons
  • Check boxes
  • A drop-down combo box
  • A multiple-pick list
  • Command buttons

All of which return the user's choices to Macro Express in the form of string variables.


A word about the script. Don't be shy. Take a look at it. It's just a standard HTML document. In fact, if you were to export it out of Macro Express and change the file extension to .htm, it would run in your browser. There is no doubt that you will need to know how to create an HTML document if you want to create a form like this. It isn't that hard to do if you stick with just the basics. That being said, this example goes beyond the basics by using accelerator keys, button handlers, special formatting, and so forth, but I tend to do that when programming. Our clients love it. But Joe ... well never mind. You are free to use this one as a starting point.


A word about security. The advantage to using HTAs is that they are run as trusted scripts because they are local and carry none of the security baggage requirements of a web page. It is also the kind of thing that will make some anti-virus software scream and rant and rave and carry-on like nobody's business, about running a script file. If you are concerned that this example macro and script file might contain a virus (they do not), then feel free to scan the playable (.mxe) file before doing anything with it. Peace-of-mind is a wonderful thing.


A word about testing. I tested this macro and script using Internet Explorer 6 under Win'XP, Win'2k, and Win'98. I believe (but am not sure) that it will also run under Win'ME and Win'95. If I had, or used, Netscape, Opera, or Firefox I would have tested those also. But I don't. So I didn't. So it goes.


Link to comment
Share on other sites



I sometimes compile C++ exe files to have them launched by Macro Express macros, but I would never have thought to dynamically generate VBScript files or HTML files that will dynamically generate MXE files ... :lol: ...


that's GREAT !!! :wub:


I will probably never use your samples "as is", but they are definitely full of small tips and ideas to create our own (powerful) macros ... many thanks !! :D

Link to comment
Share on other sites

Hi Floyd,


Thanks so much for the multiple field input.

For those of us who are not programmers, I thought I would post my attempts to make those scripts usable from Macro Express;


I have posted them as playable, but they need to be imported with the same name to interact; using environment variables to help setup my own forms.


I have not yet set it up to save a text file with my own form field definitions for each task, which would be the next step.


Someone who uses onlyME should be able to set up their own forms using this, without changing the VB sript any further.


can it be simplified or developed further for easier use?


Best, Randall


Link to comment
Share on other sites

Woops, if you have bothered to look, I had intended to make my 2 forms able to accept the buttons without input in the fields; corrected main macro only attached.

(btw, the macro not used in the zip download above ("ChangeMultiOrig") defines all the environment variables for the form labels in the original macro from Floyd (disabled as scrip1 in my "VarMultipleFieldForm" macro)



Link to comment
Share on other sites

Hi, Floyd,


Win98 with IE5.0 does not show the subcategory names ("Halogen" etc), and nor does Win 95 (as I can't update IE 5.5 in Win 95?)


If anyone wants the single playable macro (hard to read), please let me know; it now also makes the text files to load whichever form you have previously made)


Can we call VBA Word macros directly like this too?


Thanks, Randall

Link to comment
Share on other sites



Thanks for the feedback on IE 5.0.


I ran the macros that you posted in order to determine an answer to your question "... can it be simplified or developed further for easier use?". I think so, although your idea of running a macro to develop field names has some uniqueness to it.


I think a tool should be designed which allows developers to generate forms from the ground up. It will need to gather specific information about each Control. And the controls themselves might need to be limited to Text fields, Check boxes, and Radio buttons. Obviously I am thinking small to begin with. Data to be gathered would include positioning for all the controls in addition to Labels for Text boxes and fields.


Once all the information is assembled the macro would generate the necessary Macro Express code and the required HTA code, combine both into an MXE, and as a final step, import it all into an MEX library. ... *poof* a self-generated macro.


As to the "Can we call VBA Word macros directly like this too?" question ... the answer is, yes, and it is not something that requires an HTA. A VBScript will suffice. It would, in fact, replace the Word or Excel VBA macros, rather than just run it. VBScript (.vbs) files can be generated by Macro Express in the same manner that it generates HTA files.


Again, thanks for your feedback. And thanks to jowensii and Nicolas, too.

Link to comment
Share on other sites

Here is my update for people who would like to be able to use multiple field input from MacEx;


It is not done by a programmer!


Anyway, the zip now has 4 macros to import.


1. VarMultipleFieldForm

2. inputFieldChangeMulti

3. InputChangeMulti

4. Copy of Copy of ChangeMulti



After running “Varmultiplefield” once, cancel.

Then run again. Write “hi” in the top field.


Re-run, re-name your buttons if you wish (by inserting field entries)


By then, 2 text files will be in your “c:\program files\macro Express3” directory;


1. One for the form with 10 button names “Buttonsform1.txt” (edit these directly, and/or save them with various text file names for later use if you wish) You need never do this if you only wish to develop the one form.

2. One for the form with 10 field input names “fieldsform1.txt”


I guess it will be a while before Floyd evolves his fully fledged macro for specifying what fields are needed.


If anyone makes any forms to use by using his other buttons, could you please post them?

If anyone finds this is not working as expected, please let me know!


Best, Randall


(PS Floyd – Opera and Firefox work for the “Halogens” etc; but do not re-size or “submit”


Link to comment
Share on other sites

G'Day Randallc


Thanks for the new macros. I like the concept of having a form generate a form, but I am confused as to the end result. If the form that I want generated just required text input fields, could I do that? My assumption from the instructions is that the VarMultipleField macro generates a form, or it generates the 2 text files contained within the Macro Express home folder, or both. But how do I actually use them?



So, do you mean that the Submit button does not work at all in Opera and Firefox, or do you mean that it does not get enabled or disabled? To a larger question: are you running the HTA from within Firefox and Opera by renaming to HTM? Or are you running it using mshta.exe from the macro?

Link to comment
Share on other sites

Hi, Floyd.


"If the form that I want generated just required text input fields, could I do that? "


yes; Sorry I have not been clear.


Once you would run that macro and name the buttons, the field text file will be generated as well as the button text file;


Then use only the appropriate HTA %T1% .


In "VarMultipleField " macro, I have set up the field form to run only if "hi" in firstname field; but you could then just use that in your own macro as a text input form, using that hta script;


Variable Set String %T1% from Environment Variable
   If Variable %T1% = "hi"
    Macro Run: inputFieldChangeMulti
    // radioscript8
    Variable Set String %T1% "<html>PGMCRLF<head>PGMCRLF    <meta http-equiv=
    // radioscript7
    Variable Set String %T1% "<html>PGMCRLF<head>PGMCRLF    <meta http-equiv=
    // ScriptButtons2 - still allows option to bring up renaming form
    Variable Set String %T1% "<html>PGMCRLF<head>PGMCRLF    <meta http-equiv=
    // ScriptButtons3 - scrip to use once stable, renamed
    Variable Set String %T1% "<html>PGMCRLF<head>PGMCRLF    <meta http-equiv=
   End If
   Variable Set %T2% to ASCII Char of 10
   Variable Set %T3% to ASCII Char of 13




So "Macro Run: inputFieldChangeMulti" imports the field names for the text field input form, then you can run "radioscript7" %T1% by itself as your new form for text entry (change the field names for text entry using the text file first). I know I have confused things by giving an example to re-name the buttons,; especially as Icould be using multiple check boxes using the macroExpress input for this!



"are you running the HTA from within Firefox and Opera by renaming to HTM?"

Yes; even setting Firefox as default does not start HTA with a firefox window, that I can see?


Best, Randall

Link to comment
Share on other sites

Okay, I will give it a try using your instructions.



Yes; even setting Firefox as default does not start HTA with a firefox window, that I can see?

This is how it is meant to be. An HTA file is mostly nothing more than a renamed HTM file. So, if you launch it as an HTA, via Macro Express for example, then the Windows mshta.exe program will run it without all the baggage of a web page. And it should run as expected no matter which browser you use, or which is the default. Please let me know if it does not.


If you rename it to an HTM or HTML file, then whichever browser you use will launch it as a web page, complete with all the nightmares of how different browsers parse the same HTML code.

Link to comment
Share on other sites

I don't understand the HTA thing well enough; i presume you were expecting there to be problems with firefox etc, from what you have said?

There is no difference between HTA and HTM or HTML files. You can generate an HTM file from a web page designer like those provided by Macromedia, Adobe, and Microsoft, and then rename it to have an HTA extension. If you do this, and if you double-click on it from say, Windows Explorer, it will be launched by the mshta.exe program. If, on the other hand, it remains as an HTM or HTML file, then it will be launched by your default browser.


I suspect, but am far from sure, that an HTA file will run as programmed no matter which browser you use because it is being controlled by mshta.exe and (I assume) the built-in-to-Windows portion of Internet Explorer. There is a good chance that my assumption is wrong, which isn't the first time and will surely not be the last time.

Link to comment
Share on other sites

  • 2 weeks later...

Under Dialogs I found a Multiple Choice Menue creating a List of different choices. I do not use this, as I find it is too much work to do 2 clicks instead of just one:

1. Select choice by marking

2. Push OK


Instead I often just open a list of choices as e.g. the Windows Explorer and add a "wait for right mouse click command" to continue. Don't you think such a solution would be simpler ?

Link to comment
Share on other sites

Assume I want to choose one of the files I see in a Windows Explorer in the middle of a macro.


I just enter the command "Wait for a right Mouseclick"


If I start this macro, it will open the Windows Explorer and wait

till I have marked the file I have selected and as soon as I click

with my right mouse, the macro will continue and automatically

load the file I selected.


That's the way I prefer to create a Multiple Choice.

Just mark & rightclick, that's all.


I have often tried also to show a floating textbox explaining:

"Please take your choice and continue with a right Mouseclick"

but, unfortunately, the mark on "Keep Focus" doesn't work

reliably. Kevin should keep an eye on this bug !


With this simple way of multiple choice, the only problem is to get

a good list of the choices.


In fact you could use the macro express

command "Create a multiple choice Menu" (from Dialogs)

just to show the list of choices and, instead of let people place a mark

and push OK, you should be able to continue and wait for the right

mouseclick, but I am afraid this doesn't work.

Link to comment
Share on other sites

  • 3 weeks later...

Hi, Floyd,


Here is another simple form as an example using multiple text input and the date calculator (hidden fairly much in "MacroRun" statements.)


The option to use the calendar to use 2 dates for the difference instead too, which I hadn't found before.


What do you think?


Best, Randall


(PS - Only requirement is IE6, I think! - IE5 crashes vbscript in this, then ME- RUNS ON WinME, BUT PERHAPS NOT WIN98?)


Please note also Form Making Library in separate post;


Form Making Library


Edited by randallc
Link to comment
Share on other sites

  • 3 months later...


Just as jowensii posted, I too "have been a ME user for several years and I have been patiently waiting for the ability to do this. Even though it's not just native to ME, this workaround is greatly appreciated."


Thank you so so much. :D


The work you did is amazing.



Link to comment
Share on other sites

Iceman -


We are working on adding both HTAs and data mining macros as additions to the PGM Functions library. Joe is adamant that these are going to be useful tools ... and I agree. Another user in this forum, Randall, has also taken steps in this direction.

Link to comment
Share on other sites

This looks really cool and is something I really like but I get the feeling this isn’t ready for newbie prime time. I played with it a bit and started getting the creeping suspicion that if I wanted to make this work specifically for me it was going to take a lot of learning by trial and error.


Here’s my Q: I’m not an alpha geek or a programmer, is this something I can do easily?


I can make web forms, is there a way I could create a webform in FrontPage and save it to this mystical HTA format by some ‘idiots guide’ so I could use it as input in ME?

Link to comment
Share on other sites

I can make web forms, is there a way I could create a webform in FrontPage and save it to this mystical HTA format by some ‘idiots guide’ so I could use it as input in ME?



I have no idea! - Don't know Web forms very well or FrontPage at all!

Probably possible, but you would be the alpha developer, I suspect!



PS Were you looking at the HTA formbuilder that I wrote or Floyd's original? - I can talk about mine; if so, it was still very rough when I stopped doing anything with it. The forms were really just a starter, and not easy if you've been used to a "proper" program; really I was just exploring for minor applications with a few inputs.

Link to comment
Share on other sites

  • 4 months later...

Thanks for this script - I've just put it to good use taking a load of motherboard specifications, converting them to variables and then plugging them into a huge blob of html code we use as a product description template.


Quick question though - the comments say that you can return the "variant" data type the HTA uses to a integer or decimal - what is the actual syntax for doing this?


I would assume it is something along the lines of


intWrite = _

"<IVAR2:11:01:" & intStockCode & Chr(01) & ">"




decWrite = _

"<DVAR2:12:01:" & decPrice & Chr(01) & ">"


However, i'm really new to all this and have no idea if i'm right with that.

Link to comment
Share on other sites


Yes, but those commands (as opposed to string setting) don't seem to need the "& Chr(01) "

(In script editor, just copy the "Set Decimal" command line into an editor or "Text type" screen) and you will see there is no "unusual" character near the end as opposed to "Set String"

Best, Randall

Link to comment
Share on other sites

Randall is correct (as usual) B)


Variants are variables not declared specifically as integers, bytes, strings, and so forth. It is left up to the parser to decide how to convert them to run a specific operation. Parsers have rules for this of course, which allows you to take, what is usually a number, and treat it like a string as in: "<IVAR2:11:01:" & intStockCode & Chr(01) & ">". If intStockCode were really a number, you would have had to convert it to string before doing this.


plugging them into a huge blob of html code

Could not have said it any better. Love it!

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.

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.

  • Create New...