AutoHotkey Community

It is currently May 27th, 2012, 6:21 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 232 posts ]  Go to page Previous  1 ... 12, 13, 14, 15, 16  Next
Author Message
 Post subject:
PostPosted: November 12th, 2010, 2:26 pm 
@erictheturtle

Thanks that works well :)

Anyway easy way to stop the script at the time out or maybe a msgbox saying 'Update Failed' instead of the WHS error ?

Thanks :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2010, 3:05 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
this may also be useful and related for omeone since i ran into this with scripts using javascript
http://support.microsoft.com/kb/175500

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2010, 10:35 pm 
Thanks.
I resolved it using the code posted.

Would be nice to stop the script if it's running for to long !!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 15th, 2010, 7:17 pm 
using this code:
Code:
; Set timeout in milliseconds
SetTimeout(iTimeout)
{
   global __WS_iScriptControlObj__
   iErr := DllCall(__WS_VTable(__WS_iScriptControlObj__, 14), "UInt", __WS_iScriptControlObj__
            , "Int", iTimeout
            , "Int")
}


; ------  Test -----------

#include ws4ahk.ahk

If this bit take more than 20 seconds
msgbox - Error lets stop...
{


WS_Initialize()

SetTimeout(20 * 1000) ; 20 seconds

; Loop for a long time
sCode =
(
For i = 1 to 100000
   For j = 1 to 10000
   Next
Next
)

WS_Exec(sCode)
}

Is the above in red possible - obviously the code is wrong !!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2010, 4:31 pm 
Hi
I'm using ws4ahk.ahk to use VBS to query a database.

This is working fine, and the results are returned in VBS as an array.

If I add this to the code(), I get the correct results on screen
Code:
For Each item In speed
msgbox item
Next

The question is how do I get the data from array speed so I can use it in AHK ?

Alternately can I create a GUI with a dropdown list in it with the values from 'item'

Is msgbox the only AHK code that works within the CODE section. ?

Thanks :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2010, 9:41 pm 
Offline

Joined: June 27th, 2007, 9:07 pm
Posts: 101
Location: California
dave_sd wrote:
the results are returned in VBS as an array.

The question is how do I get the data from array speed so I can use it in AHK ?

Alternately can I create a GUI with a dropdown list in it with the values from 'item'


The documentation suggests
Quote:
You must convert these unhandled types to another type (usually string) before they can be returned.


So perhaps something like this would work (in VB)
Code:
Function array2str(ary)
    s = ""
    For Each item In ary
        s = s & "," & item
    Next

    array2str = s
End Function


Then call (in ahk)
Code:
WS_Eval(ret, "array2str(speed)")

Split the string up and do whatever you like with it in ahk.

Disclaimer: this code is untested and incomplete

_________________
-m35


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2010, 10:58 pm 
Thanks for that.. couldn't seem to get it working..But have sort of got this working !!

This is what I have:
Code:
Code =
    (
Connection and query BLAH BLAH BLAH

Dim speed()
   iCount = 0
   If Not objectList.EOF Then objectList.MoveFirst
   Do While Not objectList.EOF
   ReDim Preserve speed(iCount)

   speed(iCount) = objectList.Fields(0)
   iCount = iCount + 1
objectList.MoveNext
Loop
)

WS_Exec(Code)

 WS_Eval(icount, "icount")
 
   Gui, Add, Text,,Hello World
   WS_Eval(bar%A_Index%, "speed(" A_Index ")")
   Gui, Add, Text,, % bar%A_Index%



   Loop, %icount%
  {
   WS_Eval(bar%A_Index%, "speed(" A_Index ")")
   Gui, Add, Text,, % bar%A_Index%
   }
   Gui, Show,w500,
   WS_Uninitialize()


If I run this omitting the section in green then I'm returned the values from speed(1) onwards. speed(0) is ignored hence the green bit.

Can this be tidied up ? and present the results as a GUI dropdown list, not as GUI text entries ?

I would like to filter out some of the values from the returned data.
How would I use if var contains on % bar%A_Index% ?

If have tried

Code:
test := % bar%A_Index%
if test not contains UID=1
  Gui, Add, Text,, % bar%A_Index%


But that didn't work.

any ideas on that as well :) ??

Thanks for your time and patience.


Report this post
Top
  
Reply with quote  
PostPosted: March 26th, 2011, 3:40 pm 
Hi there,
I have a script for iTunes which I had working before, but now that I've reformatted my harddrive and reinstalled Windows 7 x64, I keep getting the 'Windows Scripting has not been initialized!' error. I've tried setting the path to the msscript.ocx file, but that doesn't seem to help either.

If anyone is interested in giving me a hand I would be greatly appreciative--I miss my script!

Here it is:
Code:
#Include C:\Program Files (x86)\AutoHotKey\ws4ahk.ahk


WS_Initialize("JScript")
itunes := WS_CreateObject("iTunes.Application")
WS_AddObject(itunes, "itunesapp")
WS_ReleaseObject(itunes)

;Display the current track and playlist
#c::
WS_Eval(trackname, "itunesapp.CurrentTrack.Name;")
WS_Eval(artist, "itunesapp.CurrentTrack.Artist;")
ToolTip, %artist%: %trackname%
SetTimer, RemoveToolTip, 2000
return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

; ############## iTunes ##############
;
; Media keys as normal.
;
; Rate current song:
; win+0 -> no stars
; win+1 -> *
; win+2 -> **
; win+3 -> ***
; win+4 -> ****
; win+5 -> *****

#space::
DetectHiddenWindows, On
ControlSend, ahk_parent, {space}, iTunes ahk_class iTunes
DetectHiddenWindows, Off
return

#x::
WS_Exec("var currtrack = itunesapp.CurrentTrack;")
WS_Exec("var currtime = itunesapp.PlayerPosition;")
WS_Exec("var endtime = currtrack.Finish;")
WS_Exec("var elapsedperc = 100*(currtime/endtime);")
WS_Exec("if (elapsedperc > 60){currtrack.PlayedCount = currtrack.PlayedCount + 1;} else {itunesapp.PlayerPosition = 10;} itunesapp.NextTrack();")
WS_ReleaseObject(currtrack)
return

#z::
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{left}, iTunes ahk_class iTunes
DetectHiddenWindows, Off
return

Volume_Mute::
;Toggles mute - I think this is really elegant. :)
WS_Exec("itunesapp.Mute ^= 1")
return

Volume_Down::
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{down}, iTunes ahk_class iTunes
DetectHiddenWindows, Off
return

Volume_Up::
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{up}, iTunes ahk_class iTunes
DetectHiddenWindows, Off
return

#0::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 0")
WS_ReleaseObject(currtrack)
return

#1::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 20")
WS_ReleaseObject(currtrack)
return

#2::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 40")
WS_ReleaseObject(currtrack)
return

#3::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 60")
WS_ReleaseObject(currtrack)
return

#4::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 80")
WS_ReleaseObject(currtrack)
return

#5::
WS_Exec("currtrack=itunesapp.CurrentTrack")
WS_Exec("currtrack.Rating = 100")
WS_ReleaseObject(currtrack)
return



; Required cleanup
WS_Uninitialize()


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2011, 1:00 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
brohan, you didn't install AutoHotkey_L 64-bit did you? If so, you'd better install the 32-bit version as msscript.ocx is purely 32-bit. (Related: this post by fincs.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2011, 5:02 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
@brohan: here's an updated AutoHotkey_L version of your script that does not need WS4AHK:
Code:
itunesapp := ComObjCreate("iTunes.Application")

;Display the current track and playlist
#c::
trackname := itunesapp.CurrentTrack.Name
artist := itunesapp.CurrentTrack.Artist
ToolTip, %artist%: %trackname%
SetTimer, RemoveToolTip, 2000
return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

; ############## iTunes ##############
;
; Media keys as normal.
;
; Rate current song:
; win+0 -> no stars
; win+1 -> *
; win+2 -> **
; win+3 -> ***
; win+4 -> ****
; win+5 -> *****

#space::
DetectHiddenWindows, On
ControlSend, ahk_parent, {space}, iTunes ahk_class iTunes
DetectHiddenWindows, Off
return

#x::
currtrack := itunesapp.CurrentTrack
currtime := itunesapp.PlayerPosition
endtime := currtrack.Finish
elapsedperc := 100*(currtime/endtime)
if elapsedperc > 60
   currtrack.PlayedCount := currtrack.PlayedCount + 1
else
   itunesapp.PlayerPosition := 10
itunesapp.NextTrack()
return

#z::
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{left}, iTunes ahk_class iTunes
DetectHiddenWindows, Off
return

Volume_Mute::
;Toggles mute - I think this is really elegant. :)
itunesapp.Mute := itunesapp.Mute ^ 1
return

Volume_Down::
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{down}, iTunes ahk_class iTunes
DetectHiddenWindows, Off
return

Volume_Up::
DetectHiddenWindows, On
ControlSend, ahk_parent, ^{up}, iTunes ahk_class iTunes
DetectHiddenWindows, Off
return

#0::
itunesapp.CurrentTrack.Rating := 0
return

#1::
itunesapp.CurrentTrack.Rating := 20
return

#2::
itunesapp.CurrentTrack.Rating := 40
return

#3::
itunesapp.CurrentTrack.Rating := 60
return

#4::
itunesapp.CurrentTrack.Rating := 80
return

#5::
itunesapp.CurrentTrack.Rating := 100
return

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thanks
PostPosted: March 29th, 2011, 5:38 pm 
Hey guys,
Thanks for getting back to me, really appreciate it! Ironically, I spent a long time continuing working on this and came to the exact same solution as you fincs! So simple... Sometimes these simple things can be so obscure.

Sorry, I forgot to post that I had figured it out here--should have registered...

Here is my solution


Report this post
Top
  
Reply with quote  
PostPosted: June 14th, 2011, 2:53 pm 
I have a catalogue in excel I want to take the values of some cells in X row (setting the cell cursor) and tranfer them to other application (like a fill form (HP Open view).

We have already a AHK to do that with Send keystrokes for controlV and controlP between excel and HP application, that takes a lot of time, because for each value we have to see the cahnge between windows of both apps.

I´m trying to optimize the AHK Script and get the values directly.
I have tried varios scripts and I cannot get the row number, with ActiveCell.Row
Code:
#Include ws4ahk.ahk
WS_Initialize()

Code =
(

   Dim xlApp
   Dim xlBook   
   
   'Gets the Excel file in Excel
   Sub GetExcelFile
   xlApp = GetObject("Excel.Application")
   xlApp.visible = true
   xlBook = xlApp.ActiveWorkbooks
   end sub

   'Retrieves a cell value from the specified worksheet
   Function GetCell(Column)
   Dim xlSheet
   Dim linea   
   xlSheet = xlBook.ActiveSheet
   linea = ActiveCell.Row
   GetCell = xlSheet.Cells(linea, Column).Value
   End Function
)

WS_Exec(Code)
WS_Exec(GetExcelFile)
WS_Eval(DescHP, "GetCell(13)")
Msgbox % DescHP
WS_Uninitialize()


Code:
WS_Initialize()
WS_Exec("Set oExcel = GetObject(,""Excel.Application"")")
WS_Exec("Set oActiveSheet = oExcel.ActiveSheet")
WS_Exec("oActiveSheet.Cells(1, 21).Value = ActiveCell.Row")
WS_Eval(got_the_value, "oActiveSheet.Cells(1, 21).Value")
Msgbox % got_the_value
WS_Uninitialize()


Any sugestions?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2011, 8:53 pm 
Offline

Joined: June 27th, 2007, 9:07 pm
Posts: 101
Location: California
Try checking the return value of all WS_* calls. If they're not returning True then something is wrong. Check ErrorLevel for details.

_________________
-m35


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2011, 12:08 pm 
Offline

Joined: June 17th, 2008, 7:51 am
Posts: 243
Have a look at http://www.autohotkey.com/forum/viewtop ... highlight=

_________________
Greetings
Rog


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2011, 7:46 pm 
Offline

Joined: August 7th, 2011, 10:30 am
Posts: 7
Location: Nottingham, England
Can someone point me in the right direction please as I am having trouble getting ws4ahk.ahk to work for me

Whatever I try to run I just get the error "Windows Scripting has not been initialized"

I have ws4ahk.ahk in the same folder as my script and I use VBScript a lot so I know it is installed and working on my PC ok

I then try to run the following
Code:
#include ws4ahk.ahk

vbscript =
(
msgbox "hello world"
)

WS_Initialize()
WS_Exec(vbscript)


The errorlevel is: [-2147221005] CLSIDFromProgID: error -2147221005


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 232 posts ]  Go to page Previous  1 ... 12, 13, 14, 15, 16  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, JamixZol, rbrtryn, Stigg and 20 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