jsampsonyyyyy Posted December 15, 2021 Report Share Posted December 15, 2021 How do I define an array variable for use in "Text File Begin Process"? I get an error message "Undefined variable"...etc. I do not want to give the array any content when defining it as that should be read from the text file. Quote Link to comment Share on other sites More sharing options...
rberq Posted December 15, 2021 Report Share Posted December 15, 2021 When you are editing the macro, click on the Variables tab, and at lower left there are options to add/delete/change variables. The Macro Express Help example for Text File Process shows an array variable, which is confusing, because it does not HAVE to be an array variable. It does not much matter whether you give it any content when you define it, because it will be overlaid with file data when the process runs. If you want the fields within each record to be placed in an array, look at ASCII File Process instead of Text File Process. Quote Link to comment Share on other sites More sharing options...
jsampsonyyyyy Posted December 15, 2021 Author Report Share Posted December 15, 2021 If I open the Variables tab and "add" the variable there is an error "A variable with this name already exists". But if I run the macro there is an error "Undefined variable or the variable is the wrong type". As the variable exists (?) it must be the wrong type. If it should not be a string variable (for an array of strings) what type should it be? Or does it matter in what order I write the macro? In Basic or Python one can edit code freely before running it. Perhaps this is not so in Macro Express Pro. Quote Link to comment Share on other sites More sharing options...
acantor Posted December 15, 2021 Report Share Posted December 15, 2021 Although fixing the variable problem is do-able, my suggestion is to start the macro again from scratch. Now that you have a better sense of the "order of operations," recreating the script will likely be faster. Quote Link to comment Share on other sites More sharing options...
rberq Posted December 15, 2021 Report Share Posted December 15, 2021 It's a personal preference, but I use the ME option that does NOT automatically define variables. If you set that ME option, you should be able to delete the current variable, and then when you try to save the macro, it will prompt you through defining the variable. For Text File Process, it should be a Text variable. If you currently have a text array, possibly ME objects to that and wants a single text variable -- not sure, I haven't tried that. Quote Link to comment Share on other sites More sharing options...
jsampsonyyyyy Posted December 16, 2021 Author Report Share Posted December 16, 2021 I have written a test macro which I attach here. The file being worked on is a simple text file of short lines and the intention is to display each line in a message box. However, at "Text File Begin Process" the above-mentioned error message occurs, "Undefined variable or the variable is the wrong type". This is despite "images" being set as a string variable of an array type. If there is an order in which I should set the macro up, what is it? If I need to edit it for debugging, how do I do that, or do I have to rewrite the macro from scratch for every bug? Does the error have something to do with the arrangement of percentage signs on the variable name? testFileProcess.mex Quote Link to comment Share on other sites More sharing options...
rberq Posted December 16, 2021 Report Share Posted December 16, 2021 3 hours ago, jsampsonyyyyy said: This is despite "images" being set as a string variable of an array type. "images" should not be an array type. This macro (below) runs properly if %testvar% is defined as a text variable, not as an array. If %testvar% is defined as a text array, I get the same error you describe. Text File Begin Process: C:\Temp\windowlist.txt (specifies "testvar" to receive lines from the file) Text Type (Simulate Keystrokes): %testvar% Text File End Process Macro Return In the macro editor, select the Variables tab, select Properties for your variable, and un-check the "Create as array" box. See attached screen shot. Quote Link to comment Share on other sites More sharing options...
jsampsonyyyyy Posted December 16, 2021 Author Report Share Posted December 16, 2021 Many thanks. I was not thinking straight. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.