Avarion Posted September 2, 2009 Report Share Posted September 2, 2009 Hi, i want to make a makro wich gets text from clipboard, reformates its content and append it to a file. I am not familiar with textprocessing in Macro Express. The clipboard text is in such a format: Personname (Department) Income: XXXX Entrydate: XX.XX.XXXX Sex: XXX Age: XX Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text- Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text- The file should appear like this: PersonName#Department#XXXX#XX.XX.XXXX#XXX#XX#Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text... The formatinglogic isnt so hard but i dont find the right commands in ME to manipulate strings. Any ideas? Quote Link to comment Share on other sites More sharing options...
Brain Virus Posted September 2, 2009 Report Share Posted September 2, 2009 Hi, i want to make a makro wich gets text from clipboard, reformates its content and append it to a file. I am not familiar with textprocessing in Macro Express. The clipboard text is in such a format: Personname (Department) Income: XXXX Entrydate: XX.XX.XXXX Sex: XXX Age: XX Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text- Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text- The file should appear like this: PersonName#Department#XXXX#XX.XX.XXXX#XXX#XX#Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text... The formatinglogic isnt so hard but i dont find the right commands in ME to manipulate strings. Any ideas? It kinda looks like you wanting all the spaces removed correct? What about in the sometext area? Quote Link to comment Share on other sites More sharing options...
Avarion Posted September 2, 2009 Author Report Share Posted September 2, 2009 in the sometextarea is a long description. But i dont want only the spaces removed but reformated it for an csv-file for databaseimport. Quote Link to comment Share on other sites More sharing options...
rberq Posted September 2, 2009 Report Share Posted September 2, 2009 Look at the Variable commands, especially: Variable Set Integer [Get Position of Text in Text Variable] Variable Modify String [append text, copy part of text, copy whole text, replace substring, save to text file, append to text file] With these commands and some imagination you can find the location of key characters or words in your text, extract pieces and use them to build an output string, append the # divider characters, and write the output string to a text file once you have built it. It helps a LOT if the incoming text is completely predictable -- for example, if Department is always bracketed by parentheses as you show it, if the words Income, Entrydate, Sex, Age are always there to use as delimiters for parsing, and so on. Quote Link to comment Share on other sites More sharing options...
stevecasper Posted September 2, 2009 Report Share Posted September 2, 2009 Hi, i want to make a makro wich gets text from clipboard, reformates its content and append it to a file. I am not familiar with textprocessing in Macro Express. The clipboard text is in such a format: Personname (Department) Income: XXXX Entrydate: XX.XX.XXXX Sex: XXX Age: XX Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text- Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text- The file should appear like this: PersonName#Department#XXXX#XX.XX.XXXX#XXX#XX#Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text-Some text... The formatinglogic isnt so hard but i dont find the right commands in ME to manipulate strings. Any ideas? There are a few different ways to do this. The way I'm going to show you is the longest, yet simplest, way. It's long because it treats each bit of information individually. There are more complex processes that you can use which result in a much shorter macro, but it is a bit more complicated logically. Since you're new to processing text, I felt it would be better to go with the simpler, if longer, approach. I used exactly your text from above to build this macro, however it should work fine if "Personname" is replaced by "Gary Strongmore" or if "(Department)" is replaced by "(Accounting)" - Note, however, it will not work without the parentheses. Because you put them in your text, I built the macro to rely upon them. If your clipboard text does NOT have those parentheses, you'll need to modify the logic, though I'm not in a position to instruct you in exactly what direction. Here it goes: <TVAR2:01:03:><REM2:Collect "Personname"><IVAR2:01:13:1:(><NMVAR:02:01:1:0000001:2:0000001><TMVAR2:10:02:01:001:N01:><TMVAR2:01:02:00:000:000:><TMVAR2:07:02:00:000:000:#><REM2:Collect "(Department)"><IVAR2:02:13:1:)><NMVAR:02:03:1:0000002:1:0000001><TMVAR2:10:03:01:N01:N03:><TMVAR2:21:03:00:000:000:(><TMVAR2:01:03:00:000:000:><TMVAR2:08:02:03:000:000:><TMVAR2:07:02:00:000:000:#><REM2:Collect income "xxxx"><IVAR2:01:13:1:Income:><NMVAR:01:01:1:0000001:2:0000007><IVAR2:02:13:1:Entrydate><NMVAR:02:03:1:0000002:1:0000001><TMVAR2:10:03:01:N01:N03:><TMVAR2:01:03:00:000:000:><TMVAR2:08:02:03:000:000:><TMVAR2:07:02:00:000:000:#><REM2:Collect entrydate "xx.xx.xxxx"><IVAR2:01:13:1:Entrydate:><NMVAR:01:01:1:0000001:2:0000010><IVAR2:02:13:1:Sex><NMVAR:02:03:1:0000002:1:0000001><TMVAR2:10:03:01:N01:N03:><TMVAR2:01:03:00:000:000:><TMVAR2:08:02:03:000:000:><TMVAR2:07:02:00:000:000:#><REM2:Collect sex: "xxx"><IVAR2:01:13:1:Sex:><NMVAR:01:01:1:0000001:2:0000004><IVAR2:02:13:1:Age><NMVAR:02:03:1:0000002:1:0000001><TMVAR2:10:03:01:N01:N03:><TMVAR2:01:03:00:000:000:><TMVAR2:08:02:03:000:000:><TMVAR2:07:02:00:000:000:#><REM2:Collect age "xx"><IVAR2:01:13:1:Age:><NMVAR:01:01:1:0000001:2:0000004><NMVAR:01:02:1:0000001:2:0000007><NMVAR:02:03:1:0000002:1:0000001><TMVAR2:10:03:01:N01:N03:><TMVAR2:01:03:00:000:000:><TMVAR2:08:02:03:000:000:><TMVAR2:07:02:00:000:000:#><REM2:Attach the "some text"><IVAR2:01:12:1><NMVAR:02:03:1:0000001:1:0000002><TMVAR2:10:03:01:N02:N03:><TMVAR2:01:03:00:000:000:><TMVAR2:08:02:03:000:000:><TBOX4:T:1:CenterCenter000278000200:000:T2%T2%> In the Script Editor it will look something like this: Variable Set String %T1% from Clipboard // Collect "Personname" Variable Set Integer %N1% from Position of Text in Variable %T1% Variable Modify Integer: %N1% = %N1% - 1 Variable Modify String: Copy Part of %T1% to %T2% Variable Modify String: Trim %T2% Variable Modify String: Append "#" to %T2% // Collect "(Department)" Variable Set Integer %N2% from Position of Text in Variable %T1% Variable Modify Integer: %N3% = %N2% - %N1% Variable Modify String: Copy Part of %T1% to %T3% Replace "(" with "" in %T3% Variable Modify String: Trim %T3% Variable Modify String: Append %T3% to %T2% Variable Modify String: Append "#" to %T2% // Collect income "xxxx" Variable Set Integer %N1% from Position of Text in Variable %T1% Variable Modify Integer: %N1% = %N1% + 7 Variable Set Integer %N2% from Position of Text in Variable %T1% Variable Modify Integer: %N3% = %N2% - %N1% Variable Modify String: Copy Part of %T1% to %T3% Variable Modify String: Trim %T3% Variable Modify String: Append %T3% to %T2% Variable Modify String: Append "#" to %T2% // Collect entrydate "xx.xx.xxxx" Variable Set Integer %N1% from Position of Text in Variable %T1% Variable Modify Integer: %N1% = %N1% + 10 Variable Set Integer %N2% from Position of Text in Variable %T1% Variable Modify Integer: %N3% = %N2% - %N1% Variable Modify String: Copy Part of %T1% to %T3% Variable Modify String: Trim %T3% Variable Modify String: Append %T3% to %T2% Variable Modify String: Append "#" to %T2% // Collect sex: "xxx" Variable Set Integer %N1% from Position of Text in Variable %T1% Variable Modify Integer: %N1% = %N1% + 4 Variable Set Integer %N2% from Position of Text in Variable %T1% Variable Modify Integer: %N3% = %N2% - %N1% Variable Modify String: Copy Part of %T1% to %T3% Variable Modify String: Trim %T3% Variable Modify String: Append %T3% to %T2% Variable Modify String: Append "#" to %T2% // Collect age "xx" Variable Set Integer %N1% from Position of Text in Variable %T1% Variable Modify Integer: %N1% = %N1% + 4 Variable Modify Integer: %N2% = %N1% + 7 Variable Modify Integer: %N3% = %N2% - %N1% Variable Modify String: Copy Part of %T1% to %T3% Variable Modify String: Trim %T3% Variable Modify String: Append %T3% to %T2% Variable Modify String: Append "#" to %T2% // Attach the "some text" Variable Set Integer %N1% from Length of Variable %T1% Variable Modify Integer: %N3% = %N1% - %N2% Variable Modify String: Copy Part of %T1% to %T3% Variable Modify String: Trim %T3% Variable Modify String: Append %T3% to %T2% Text Box Display: T2 Quote Link to comment Share on other sites More sharing options...
Avarion Posted September 2, 2009 Author Report Share Posted September 2, 2009 Thank you all. Now I have to understand how this script works then I'll go for modifying it. Quote Link to comment Share on other sites More sharing options...
stevecasper Posted September 2, 2009 Report Share Posted September 2, 2009 Thank you all. Now I have to understand how this script works then I'll go for modifying it. I'll help you figure it out, since I'm the one who just threw it in there without any explanations . Since I basically just did the same thing over and over and over, I'll just pick apart one section to help you see what I was doing, so you can modify it to suit your specific needs. // Collect income "xxxx" Variable Set Integer %N1% from Position of Text in Variable %T1% Variable Modify Integer: %N1% = %N1% + 7 Variable Set Integer %N2% from Position of Text in Variable %T1% Variable Modify Integer: %N3% = %N2% - %N1% Variable Modify String: Copy Part of %T1% to %T3% Variable Modify String: Trim %T3% Variable Modify String: Append %T3% to %T2% Variable Modify String: Append "#" to %T2% // Collect income "xxxx"Variable Set Integer %N1% from Position of Text in Variable %T1% - This sets the value of N1 to the position of "Income:" in the variable T1 (saved from the clipboard). If you started at the P in "Personname" and counted how many characters and spaces before reaching the I in "Income:" you would get the same value. Variable Modify Integer: %N1% = %N1% + 7 - This counts forward from N1 (the position of I in Income) 7 spaces (because Income: is 7 characters long - including the colon). It sets N1 as this new value. Now, N1 = the position of the space immediately following "Income:" Variable Set Integer %N2% from Position of Text in Variable %T1% - This sets N2 with the value of the position of the A in "Age:". This is useful to help define the location to the right hand side of the XXXX of "Income". Variable Modify Integer: %N3% = %N2% - %N1% - This command takes the difference between N2's value and N1's value, and assigns that value to N3. Example: If N1 = 5 and N2 = 12, then N3 = 7. This will be important for the next step. Variable Modify String: Copy Part of %T1% to %T3% - Here we take T1 (the entire clipboard contents) and we start at the position N1 (the location of the space immediately following "Income:") and we copy N3 characters over. So, if N1=5 and N2=12, then we will be copying 7 characters over from the space after "Income:". Now those 7 characters get saved to variable T3. Variable Modify String: Trim %T3% - The Trim commands remove spaces from a text variable. So if T3 looks like this: " 9453 ", the trim command will make it look like this: "9453" (without the quotes, of course). Variable Modify String: Append %T3% to %T2% - This will add T3 to the end of T2 (which I established earlier in the macro - T1 contains the clipboard contents, and T2 receives the modified text). I use "append" rather than "save" because I want to add information, not replace it. Variable Modify String: Append "#" to %T2% - Because your example used the pound sign "#" as your separator character between each bit of information, I did the same thing. Appending # to the end of T2 after each modification will keep the macro in line with what you are trying to do. I hope this helps you out! Quote Link to comment Share on other sites More sharing options...
Avarion Posted September 2, 2009 Author Report Share Posted September 2, 2009 Yes it helps. Thank you very much. Quote Link to comment Share on other sites More sharing options...
Avarion Posted September 2, 2009 Author Report Share Posted September 2, 2009 Oh, one more question. The sometext contains linebreaks. How can i remove em? I think mit replace text in variable but how can i search for a cr/nl? Quote Link to comment Share on other sites More sharing options...
rberq Posted September 2, 2009 Report Share Posted September 2, 2009 Oh, one more question. The sometext contains linebreaks. How can i remove em? I think mit replace text in variable but how can i search for a cr/nl? Normal line breaks are carriage-return-line-feed, or x'0D0A' (decimal '1310'). So if your text is in T1, I think this will do it: // .... set up CR-LF in T98 Variable Set %T98% to ASCII Char of 13 Variable Set %T99% to ASCII Char of 10 Variable Modify String: Append %T99% to %T98% Replace "%T98%" with " " in %T1% [all instances] Quote Link to comment Share on other sites More sharing options...
stevecasper Posted September 3, 2009 Report Share Posted September 3, 2009 Normal line breaks are carriage-return-line-feed, or x'0D0A' (decimal '1310'). So if your text is in T1, I think this will do it: // .... set up CR-LF in T98 Variable Set %T98% to ASCII Char of 13 Variable Set %T99% to ASCII Char of 10 Variable Modify String: Append %T99% to %T98% Replace "%T98%" with " " in %T1% [all instances] I second that. Of course, the macro I built above removes them automatically (unless you want them removed from the "some text" section). Quote Link to comment Share on other sites More sharing options...
Avarion Posted September 3, 2009 Author Report Share Posted September 3, 2009 Thank you all. Its working. Now some finetuning for the different datasources and the database will be ready in notime 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.