AutoHotkey Community

It is currently May 27th, 2012, 1:02 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: November 24th, 2011, 12:41 pm 
Offline

Joined: June 1st, 2006, 5:04 pm
Posts: 45
Location: Denmark
Can anyone tell me why the below code sometimes returns the wrong %FinalPrem%, but mostly it works?

The setup of the script is to:

1: take a value from a system
2: put the value into excel
3: copy the calculated excel value
4: plaste the calculated value from above into the place where i took the value in step 1.

For some reason the value in step 4 is sometimes the same value as step 1! But only like one out of 20 or 30.

Do i need more delays in my code to make it more reliable?

Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


#3:: ;Brug ved 3 deductables

loop
{
loop 3
{
Send ^c
sleep 100
IfEqual, Clipboard, %FinalPrem%
   {
   Msgbox, Cover finished
   return      
   }
Winactivate, Microsoft Excel - Indeksliste.xlsx
sleep 100
Send ^v
sleep 125
Send {right}
sleep 125
Send ^c
sleep 325
FinalPrem := clipboard 
sleep 225
Send {left}
sleep 125
Winactivate, ProductBuilder
sleep 100
Send, {F2}
sleep 125
Send, +{home}
sleep 200
Send, %FinalPrem%
sleep 125
Send, {enter}
sleep 125
send, {right}
sleep 125
}
send {tab}
send {tab}
send {tab}
}
return


Edit: Added SendMode Input to the post that i forgot to copy from my code

_________________
Casper


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2011, 1:02 pm 
Offline

Joined: May 12th, 2009, 2:37 pm
Posts: 640
Location: Gloucester UK
Unfortunately interacting with Excel is a bit of a ball ache as there is no feedback from it using the method you have used.
This means that although most of the time the cursor or selected cell is in the right place, it is posible that it won't be and there is no way for you scipt to know.
For interacting with Excel it is recommended that you use COM in which the program and all the elements within it are assigned as objects which you can access directly. Mickers has done a very nice tutorial on using COM with Excel here.
Although it is a simple tutorial, some of the concepts it discusses are quite advanced (I know I've only just started to get me head around them) so my next question would be, what maths is Excel doing to the initial value you get from your system? AHK has some quite advanced maths functions built in so my gut feeling wold be that you skip Excel all together like in this psuedo code
Code:
get value from original system
do maths to it
paste back to original system


Does that sound feasable?

_________________
The sooner you fall behind, the more time you have to catch up.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2011, 1:21 pm 
When you copy data from excel it may include newline chars, see http://www.autohotkey.com/wiki/index.ph ... #Clipboard (excel)


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Amandaville, BrandonHotkey, chaosad, Yahoo [Bot] and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group