Jump to content
Macro Express Forums

Embedding a file in macro


Cory

Recommended Posts

Is there a way to embed a file contents into ME easily? I’m developing a macro that relies on a couple of INI files with 50 or so entries each. For deployment to several sites it might be easier if I could have the contents of this file embedded in the macro. Something like T1=abunchoftext so that I could take T1 and write it to a file. But of course I can’t paste this in to a Set Text Variable since it has CRLF’s. My tack now is ot set a var for CRLF and paste that in to the set var command using the var. But that’s not very elegant. I could create the INI file and write code to create each entry in a sense building the INI from scratch but that seems laborious as well. Maybe I couldbypass the limitation of the input dialog box by using the direct editor. Is there an easier way to get a chunk of data into ME so that I could use it to create a file later?

Link to comment
Share on other sites

My tack now is ot set a var for CRLF and paste that in to the set var command using the var.
You are on the right track. Joe did this with some of his macros. I remember discussing this issue with him some time ago.

 

If it were me I would just create the INI files from a macro. The macro would test for the existence of the .ini file and, if not found, create it with default values. This technique requires two macro commands for each entry in your INI file. Something like this:

Variable Set String %T1% "Some Value"
Variable Modify String: Save %T1% to INI File

But, once written, it is easily understood and maintainable.

 

If you use the first technique, your macro will look more elegant but it is cumbersome to change and it may not be easily understood by others. Of course, that may be one of your goals. :D

 

The first technique could be accomplished with only six macro commands (plus comments):

// Set T13 to CRLF
Variable Set %T13% to ASCII Char of 13
Variable Set %T10% to ASCII Char of 10
Variable Set String %T13% "%T13%%T10%"

Variable Set String %T1% "A Bunch Of Stuff Representing an INI file"
Replace "##BLUE_CRLF##" with "%T13%" in %T1%
Variable Modify String: Save %T1% to INI File

Link to comment
Share on other sites

Embedded text in a macro is easy. And it lends itself to a zero footprint model. In other words, you need nothing more than the macro to do whatever it is that the macro does. A good example of this is the Multiple Field Input example macro.

 

The generated HTA code is contained in string variable(s). You can see where CR/LF sequences are stored as "PGMCRLF" and replaced with real CR/LF strings when required in the manner that Kevin has shown.

 

If I want to edit the HTA string, I simply copy it to my text editor, replace all "PGMCRLF" with actual CR/LF, and then hack away. When finished, I do the opposite.

Link to comment
Share on other sites

That HTA thing ticks me off! I dorked and dorked with that and could never get one of my own to work and I REALLY would like a multi-field input capability. I finally had to give up due to time constraints and sanity levels. Maybe if Joe is interested in helping me I should take another crack at it. Now where was I?

 

Oh yeah… The HTA is exactly the kind of thing I was thinking of in terms of storing a file. Mainly I wanted to check to see that I wasn’t missing something. Generally I think the CRLF is the best way to approach the problem especially since most of my macros start with my CRLF/TAB subroutine as I use them constantly. But in the case of an INI file I like the idea building it because it would then be easier to tweak later.

 

I feel a feature request coming on… Embed File command.

Link to comment
Share on other sites

I took a drag off my cup-o-joe and decided to have another look at your HTA this morning because I really would like to have this capability. I retraced my steps and found where I went afoul last time. Even though HTA is basically an HTML file associated with a different application your example is not a simple HTML form, it’s all VBScript. I am not a VB programmer so this is beyond my scope. I can follow it a little but it’s been decades since I’ve done any real programming and I know if I ever tried to fake it to make my own version I’d make some syntactical error someplace and would be stuck until I learned to program VBScript. One of these days I’ll lean VBScript and VB but for the moment it’s the deep end of the pool for me.

Link to comment
Share on other sites

Creating a simple, but dynamic, multiple field input form based on parameters supplied by Macro Express (maybe in the format of an INI file) would not be all that difficult to do. It really depends on the end-game, or what you want to prevent the user from inputting.

 

If it's just a basic form, you need variables for:

  • Width and height of the form (assume a center position on the display)
  • How many text input fields it contains
  • the X and Y coordinates of each each one for placement
  • The label and label position for each field (assume either left of, or above each field)
  • The minimum and maximum number of characters for each field
  • ... and so forth.

Placing all of this information in an INI file is easy to do for Macro Express, as is generating the script on the fly that presents the form to the user. It's easier than it sounds. In fact, an INI file might be overkill. On the other hand, they are easy to maintain.

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