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

  • 5 months later...

Thanks guys. Your replies have been very helpful and I've learned a lot since I originally posted this 6 months ago. I wish I could post a picture of what this screen looks like so you could understand the screen control. Imagine a screen where you have a prompt for Inventory that you would type a code such as MAIN and then press <Enter>. Then you'd type the Stock number such as 123456 and then press <Enter>. You'd then be able to type in several fields such as Description, Department, Quantity, etc and then when you file that entry, the prompt returns you back to the Stock Number prompt again where you can start entering the next number...or you can simply press <Enter> again and the screen control will take your cursor back up the Inventory field where you can enter the next inventory code.

 

Here's a revised version of my code. Let me know if you have any other thoughts on how to do this correctly because it isn't working. I'm open to other ideas as well.

 

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

    Text Type (Simulate Keystrokes): <ENTER>

  End If
  Text Type (Use Clipboard and Paste Text): %T[2]% // Stock#

  Text Type (Simulate Keystrokes): <ENTER>

   ((( Enter all the other fields )))

  Text Type (Simulate Keystrokes): <F12><ENTER> // File

  Variable Set String %INV% to "%T[1]%" // Save Inventory
ASCII File End Process

Link to comment
Share on other sites

It's hard to offer advice when you don't say WHAT is not working.  Perhaps you could take a screen shot of your entry screen, and upload it to this forum thread.  Here are a couple shot-in-the-dark suggestions.  

 

1. Initially, try using the (Simulate Keystrokes) method for all your Text Type commands.  Pasting from clipboard usually works, but not always.  Once you have the Text Type working with simulated keystrokes, you can go back and test the paste option to speed things up.

 

2. Your typing commands will zip along very fast, regardless whether or not the application is ready to receive the next type-in.  Try putting a delay after each <ENTER>, if the application needs time to position to the next input field.  Even better, for testing, put a Wait for Key Press command after each <ENTER>, so the macro won't proceed until you can see with your own eyes that it is time for the next field to be typed.

Link to comment
Share on other sites

It sounds like you're entering this into a form. Maybe a Db. One form per row. Looks like F12 saves the record. Is this like what you are using?

 

First off I'd use controls if you can. If it's a web page you can't. Elminates all the problems with text typing and clipboard. About 100 times faster and much less prone to errors. No timing needed. 

 

I second what rberq said about clipboard and timing. 

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