Jump to content
Macro Express Forums

How do I capture text parts into an array?


Recommended Posts

Hi All.

I'm trying to learn to use arrays--which I've never done. 

 

My experimental setup is as follows:  I have a file on my Desktop called 4MacExp.txt.  It contains four lines.  

foo
bar
bip
wam

 

I have a Text Variable called ProcessedFile that is an array variable with 10 parts.  

 

My (not working) code is as follows:  
 

<TEXT FILE BEGIN PROCESS Filename="C:\\Users\\SWKunkel\\Desktop\\4MacExp.txt" Start_Record="1" Process_All="TRUE" Records="1" Variable="%ProcessedFile%"/>
<TEXT FILE END PROCESS/>
<TEXT BOX DISPLAY Title="Variable results" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 ProcessedFile[1]\r\n\\par ProcessedFile[\\f1 2\\f0 ]\r\n\\par ProcessedFile[\\f1 3\\f0 ]\r\n\\par ProcessedFile[\\f1 4\\f0 ]\r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>


My textbox at the end has

ProcessedFile[1]
ProcessedFile[2]
ProcessedFile[3]
ProcessedFile[4]

 

It seems like the processed parts of the text file should get saved into the first four components of the array, then get displayed in the textbox like

foo
bar
bip
wam

 

It doesn't work though.  I get an error:  

Undefined variable or the variable is the wrong type
"%ProcessedFile%"
Macro Name: ReadWriteIni
Line Number: 1

 

I also tried ProcessedFile[] but that didn't work either.

 

Ideas?  

 

Link to comment
Share on other sites

Text File Process places the entire line into a single variable.  
When Text File Process reads the first record of your file, "foo" will be placed in ProcessedFile[1].
When Text File Process reads the second record of your file, "bar" will be placed in ProcessedFile[1].
When Text File Process reads the third record of your file, "bip" will be placed in ProcessedFile[1].
When Text File Process reads the fourth record of your file, "wam" will be placed in ProcessedFile[1].
Nothing will ever be placed in ProcessedFile [2], [3], or [4].  

 

If your text file was only a single line,
AND that single line contained foo,bar,bip,wam
AND you used ASCII File Begin instead of Text File Begin,

AND you specified the file as ASCII Delimited Text,
then I think the variables would be distributed into [1], [2]. [3]. and [4] as you wish.  

 

Link to comment
Share on other sites

The alternative is to leave your file as is, continue to read it with Text File Process, but put some code after Text File Begin (and before Text File End) to keep count of which record is being handed to the macro and move to [1], [2], [3] and so on as appropriate. 

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