Jump to content
Macro Express Forums

Need help setting values of variables


Recommended Posts

Hi all,

I am trying to create a macro to help out with work. I have very basic programming knowledge from a few high school classes and I have seen this topic sort of addressed a few times (Cory always brought up Regex), but I want to see if I am not going about this the right way.

 

I have a bunch of text on a web page that gets highlighted with crtl+a and then saved to a variable. I can then read variable and use "if variable contains xyz, variable2 = A. From there I can I just keep searching for key phrases from the text and setting them into new variables. This works fine for things that are "multiple choice" so to speak, but will not work for things like people's names, since it will be completely random what the name is.

 

To get around this, I tried the approach of having the mouse click in selected spots where the words I am looking for will be and copying to clipboard, then setting variable from clipboard. This doesn't work all the time because little discrepancies in the changing web page make it so that I am always off by a few (or sometimes many) pixels.

 

Any ideas here? I was thinking about revisiting my first approach when I just search for phrases in the variable... something like "if variable contains "FIRST NAME: *********" where the ***s are the person's actual name. I would only want to store this info into a new variable though, and not all the extraneous text in the variable. Can this be done?

 

TIA,

Mike

Link to comment
Share on other sites

If you have the entire page in a variable you can use the "Variable Set Integer to the position of" command to search for something in front of the name and something after the name. Something like this might get you started:

Variable Set Integer %Idx% to the position of "First Name:" in %sTemp% // Find "First Name:" in the input string
Variable Modify Integer: %Idx% = %Idx% + 10 // Adjust the idx to skip over "First Name:"
Variable Modify String: Copy a substring in %sTemp%, starting at %Idx% and 99999 characters long to %FirstName% // Copy from the first name to the end of the string

This is not complete. You will have to determine what characters follow the First Name and then do another Variable Modify String: Copy a substring command.

 

Link to comment
Share on other sites

If you have the entire page in a variable you can use the "Variable Set Integer to the position of" command to search for something in front of the name and something after the name. Something like this might get you started:

Variable Set Integer %Idx% to the position of "First Name:" in %sTemp% // Find "First Name:" in the input string
Variable Modify Integer: %Idx% = %Idx% + 10 // Adjust the idx to skip over "First Name:"
Variable Modify String: Copy a substring in %sTemp%, starting at %Idx% and 99999 characters long to %FirstName% // Copy from the first name to the end of the string

This is not complete. You will have to determine what characters follow the First Name and then do another Variable Modify String: Copy a substring command.

 

Thanks for this bit of advice, Samrae. Will this work if the only thing that appears after the first name is a bunch of blank spaces? Or does it need to be a distinct character?

The way that the web page looks when its is copied to the clipboard and set to a variable is something like "First Name: Michael Last name: Jones". Based on this predictable pattern, maybe I can make it find the letter 'L' as the marker to modify the string?

Link to comment
Share on other sites

Use "Last name:" in a "Variable Set Integer %Idx% to the position of" to mark the end of the first name. If nothing appears after the last name but spaces you can get all the characters and then use the "Variable Modify String %sTemp%: Trim" command to remove any leading and trailing spaces.

 

Start with the sample provided and try it. See what happens and see where you need to adjust the macro. If you get stuck post your macro for others to help.

Link to comment
Share on other sites

I had this problem often and what I did was to have a external VBScript download the HTML contents to a variable. What is nice about this is that you can use the HTML tags to identify regions. So let's say you have a series of UL (list) items. They all appear with the <li> tag around them. So I would simply extract whichever one I wanted, say the third one and that's it. Using these normally invisible tasks is far superior. And of course a coupe of lines of RegEx to your script and it will return exactly the values you seek. And I'm happy to write an expression or two for you to help you get a feel for it. I'm no expert but I can usually get the desired results pretty easy. And I'm available for hire.

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.

Guest
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.

Loading...
 Share

×
×
  • Create New...