Jump to content
Macro Express Forums

Selecting Text to a Variable

Recommended Posts

I'm guessing you have it on the clipboard already.


There are many ways to accomplish this but this one is conceptually easier.

  1. Set a string variable %text% to the clipboard's contents.
  2. Set an integer variable %pos% to the position of the semi-colon in %text%.
  3. Modify string to delete part of the text in %text% from 1 to %pos%.
  4. Set %pos% to the position of the comma.
  5. Modify string to copy part of %text% from 1 to %pos% to %text%.

That's all there is to it. 5 might be slightly confusing. Note that I'm avoiding the creation of a second string variable. IE I'm copying part of %text% to %text% effectively overwriting the original version of the variable. If you like you could copy part of it to %text2% if it's easier to follow.

Link to comment
Share on other sites

Thanks for the quick response!


I can have it on the clipboard... At this point I do not. Is one way easier than the other. I mean if I don't have it on the clipboard already, is there a different or more easy way to do it? It doesn't matter, to me, either way...on the clipboard or not; just whichever you think is the best way to go.

Link to comment
Share on other sites

If this is a process that you need to repeat many times, and speed is an issue, a better way is to to copy the contents of the clipboard to a variable, and perform the manipulations there rather than on the clipboard. Although doing the calculations in "variablespace" requires another step or two, macros run faster that way.

Link to comment
Share on other sites

Heather you did not indicate where the text is to begin with so I can make no suggestion as to evaluation. EG if ti's in a text file saved to disk I would set the variable directly to it's contents. But if it was the last line of a log file I'd use a different method.


Given your other posts I get a feel for what you're trying to do. And often it seems that you're trying to use other applications as a sort of variable space. IE a place to hold data that you're making decisions on or driving processes from. If this is the case you would be much better off learning to suck this data into variables, including arrays, and run from there. I've tried to explain this to you guys before but it has always fallen on deaf ears probably because it doesn't meet Bob's expectation of how it should work. But this tactic causes all kinds of problems with timing, performance, and other issues that are making life more difficult for you.

Link to comment
Share on other sites

Alan this is a process that we will need to repeat many times. We are looking to do exactly that, process the data in "variablespace." We have specific occurrences of symbols etc. but varying lengths of text.


Our text file uses the "§" (section symbol) in a lot of cases to separate the text. I would like to be able to go to a location based on a § or a combination of § § § and pull the data between and trim the spaces from the front and back. In some cases I will want to find everything between a "," (comma) and a "§" (section symbol) and copy that to its own variable.

Link to comment
Share on other sites

Heather you should bring the entire file into a variable and process it from there. Or repeat line by line thru the file. I don't know what format you have so I don't know which to recommend. You can use those special charactors to extract the data you need. If you like post some samples and I'd be happy to give you some examples.


As an aside I want to mention RegEx. Ever since there was computers and data programmers have struggled with exactly the same tasks you are faced with. So they created an 'engine' with a uniform syntax to crunch text data like this. RegEx is not a computer programming language but a whole adjunct. Every computer language I know utilizes it. As of now MEP has no facility for RegEx. It's a very intimidating at first but depending on how much crunching you are doing it can be very powerful and fast. Also the expressions that capture data are very flexible and you can do all kinds of things. If you are interested I could write some programs or VBScripts for you to use. I've been thinking that one day I would create a couple of simple VBScript where the user could provide the expression and the text to be evaluated and the script or program would return the text for some common tasks. I used to do a lot of text crunching in MEP for my scrapers but now I write all my scrapers in VB.NET and life is sooooo much easier. Also if you would like contact me offline and we could set up a phone call and I could explain more.

Link to comment
Share on other sites


Once again Thank you for the help. I believe we have your email address so I will shoot you an email personally. I checked out the RegEx like you suggested and it really seems like that just might be the way to go for what we are doing. We are trying to pull the data out of a text file that we have. This text file used to run the navigation for our website. We are completely updating our site so we would like to extract the work we have done in this prior format, into a data file that we can use to create and update our new navigation much easier.


Due to our work we always have some kind of data processsing, parsing, extracting, etc that we are trying to do. We appreciate all the help you do offer.


We took a look at the programs that JustGreat Software offers. What would you recommend we look at first? They have RegexMagic, RegexBuddy and PowerGREP. Obviously they are different levels but we wanted your opinion.


Thanks once again for all your help.



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.

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.


  • Create New...