 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
tank
Joined: 21 Dec 2007 Posts: 3700 Location: Louisville KY USA
|
Posted: Wed Feb 03, 2010 5:17 pm Post subject: Some advice |
|
|
obviously ws4ahk provides an easy way to implement vbscript or jscript within ahk thus extending its functionality nicely.
However the question should not be | Quote: | | if I want to use ws4ahk to add a certain value 2 cells to the left of a cell with "ABCD" in it, how would I do this? I can reference cells directly, but is there any way to get the address of a cell with a given value in it? | it should be what vbscript or jscript would be used to do this?.
Consider using the built in macro recorder within excel to get some clue. Note not all code that qualifies as VBA is transfered "as is" to vbscript. but this can be used to test and if it works hurrah but if not then you will need to look into finding out methods from vbscript. For this the MSDN is a great place to start as well as microsofts forums.
Once you have code that will work in a .vbs file then you begin using ws4ahk at that point it should be super easy _________________
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed; |
|
| Back to top |
|
 |
Infiltrated Newbie Guest
|
Posted: Thu Feb 18, 2010 8:29 pm Post subject: |
|
|
This GoogleEarthPhotoTag script makes use of ws4ahk.ahk.
When I use Autohotkey_L (unicode) and run the script I get the error:
| Code: |
Windows Scripting has not been initialized.
Exiting application.
|
I guess ws4ahk must be modified for compatibility with Autohotkey_L (Unicode).
How to do that?
Thanks |
|
| Back to top |
|
 |
erictheturtle
Joined: 27 Jun 2007 Posts: 101 Location: California
|
Posted: Fri Feb 19, 2010 3:35 am Post subject: |
|
|
I had a feeling ws4ahk wasn't going to work with Lexikos's impressive Unicode improvement.
I can appreciate wanting it updated, but is there a reason why you need to run the GoogleEarthPhotoTag program with the new Authotkey_L (Unicode) instead of normal Autohotkey? _________________ -m35 |
|
| Back to top |
|
 |
lexikos* Guest
|
Posted: Fri Feb 19, 2010 5:47 am Post subject: |
|
|
Try this:
| Code: | __WS_ANSI2Unicode(sAnsi, ByRef sUtf16)
{
if A_IsUnicode
return true, sUtf16 := sAnsi
...
| If you pass a UTF-16 string (sAnsi in a Unicode build) to MultiByteToWideChar and tell it that the string is ANSI, you won't get meaningful output. |
|
| Back to top |
|
 |
Beefer Guest
|
Posted: Fri Feb 19, 2010 9:12 am Post subject: |
|
|
Hello, I would like to use this code to connect to my Web Cam. If I run this code, should it not produce a preview window of my connected cam? Am I missing something critically important?
| Code: |
code=
(
Public Class Form1
'---constants for capturing the video from webcam---
Const WM_CAP_START = &H400S
Const WS_CHILD = &H40000000
Const WS_VISIBLE = &H10000000
Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
Const WM_CAP_EDIT_COPY = WM_CAP_START + 30
Const WM_CAP_SEQUENCE = WM_CAP_START + 62
Const WM_CAP_FILE_SAVEAS = WM_CAP_START + 23
Const WM_CAP_SET_SCALE = WM_CAP_START + 53
Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
Const SWP_NOMOVE = &H2S
Const SWP_NOSIZE = 1
Const SWP_NOZORDER = &H4S
Const HWND_BOTTOM = 1
'---used as a window handle---
Dim hWnd As Integer
'--The capGetDriverDescription function retrieves the version
' description of the capture driver--
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" _
(ByVal wDriverIndex As Short, _
ByVal lpszName As String, ByVal cbName As Integer, _
ByVal lpszVer As String, _
ByVal cbVer As Integer) As Boolean
'--The capCreateCaptureWindow function creates a capture window--
Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
(ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
ByVal x As Integer, ByVal y As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Short, ByVal hWnd As Integer, _
ByVal nID As Integer) As Integer
'--This function sends the specified message to a window or
' windows--
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal Msg As Integer, _
ByVal wParam As Integer, _
<MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) _
As Integer
'--Sets the position of the window relative to the screen buffer--
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" _
(ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, _
ByVal y As Integer, _
ByVal cx As Integer, ByVal cy As Integer, _
ByVal wFlags As Integer) As Integer
'--This function destroys the specified window--
Declare Function DestroyWindow Lib "user32" _
(ByVal hndw As Integer) As Boolean
'---preview the selected video source---
Private Sub PreviewVideo(ByVal pbCtrl As PictureBox)
hWnd = capCreateCaptureWindowA(0, _
WS_VISIBLE Or WS_CHILD, 0, 0, 0, _
0, pbCtrl.Handle.ToInt32, 0)
If SendMessage( _
hWnd, WM_CAP_DRIVER_CONNECT, _
0, 0) Then
'---set the preview scale---
SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
'---set the preview rate (ms)---
SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0)
'---start previewing the image---
SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0)
'---resize window to fit in PictureBox control---
SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, _
pbCtrl.Width, pbCtrl.Height, _
SWP_NOMOVE Or SWP_NOZORDER)
Else
'--error connecting to video source---
DestroyWindow(hWnd)
End If
End Sub
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
PreviewVideo(PictureBox1)
End Sub
)
WS_Initialize("VBScript")
WS_Exec(Code)
WS_Uninitialize()
|
|
|
| Back to top |
|
 |
erictheturtle
Joined: 27 Jun 2007 Posts: 101 Location: California
|
Posted: Fri Feb 19, 2010 1:50 pm Post subject: |
|
|
What's the value of ErrorLevel after each call? _________________ -m35 |
|
| Back to top |
|
 |
Beefer Guest
|
Posted: Fri Feb 19, 2010 8:05 pm Post subject: |
|
|
| Code: |
Public Class Form1
'---constants for capturing the video from webcam---
Const WM_CAP_START = &H400S
Const WS_CHILD = &H40000000
Const WS_VISIBLE = &H10000000
Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
Const WM_CAP_EDIT_COPY = WM_CAP_START + 30
Const WM_CAP_SEQUENCE = WM_CAP_START + 62
Const WM_CAP_FILE_SAVEAS = WM_CAP_START + 23
Const WM_CAP_SET_SCALE = WM_CAP_START + 53
Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
Const SWP_NOMOVE = &H2S
Const SWP_NOSIZE = 1
Const SWP_NOZORDER = &H4S
Const HWND_BOTTOM = 1
|
^^^ After this portion, I am receiving an "Expected Identifier" errorlevel
| Code: |
'---used as a window handle---
Dim hWnd As Integer
'--The capGetDriverDescription function retrieves the version
' description of the capture driver--
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" _
(ByVal wDriverIndex As Short, _
ByVal lpszName As String, ByVal cbName As Integer, _
ByVal lpszVer As String, _
ByVal cbVer As Integer) As Boolean
'--The capCreateCaptureWindow function creates a capture window--
Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
(ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
ByVal x As Integer, ByVal y As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Short, ByVal hWnd As Integer, _
ByVal nID As Integer) As Integer
'--This function sends the specified message to a window or
' windows--
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal Msg As Integer, _
ByVal wParam As Integer, _
<MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) _
As Integer
'--Sets the position of the window relative to the screen buffer--
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" _
(ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, _
ByVal y As Integer, _
ByVal cx As Integer, ByVal cy As Integer, _
ByVal wFlags As Integer) As Integer
'--This function destroys the specified window--
Declare Function DestroyWindow Lib "user32" _
(ByVal hndw As Integer) As Boolean
'---preview the selected video source---
Private Sub PreviewVideo(ByVal pbCtrl As PictureBox)
hWnd = capCreateCaptureWindowA(0, _
WS_VISIBLE Or WS_CHILD, 0, 0, 0, _
0, pbCtrl.Handle.ToInt32, 0)
If SendMessage( _
hWnd, WM_CAP_DRIVER_CONNECT, _
0, 0) Then
'---set the preview scale---
SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
'---set the preview rate (ms)---
SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0)
'---start previewing the image---
SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0)
'---resize window to fit in PictureBox control---
SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, _
pbCtrl.Width, pbCtrl.Height, _
SWP_NOMOVE Or SWP_NOZORDER)
Else
'--error connecting to video source---
DestroyWindow(hWnd)
End If
End Sub
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
PreviewVideo(PictureBox1)
End Sub
)
|
^ basically after any sub-portion up here, I am receiving an "Expected end of statement" |
|
| Back to top |
|
 |
erictheturtle
Joined: 27 Jun 2007 Posts: 101 Location: California
|
Posted: Fri Feb 19, 2010 9:22 pm Post subject: |
|
|
It's good you posted your code, and checked what ErrorLevel says. You should also try putting your code into a .vbs file and running it. It will give you the same result. This is because you are doing several things that may be allowed in VB6 and VBA, but are not allowed in VBScript, which is what ws4ahk uses.
I could try walking through your code and identifying all VBScript incompatibilities, but there is plenty of that information already available on the web :)
If you still have problems after you update the code, let me know. _________________ -m35 |
|
| Back to top |
|
 |
Infiltrated Newbie Guest
|
Posted: Fri Feb 19, 2010 9:35 pm Post subject: |
|
|
That worked fine, thanks Lexikos. Your work and patience never stop amazing me
However, GoogleEarthPhotoTag exif part will not work anyways because exiv2 does not support unicode.
Another similar app, Exiftool, faces the same problem:
| Quote: | | In Windows, ExifTool will not process files with Unicode characters in the file name. This is due to an underlying lack of support for Unicode filenames in the Windows standard C I/O libraries. |
The only solution I can think of is to temporarily rename path and filename.
| Quote: | | why you need to run the GoogleEarthPhotoTag program with the new Authotkey_L (Unicode) instead of normal Autohotkey? |
I've got a lot of folders and files named in 2 different (non-english) languages. Like many others I am just in need of unicode suport many times
Sorry for going offtopic |
|
| Back to top |
|
 |
tov Guest
|
Posted: Wed May 12, 2010 12:03 pm Post subject: |
|
|
I need to pass 3 values to my vbs code.
These values will come from a GUI, how do I put them in the VBS ?
They are USERNAME, PASSWORD, IPADDDRESS
| Code: | #Include ws4ahk.ahk
WS_Initialize()
objSO := WS_CreateObject("SuperOffice.Application")
WS_AddObject(objSO, "objSO")
Code =
(
Set ado = CreateObject("ADODB.Connection")
ado.Provider = "ADSDSOObject"
ado.Properties("User ID") = "USERNAME"
ado.Properties("Password") = "PASSWORD"
serverName = "IPADDRESS:386"
) |
Thanks |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 3700 Location: Louisville KY USA
|
Posted: Wed May 12, 2010 12:17 pm Post subject: |
|
|
| Code: | #Include ws4ahk.ahk
WS_Initialize()
objSO := WS_CreateObject("SuperOffice.Application")
WS_AddObject(objSO, "objSO")
Code =
(
Set ado = CreateObject("ADODB.Connection")
ado.Provider = "ADSDSOObject"
ado.Properties("User ID") = "%USERNAME%"
ado.Properties("Password") = "%PASSWORD%"
serverName = "%IPADDRESS%:386"
) | It amy look bizzzare to use modulous to call variable within quote but it is the correct answer within a line continuation block _________________
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed; |
|
| Back to top |
|
 |
erictheturtle
Joined: 27 Jun 2007 Posts: 101 Location: California
|
Posted: Wed May 12, 2010 12:29 pm Post subject: |
|
|
Woah tank, you're fast. I couldn't even login before you finished replying ;)
To add to tank's correct reply, here is a bit more.
| Code: |
#Include ws4ahk.ahk
WS_Initialize()
USERNAME := "<something>"
PASSWORD := "<something>"
IPADDRESS := "<something>"
Code =
(
Set objSO = CreateObject("SuperOffice.Application")
Set ado = CreateObject("ADODB.Connection")
ado.Provider = "ADSDSOObject"
ado.Properties("User ID") = "%USERNAME%"
ado.Properties("Password") = "%PASSWORD%"
serverName = "%IPADDRESS%:386"
)
|
I'm not sure why people seem to like to use WS_CreateObject() and WS_AddObject() when it's less error-prone to just create the object in VBScript directly. _________________ -m35 |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 3700 Location: Louisville KY USA
|
Posted: Wed May 12, 2010 12:31 pm Post subject: |
|
|
ha ha i didnt even look at that im still half asleep _________________
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed; |
|
| Back to top |
|
 |
tov Guest
|
Posted: Wed May 12, 2010 12:41 pm Post subject: |
|
|
| erictheturtle wrote: |
I'm not sure why people seem to like to use WS_CreateObject() and WS_AddObject() when it's less error-prone to just create the object in VBScript directly. |
Thanks for the reply.
Can you please explain this ? thank you |
|
| Back to top |
|
 |
erictheturtle
Joined: 27 Jun 2007 Posts: 101 Location: California
|
Posted: Wed May 12, 2010 12:51 pm Post subject: |
|
|
| tov wrote: | | erictheturtle wrote: |
I'm not sure why people seem to like to use WS_CreateObject() and WS_AddObject() when it's less error-prone to just create the object in VBScript directly. |
Thanks for the reply.
Can you please explain this ? thank you |
Your code
| Code: | ... objSO := WS_CreateObject("SuperOffice.Application")
WS_AddObject(objSO, "objSO")
... |
vs mine
| Code: | ...
Set objSO = CreateObject("SuperOffice.Application")
... |
Your code basically works as well as mine, but it's more typing (and yours will have a memory leak if you don't WS_Release()ing the created object on the AHK side). But I'm really just expressing my general surprise that so many people choose the approach that takes more typing and requires explicit memory management. _________________ -m35 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|