Jump to content
Macro Express Forums

How Can Me Read From A Text File And Save.


jay185

Recommended Posts

I have a text file that have variables in it. lets say, an html table w/ variables in each table all set to 0.

 

My problem is, how do I load that text file and save as a different name text file w/ values saved in variable in it?

 

lets say main.txt contains:

 

<html><body>

Box 1 contains %T99%

</body></html>

 

then ME will read the file main.txt and replace the value of %T99% to whatever I set it to (e.g. 100), then it will output a file naming mainb.txt then it shoud contain

 

<html><body>

Box 1 contains 100

</body></html>

 

........

 

 

is this possible? if so, please help me...

Link to comment
Share on other sites

Try setting the 'Variables Evaluation Level' to 1 or larger. If you are using Macro Express v 3.7 or later you can set this by clicking Options, Preferences, Miscellaneous and then the Advanced button. For v 3.6 and prior, download TweakME3.mxe from the More Macro Express Downloads page and run it to change the 'Variables Evaluation Level'.

 

These topics seem similar to what you are asking and may help: Text Typing An Expression and Step Thru An Array

Link to comment
Share on other sites

I actually can't make this to work...

 

here's my sample.

 

My code looks like this.

 

Variable Set Integer %N1% from Prompt

Variable Set Decimal %D1% from Prompt

Variable Modify Decimal: Convert %D1% to text string %T1%

Variable Modify String: Save %T1% to Environment Variable

Text File Begin Process: "3pm.txt"

  Variable Modify String: Append %T99% to Text File

Text File End Process

 

actual script

 

<IVAR2:01:02:FWhat Time?TFCenter:Center><DVAR2:01:02:FAA DailyTFCenter:Center><DMVAR:05:01:1:000000000000001.0000:1:000000000000002.0000><TMVAR2:19:01:00:000:000:%N1%AAD><BTFBEG:099:000001:000000:C:\Documents and Settings\Administrator\Desktop\3pm.txt><TMVAR2:20:99:00:000:000:C:\Documents and Settings\Administrator\Desktop\3.htmF><BTFEND>

 

on the text file is an html code... where as it shows

3pm  %3AAD%

 

4pm  %4AAD%

 

5pm  %5AAD%

thanks a lot

Link to comment
Share on other sites

I have found a solution for my problem, this is to open up the file itself from notepad, copy the whole file, transfer it to a variable, open a new notepad, then type in by using the variable i used to transfer my previous file. hehehehehe am starting to go crazy

Link to comment
Share on other sites

I have found a solution for my problem, this is to open up the file itself from notepad, copy the whole file, transfer it to a variable, open a new notepad, then type in by using the variable i used to transfer my previous file. hehehehehe am starting to go crazy

Actually, you can initialize a Text variable by the "Set from file" command in the Variable catalog, you do not need to open the file by Notepad.exe but just get whatever in the file backgroud, this will make your macro more robust. Hope this advice would be help. :D

Link to comment
Share on other sites

As the last person said, do a "Variable set string - such value from file" to load the entire file into a text variable. Just in case it isn't obvious on what to do once you have the file and a text variable, here are some more thoughts, based on how I frequently accomplish the same objective:

 

- in my original "template" text file, I put in place holders for the text or numbers I want to insert. And I give these placeholders unique names to ensure that they don't accidentally coincide with actual text in my file. For example, I will use the phrase replaceMDNhere for the location where I need to put the MDN value.

 

- once I load the text file into the variable, I do a search and replace on all occurrences of my placeholder in the text variable, such that the placeholder is replaced with whatever text or numbers I want to use. Replacements are done with the variable modify string - replace substring, where the replacement text can be a text variable, a number variable, or a fixed value.

 

- if I have different placeholder strings in a single file, I repeat the replacement process for each placeholder. (On each replacement, I make sure that macro express is set to replace all occurrences.)

 

- then write the text string back to a text file.

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