Extract variables, sequence of keystrokes, and extract variables again

Hello, I come to you after thinking a lot about how to do this but with little knowledge. Please help.

I extract text from some files:

CC 8128361
COTIZANTE
8128361 CONTROL DE PLACA: Z012/VALOR:0/997002
8128361 CONTROLADO: Z012/VALOR:0/36107
8128361 EDU DETARTRAJE: Z012/VALOR:0/36302 990203
8128361 RIAS: Z012/MODERADORA:4500/36101
8128361 TERA: Z012/VALOR:0/36903

It's formatted with the data I need, for example from the file 8128361 PLATE CONTROL three variables are extracted: Z012, 0, and 997002, and so on.

The idea is to automate filling out a webpage with this data and make it repetitive. We have 5 lines, so the sequence would be to save "CONTRIBUTOR" in a variable that works for all of them, then extract the variables from the first line, execute the keystroke sequence, then add a pause before continuing with the next line. Extract the next line, execute the keystrokes, pause. Continue like this until there are no more lines.

Is your rule for a variable the following? The characters after the first : and before the first / (Z012 in your example), the character after "VALOR:" and before the next slash (0), and the characters immediately after that slash (997002)?

If so, then ...

Is the last variable 36302 990203? Or is that two variables?

-rob.

Yes. You right.

When two different numbers are presented, the keystroke sequence would be to write the first number 36302, wait 0.5 sec, press enter, write the second number 990203 and press enter.

Now that I think about it, I wouldn't know how to do that, I suppose by adding the enter function to the variable, but I wouldn't know how to implement the wait.

Thank you for your response

Can the macro ignore the first two lines, or are they important somehow?

-rob.

First line can be ignored, the second line is constant, is used on sequence of keystrokes but is the same for the rest of the lines.

Also, what is the "keystroke sequence?" Are you entering one of the variables then Tabbing to another field? Or are you combining the three variables into one string then pasting that and moving to the next line?

The more detail you can provide on the process, the better the answers you'll get here. Here's a demo that uses Excel, splits out the vars and enters them in separate cells, and has a pause when there's a two-number sequence in the final var spot:

An animated GIF hides within

excel_demo

Data extraction and pasting.kmmacros (29 KB)

As written, the macro works in Excel, but you could change it to TextEdit, and I think it'd still work. The macro uses regular expressions to split apart the variables, and then has a special case for when the last variable has a space within it.

I have no idea if this is what you wanted, as we don't have all the details on your project, but hopefully it gets you started.

-rob.

1 Like

Sorry, is just too longest, I'll add all here. Right now I just do variables manually:

Type the Tab Keystroke
Pause for 0.2 Seconds
Type the P Keystroke
Pause for 0.2 Seconds
Type the B Keystroke
Pause for 0.2 Seconds
Type the S Keystroke
Pause for 0.2 Seconds
Type the Return Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Insert Text “FIRST VARIABLE” by Pasting (ON THIS CASE Z012)
Pause for 0.2 Seconds
Type the Return Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Insert Text “NINGUNA” by Pasting
Pause for 0.2 Seconds
Type the Return Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Return Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Insert Text “NINGUNO” by Pasting
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Insert Text “NINGUNO” by Pasting
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Insert Text “UNITED TEXT ASOCIATED TO CODES. I MEAN:…” by Pasting (UNITED TEXT ASOCIATED TO CODES. For this case:
997002: TEXT ASOCIATED (I asociate long text to each code)
36107: TEXT ASOCIATED
36302: TEXT ASOCIATED
990203: TEXT ASOCIATED
36101: TEXT ASOCIATED
36903: TEXT ASOCIATED) this text is for all then, all reconoced text can be past at once.
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Space Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Space Keystroke
Pause for 0.2 Seconds
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the Space Keystroke
Pause for 1 Second
Type the Tab Keystroke
Pause for 0.2 Seconds
Insert Text “IT'S A WORD WHAT DEPEND ON CODE:…” by Pasting (IT CAN BE DEPEND ON VARIABLE:
"HIGIENE": 990203, 36302, 997106, 36903, 997002
"CLASIFICACION" FOR: 36101, 3000400, 3000401, 8902037, 8903039, 8903049, 8903038, 36107.
"HISTORIA": 36601, 87045*("*" CAN BE 1,2,3,4 OR 5), 232102, 230202,
"URGENCIA": 890704

IF SECOND VARIABLE CONTAINS 0
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the 0
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the 0

IF CONTAINS COPAGO
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the "number"
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the 0

IF CONTAINS MODERADORA
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the 0
Type the Tab Keystroke
Pause for 0.2 Seconds
Type the "number"

Type the Tab Keystroke
Pause for 0.2 Seconds
VARIABLE "COTIZANTE" OR "SUBSIDIADO" OR "BENEFICIARIO"
Type the Tab Keystroke
Pause for 0.2 Seconds
LAST VARIABLE "8903039" OR "36101"...

Here I need review and confirmate, press some buttons then start again with next line when it's done.

I forgot the case when are two:

When the last are two numbers just:

Type the Tab Keystroke
Pause for 0.2 Seconds
VARIABLE "COTIZANTE" OR "SUBSIDIADO" OR "BENEFICIARIO"
Type the Tab Keystroke
Pause for 0.2 Seconds
Insert by pasting "Last variable" then press enter
Pause for 0.2 Seconds
Insert by pasting "second number of last variable" then press enter

Some examples:
CC 8128361

COTIZANTE

8128361 CONTROL DE PLACA: Z012/VALOR:0/997002

8128361 CONTROLADO: Z012/VALOR:0/36107

8128361 EDU DETARTRAJE: Z012/VALOR:0/36302 990203

8128361 RIAS: Z012/MODERADORA:4500/36101

8128361 TERA: Z012/VALOR:0/36903

CC 16345228

COTIZANTE

16345228 CONTROL DE PLACA: Z012/VALOR:0/997002

16345228 DETARTRAJE: Z012/VALOR:0/36302

16345228 EDU TERA: Z012/VALOR:0/36903 990203

16345228 RIAS: Z012/VALOR:0/36101

CC 32109403

COTIZANTE

32109403 CONTROL DE PLACA: Z012/VALOR:0/997002

32109403 CONTROLADO: Z012/VALOR:0/36107

32109403 DETARTRAJE: Z012/VALOR:0/36302

32109403 EDU: Z012/VALOR:0/990203

32109403 RIAS: Z012/MODERADORA:4500/36101

32109403 TERA: Z012/VALOR:0/36903

CC 36548492

COTIZANTE

36548492 DETARTRAJE TERA CONTROL DE PLACA: Z012/VALOR:0/36302 36903 997002

36548492 EDU: Z012/VALOR:0/990203

36548492 RIAS: Z012/VALOR:0/36101

CC 43497400

COTIZANTE

43497400 ORDEN RX: Z012/MODERADORA:4500/870454

43497400 RESINAS: Z012/VALOR:0/232102

CC 71622225

SUBSIDIADO

71622225 CONTROL DE PLACA: Z012/VALOR:0/997002

71622225 DETARTRAJE: Z012/VALOR:0/36302

71622225 EDU TERA: Z012/VALOR:0/36903 990203

71622225 RESINAS: K021/VALOR:0/232102

CC 1017127910

COTIZANTE

1017127910 URG: K040/MODERADORA:4500/890704

CC 1017263882

COTIZANTE

1017263882 CONTROL DE PLACA: Z012/VALOR:0/997002

1017263882 CONTROLADO: Z012/VALOR:0/36107

1017263882 DETARTRAJE: Z012/VALOR:0/36302

1017263882 EDU TERA: Z012/VALOR:0/36903 990203

1017263882 RIAS: Z012/VALOR:0/8903038

TI 1025667860

BENEFICIARIO

1025667860 CONTROL DE PLACA: Z012/VALOR:0/997002

1025667860 CONTROLADO: K051/VALOR:0/36107

1025667860 EDU: Z012/VALOR:0/990203

1025667860 RIAS: Z012/MODERADORA:4500/36101

1025667860 TERA: K051/VALOR:0/36903

TI 1025667861

BENEFICIARIO

1025667861 CONTROLADO: Z012/VALOR:0/36107

1025667861 EDU CONTROL DE PLACA: Z012/VALOR:0/990203 997002

1025667861 RIAS: Z012/VALOR:0/3000401

CC 1026137220

COTIZANTE

1026137220 DETARTRAJE: Z012/VALOR:0/36302

1026137220 EDU CONTROL DE PLACA: Z012/VALOR:0/990203 997002

1026137220 TERA: Z012/VALOR:0/36903

1026137220 URG: Z012/VALOR:0/890704

CC 1045111475

BENEFICIARIO

1045111475 EXO: Z012/COPAGO:7400/36601

1045111475 ORDEN RX: K083/MODERADORA:4500/870455

Thanks; I'll look at this tomorrow, it's too late here for my brain tor process anything more today :).

-rob.

1 Like

Thank u a lot for your effort, I learn a lot with your first reply.

Reading it this morning, sorry to say I'm more confused than I was last night. The long example contains variables you didn't mention before, and things where I just can't follow the flow at all.

Based on your first posts, you needed four variables out of the block of text, just entered with some keystrokes and delays. But in your posts from last night, there are conditionals, as well as something about a last number? And in those conditionals, you talk about the second variable containing "COPAGO", etc. But from your first posts, the second variable wasn't ever a word:

The first variable was the word, then the rest were just numbers and/or letters. From my reading, it seems like the most important thing is the first variable, the word. Each word has its own set of rules, it would appear?

I don't think I'll be able to help much more than I have, but if I were you, I'd probably be trying to write a set of rules based on the first word's requirements. Then I'd look for commonalities across each word's rules, as those parts could be shared in your macro, leaving just custom bits for each word's particular requirements.

This is probably not what you wanted to read, but trying to come up with a macro based on the amount of conditions and variables you've provided will be quite time consuming, and I don't have the time to spend on that project at the moment.

But hopefully the provided macro shows you how you can extract the variables from the text, and if you have specific questions as you work on your macro, please do post them (in new threads, specific to each question) and I'm sure the community can help answer them.

-rob.

I just tried to show u the complete Macro. I'ts ok, a learn a lot. Thank U. I'll try and if I'm stucked again, can I ask u?

Certainly you can!

I understand you were showing the complete macro, but it's tough to understand it from an outsider's perspective given the data and trying to infer the proper rules and process.

If you have specific questions, I'm sure I (or others here) can help. It's just that developing a full macro for what you need is going to be time consuming, probably with a lot of back and forth, and I personally don't have the time for that at the moment.

-rob.

1 Like

"Show" is often better than "tell" -- and it's even better if you upload your actual macro rather than the textual representation. You'll find instructions on how to do that in the "How to Post/Upload your Macros and Scripts" post.

Remember to replace any "sensitive" information first, and if you can put any "external" data into a variable instead.

Nice!, I didn't know how to. Thank you.

1 Like

It's done. Thank u a lot. Love u. :rofl:

1 Like

Congrats! Always a good feeling to wrap up a nice timesaving macro.

-rob.

2 Likes