Jump to content
Macro Express Forums

Simple Help


m204prgmr
 Share

Recommended Posts

Good Morning,

I have 90+ text files that I need to be edited by finding the text KEY and replace it with ORD CHAR. I'm using ASCII file processing. I can find the work KEY and I can replace it with ORD CHAR, %T% will show this to me 3 times in my text display. I am having trouble saving my work and don't know what is missing. Below is a sample of the ME code and below that is a sample text file I am using.

 

<ADFBEG:F11:001:000001:000000:c:\ACTASSMEtestfile.txt><TVAR2:05:01:KEY><TVAR2:08:01:ORD CHAR><IFVAR2:1:01:8:?&ACTASS ><IFVAR2:1:01:8:NKEY><IFVAR2:4:01:7:T5T><TMVAR2:21:01:00:000:000:KEY%T8%><ENDIF><TBOX4:T:1:CenterCenter000278000200:000:The new line changed%T1%><ENDIF><ENDIF><ADFEND><LAUNCHDEL2:0:01c:\ACTASSMEtestfile.txt>

 

 

IN FILE ?&ACTASS DEFINE FIELD 'FISCAL YEAR' -

( NFRV NKEY NCOD STR NNR VIS UP NORD )

IN FILE ?&ACTASS DEFINE FIELD 'INOUT CODE' -

( DEF NFRV KEY NCOD STR NNR VIS UP NORD )

IN FILE ?&ACTASS DEFINE FIELD 'IP NUMBER' -

( DEF NFRV KEY NCOD STR NNR VIS UP NORD )

IN FILE ?&ACTASS DEFINE FIELD 'IPD MNEMONIC' -

( NFRV NKEY NCOD STR NNR VIS UP NORD )

IN FILE ?&ACTASS DEFINE FIELD 'IPD NUMBER' -

( DEF NFRV KEY NCOD STR NNR VIS UP NORD )

IN FILE ?&ACTASS DEFINE FIELD 'LAST CASE CHANGE DATE' -

( NFRV NKEY NCOD STR NNR VIS UP NORD )

 

 

Any help would be appreciated..thanks

"We will intuitivly know how to handle things which use to baffle us.." ...LOL this one is driving me nuts..

Link to comment
Share on other sites

Bob -

 

The solution is to append the current T1 string (changed or not) to a "save to" string after each pass through the loop and then overwrite the file with the "save to" string:

// Create a CR/LF string
Variable Set %T1% to ASCII Char of 010
Variable Set %T13% to ASCII Char of 013
Replace "%T13%" with "%T13%%T1%" in %T13%

// Create a "save to" string
Variable Set String %T10% ""

// Set search and replace variables
Variable Set String %T5% "KEY"
Variable Set String %T8% "ORD CHAR"

// Process the text file
ASCII File Begin Process: "ACTASSMEtestfile.txt" (Tab Delimited Text )
 If Variable %T1% does not contain "?&ACTASS "
   AND
 If Variable %T1% does not contain "NKEY"
   AND
 If Variable %T1% contains variable %T5%
   Replace "KEY" with "%T8%" in %T1%
   Text Box Display: The new line changed
 End If
 
 // Append current T1 string and the CR/LF string to saved string (T10)
 Variable Modify String: Append %T1% to %T10%
 Variable Modify String: Append %T13% to %T10%
 
ASCII File End Process

// Overwrite the text file
Variable Modify String: Save %T10% to Text File



<REM2:><REM2:Create a CR/LF string><ASCIIC:1:1:010><ASCIIC:13:1:013><TMVAR2:21:13:00:000:000:%T13%%T13%%T1%><REM2:><REM2:Create a "save to" string><TVAR2:10:01:><REM2:><REM2:Set search and replace variables><TVAR2:05:01:KEY><TVAR2:08:01:ORD CHAR><REM2:><REM2:Process the text file><ADFBEG:F11:001:000001:000000:c:\temp\ACTASSMEtestfile.txt><IFVAR2:1:01:8:?&ACTASS ><AND><IFVAR2:1:01:8:NKEY><AND><IFVAR2:4:01:7:T5T><TMVAR2:21:01:00:000:000:KEY%T8%><TBOX4:T:1:CenterCenter000278000200:000:The new line changed%T1%><ENDIF><REM2:><REM2:Append current T1 string and the CR/LF string to saved string (T10)><TMVAR2:08:10:01:000:000:><TMVAR2:08:10:13:000:000:><REM2:><ADFEND><REM2:><REM2:Overwrite the text file><TMVAR2:17:10:00:000:000:c:\temp\ACTASSMEtestfile.txtF><REM2:>

Link to comment
Share on other sites

Floyd,

You're the best, thank you.

Question, you used AND between the IF statements.

Is it necessary? Or does it remove any non forseen problems. I just assumed (from Model 204 programming logic) that one IF followed by another is saying that the second condition will never be engaged unless the first IF statement is satisfied.

Thanks again.

Link to comment
Share on other sites

Bob -

 

You're the best, thank you

Appreciate the compliment, but I am not ... and neither is Joe B). Kevin at Insight is the best. I have never asked him a question that he could not answer.

 

Either way is good. With your nested IFs you are really saying "IF this is OK and IF this is OK and IF this is OK, then do the task." But you have used 3 IF/END IF constructs to do it. Using logical ANDs within a single construct results in the same logic. There is no good or bad way to construct logic ... the best way,however, is your own way.

 

I also placed the:

 

Variable Set String %T5% "KEY"

Variable Set String %T8% "ORD CHAR"

 

outside the loop. There is no sense in redefining them each time through the loop.

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

×
×
  • Create New...