Jump to content
Macro Express Forums

Recommended Posts

When processing a CSV file and saving the columns into the %T% array, I'd like to be able to do something different every time %T[1]% changes. For instance, I have a CSV file with two columns and I want to process the file and refer to the previous line and save that value off to a variable as I'm processing it so I can refer to it later. Seems like such a simple thing to do, but nothing I've tried yet has worked. Any ideas?

 

ABC,123

ABC,324

ABC,567

DEF,345

DEF,786

Link to comment
Share on other sites

I would find it be helpful to see the code you've tried, and to look at some of the actual data.

 

When you say, "I'd like to be able to do something different every time %T[1]% changes", I think you're saying you want to compare the value of %T[1]% against the value obtained the last time you triggered the macro. If that's the case, make sure your macro begins with "Variable Restore" and ends with "Variable Save."

Link to comment
Share on other sites

Thanks. Here's a snippet of my code.
 

ASCII File Begin Process: "C:\Temp\Stock.csv" (Comma Delimited Text (.csv))
  If Variable %T[1]% Does not Equal "%T[99]%"
    Text Type (Use Clipboard and Paste Text): %T[1]% // Inventory

  End If
  Text Type (Use Clipboard and Paste Text): %T[2]% // Stock#
  Variable Set String %T[99]% to "%T[1]%" // Save Inventory
ASCII File End Process
 

Link to comment
Share on other sites

When each record of the CSV file is accessed, I think that ALL elements of array T are cleared, then populated with values from the current record. 

Your macro saves inventory in T[99], but that will be cleared to null when processing of the next record begins because it is part of the same array. 

Therefore command "If Variable %T[1]% Does not Equal "%T[99]%"" will ALWAYS find T[1] unequal to T[99]. 

Try defining a new text variable in which you save inventory, and change the "If Variable" command to use that as well.  Any single non-array variable should work -- call it TSAVE or something else meaningful. 

 

I'm not sure of the above, but it's easy for you to test. 

Link to comment
Share on other sites

rberg is right. You should name your variables somehting meaningful. Make an array named "Cells", "Values", or something. And whatever is in 99 should also have a meaningful name. The default T values are a holdover from the old ME when we didn't have the ability to name. The first thing I do when I start a macro is to go in and delete all 4 of the baked-in values. 

I can't tell for sure, but you might have intended the second TextType to be in an "else" of the condition above. 

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