NeVeR Posted July 4, 2022 Report Share Posted July 4, 2022 Hi, I have ME - not the pro-version. just the normal one I have a list of 200 lines in a text file I want the macro to select one of these lines at random each times it's ran and store the selected lines text in T1 How can I do this? Thank. Quote Link to comment Share on other sites More sharing options...
Cory Posted July 4, 2022 Report Share Posted July 4, 2022 It's been a while since I worked in the old MEP, so I might get some things wrong. I would first use Text File Process and count the number of lines and store in an integer variable. Then create an integer variable using Set Random Variable, or whatever it's called in ME. Then use text file process command and use the "Start at" with your random number and set the "Number of Records" to 1. Quote Link to comment Share on other sites More sharing options...
acantor Posted July 4, 2022 Report Share Posted July 4, 2022 Cory's solution sounds very workable. If you know the exact number of lines the text file contains, something like this might work well enough. But Cory's solution is better. Variable Set Integer %RandomValue% to a random value between 1 and 200 Variable Modify Integer: %RandomValue% = %RandomValue% - 1 Text Type (Simulate Keystrokes): <CONTROL><HOME> // Go to top of text file Repeat with Variable: Repeat %RandomValue% times // Go down %RandomValue% lines Text Type (Simulate Keystrokes): <ARROW DOWN> End Repeat Text Type (Simulate Keystrokes): <HOME><SHIFT><END> // Select the entire line Clipboard Copy Variable Set String %T1% from the clipboard contents Text Type (Simulate Keystrokes): <HOME> // Deselect to start of line Quote Link to comment Share on other sites More sharing options...
Cory Posted July 4, 2022 Report Share Posted July 4, 2022 There's another trick one can do to count. Read the entire file in and get the number of characters. Then replace the carriage return or line feed with nothing. Subtract the second length, and that's the number of lines. Quote Link to comment Share on other sites More sharing options...
Bruce Thomson Posted July 4, 2022 Report Share Posted July 4, 2022 In the list of commands at the left in the editing pane I noticed a Variable set Decimal - Set to a Random Value Also there, I see 'Repeat' functions, including 'Repeat until', which could be used to increase a variable to the random value. It seems likely therefore you could set a random variable, and do a Repeat Until loop until that variable is exhausted. 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.