Sign in to follow this  
Followers 0
locutus243

how clever is the computer?

7 posts in this topic

Hiya guys,

I am using AutoIT to enter data into a series of tables in another application. The way it does it is to tab across the cells. So it enters data, moves across a square, then enters the next peice of data. After entering the fourth peice of data it tabs down to the next row and does the same. This process continues through the whole table.

My problem is that at the moment this is a continuous loop that never stops. I need it to be able to stop after the last row so that I can save my data. But I never know how many rows my table is going to be until I open that file, there may be just 2 rows in some cases or up to 15 in others.

Therefore I was wondering if anybody could come up with a way that AutoIT could detect when it comes to the bottom of the column for me so that it can automatically save and I can run it without any human intervention to enter how many rows there are.

(thats how I'm doing it at the moment, specifying how many rows and then using Do..Until func)

Thanks for your help

Mark

Share this post


Link to post
Share on other sites



Hiya guys,

I am using AutoIT to enter data into a series of tables in another application. The way it does it is to tab across the cells. So it enters data, moves across a square, then enters the next peice of data. After entering the fourth peice of data it tabs down to the next row and does the same. This process continues through the whole table.

My problem is that at the moment this is a continuous loop that never stops. I need it to be able to stop after the last row so that I can save my data. But I never know how many rows my table is going to be until I open that file, there may be just 2 rows in some cases or up to 15 in others.

Therefore I was wondering if anybody could come up with a way that AutoIT could detect when it comes to the bottom of the column for me so that it can automatically save and I can run it without any human intervention to enter how many rows there are.

(thats how I'm doing it at the moment, specifying how many rows and then using Do..Until func)

Thanks for your help

Mark

Once you tab into a field you could get it to check to see if the field is populated, if not save and exit. Please do not ask me how to do that as I am just good at coming up with ideas.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Are you reading the data from another file? What about checking for EOF?

Share this post


Link to post
Share on other sites

Hey guys,

Thanx for your suggestions but because the cells all have the same in then working out where I am from the data in them won't work. I've attached a screenshot of the program I'm working with. As you can see a cell is highlighted, if I key {DOWN} then it moves down to the next row, but when it gets to the bottom row pressing the {DOWN} button just does nothing. I need my script to realise when it reaches the bottom and therefore when it is not going anywhere (then I can count the number of rows in the table!).

See if you have any ideas

Thanks

Mark

Share this post


Link to post
Share on other sites

Hey guys,

Thanx for your suggestions but because the cells all have the same in then working out where I am from the data in them won't work. I've attached a screenshot of the program I'm working with. As you can see a cell is highlighted, if I key {DOWN} then it moves down to the next row, but when it gets to the bottom row pressing the {DOWN} button just does nothing. I need my script to realise when it reaches the bottom and therefore when it is not going anywhere (then I can count the number of rows in the table!).

See if you have any ideas

Thanks

Mark

You forgot to attach the screenshot.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Hey guys,

Thanx for your suggestions but because the cells all have the same in then working out where I am from the data in them won't work. I've attached a screenshot of the program I'm working with. As you can see a cell is highlighted, if I key {DOWN} then it moves down to the next row, but when it gets to the bottom row pressing the {DOWN} button just does nothing. I need my script to realise when it reaches the bottom and therefore when it is not going anywhere (then I can count the number of rows in the table!).

See if you have any ideas

Thanks

Mark

Share this post


Link to post
Share on other sites

Hey guys,

Thanx for your suggestions but because the cells all have the same in then working out where I am from the data in them won't work. I've attached a screenshot of the program I'm working with. As you can see a cell is highlighted, if I key {DOWN} then it moves down to the next row, but when it gets to the bottom row pressing the {DOWN} button just does nothing. I need my script to realise when it reaches the bottom and therefore when it is not going anywhere (then I can count the number of rows in the table!).

See if you have any ideas

Thanks

Mark

The method I used for a similar problem is:

Use pixelsearch to find the color of the highlighted row.

grap 100 or so pixels from about 4 pixels below that first pixel you found (since pixel search searches from top to bottom, it will return the top of the row), put the colors of these pixels into an array

Hit the down arrow once

Hit the up arrow once

Find the highlighted row and again get its Y position (in case you scrolled down)

Hit the down arrow once

Find the highlight color and make sure its Y position is greater then where you just were

If it is, do your work, otherwise you are at the end

I used a similar method for scrolling right in Firefox to read a table. Here is some of the code from that which might help if you get stuck (I did not look back to find all functions and global variables so this will not run as-is).

func next_box_right($boxes_right = 1)
    local $boxes_moved = 0  

    for $boxes_moved = 1 to $boxes_right
        local $reference_x = 0
        local $had_to_move_right = 0
        Do
        ;Always want to have a box to the right of the current box
        ;so First, go right until a line is found (will always happen unless there is something unaccounted for wrong)
            $current_position[0] = $current_position[0] + 1
            mousemove($current_position[0], $current_position[1], 0)
            if($current_position[0] = $max_x) Then
                exit_program("When searching for the next_box_right, could not find the right hand side of the current box.")
            EndIf
        until(pixelgetcolor($current_position[0], $current_position[1]) = $bp_grey_table)
        
        $reference_x = $current_position[0]
    ;Now you are at the next box to the right, but not sure if the right side of that box is on the screen yet, so 
    ;do these steps to make sure:
        local $loop_problem = 0
        $current_position[0] = $current_position[0] + 2
        while(another_box_to_the_right($current_position[0], $current_position[1]) = 0) 
        ;being here in the loop statement means there is not a right edge to the current box on the screen
            ;move mouse pointer left to the last BP grey line
                Do
                    $current_position[0] = $current_position[0] - 1
                until(pixelgetcolor($current_position[0], $current_position[1]) = $bp_grey_table)
            
            ;now get some pixels to the left of this line so we can find where we were
                get_pixels_to_left($current_position[0], $current_position[1], $pixels_to_check)    
            ;get_pixels_to_left are stored in the global array $pixel_row
            ;now actually move over to the right (hit right arrow key a few times)
                move_right()
                $loop_problem = $loop_problem + 1
                if($loop_problem = 50) Then
                    exit_program("Got stuck in the loop trying to find another box to the right (could not find one after 50 moves to the right).")
                EndIf
                sleep($short_delay)
            ;now set the x coordinate to be where it was before we cold not find another_box_to_the_right
                $current_position[0] = find_end_of_pixels($pixels_to_check)
            WEnd
    ;then move off the dividing line
        $current_position[0] = $current_position[0] + 3
    Next
EndFunc


func find_end_of_pixels($number_of_pixels)
    local $temp_x = 0
    local $current_x = 0
    local $found_match = 1
    Do
        $found_match = 1
        for $temp_x = $current_x to $current_x + $pixels_to_check
            if not (pixelgetcolor($temp_x, $current_position[1]) = $pixel_row[$temp_x - $current_x]) Then
                $temp_x = $current_x + $pixels_to_check
                $found_match = 0
            EndIf
            $temp_x = $temp_x + 1
        Next
        $current_x = $current_x + 1
        if($current_x = $max_x) Then
            exit_program("Could not find the pixel row after scrolling to the right")
        EndIf
    until $found_match = 1
    $current_x = $temp_x + 4
    return $current_x
EndFunc

func another_box_to_the_right($x_start, $y_position)
    Do
        $x_start = $x_start + 1
        if($x_start = $max_x) Then
            return 0
        EndIf
    until(pixelgetcolor($x_start, $y_position) = $bp_grey_table)
    return 1    
EndFunc


func get_pixels_to_left($x_start, $y_position, $number_of_pixels)
    local $i
    local $temp_x = $x_start
    $temp_x = $x_start - $number_of_pixels
    
    for $i = 0 to $number_of_pixels - 1
        $pixel_row[$i] = pixelgetcolor($temp_x, $y_position)
        $temp_x = $temp_x + 1
    Next    
EndFunc

func move_right()
    send("{right}")
    sleep($short_delay)
EndFunc

;This function copies the contents of the current box.  It also moves the mouse position to the beginning of the next box.
;Contents will be on the clipboard
func copy_current_box()
    next_box_right()
    local $copy_temp_x = $current_position[0]
    Do  
        $copy_temp_x = $copy_temp_x - 1
    until(pixelgetcolor($copy_temp_x, $current_position[1]) = $bp_grey_table)
    $copy_temp_x = $copy_temp_x - 6
    mousemove($copy_temp_x, $current_position[1], 0)
    sleep($short_delay / 2)
    mousedown("left")
    Do
        $copy_temp_x = $copy_temp_x - 1
    Until(pixelgetcolor($copy_temp_x, $current_position[1]) = $bp_grey_table)
    $copy_temp_x = $copy_temp_x + 3
    mousemove($copy_temp_x, $current_position[1], 0)
    sleep($short_delay / 2)
    mouseup("left")
    sleep($short_delay / 2)
    send("^c")
    sleep($short_delay / 2)
    mousemove($current_position[0], $current_position[1], 0)
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0