Sign in to follow this  
Followers 0
DavidFromLafayette

Convert OCX from Excel VB to Autoit

6 posts in this topic

I have a handed down Excel spreadsheet (VB code below) that using an OCX file to make calls to some proprietary software. I am trying to use the same OCX calls to pull and push two values from the software. From what I have read here and other places this should not be this difficult, but there is something fundamental I am missing. Any suggestions are welcome. ShmData.OCX is the OCX file already registered.

AutoIT code so far:

Global $CDA = ObjCreate("ShmData")

ConsoleWrite(@error) <-- produces -2147221005

;~ $Count = 2000

;~ $x = $CDA.GetAllMnemonics($Count)

;~ For $i = 0 To $Count - 1

;~ $Mnemonoic = $x[$i]

;~ $MnemonicValue = $CDA.GetValue($x[$i])

;~ Next

VB Code

Dim CDA As ShmData

Dim Count As Integer

Set CDA = New ShmData

CDA.SetAppName ("Excel CDA")

CDA.CdaName = "local"

Count = 2000

x = CDA.GetAllMnemonics(Count)

For i = 0 To Count - 1

RangeStr$ = "D" + Mid(Str(i + 1), 2)

Application.Sheets("Sheet1").Range(RangeStr$).Value = x(i)

RangeStr$ = "E" + Mid(Str(i + 1), 2)

Application.Sheets("Sheet1").Range(RangeStr$).Value = CDA.GetValue(x(i))

RangeStr$ = "F" + Mid(Str(i + 1), 2)

Application.Sheets("Sheet1").Range(RangeStr$).Value = ((CDA.GetTimeStamp(x(i)) - 3600 * 5) / 86400) + DateValue("01/01/1970")

Next i

Share this post


Link to post
Share on other sites



You need to use an Error Event Handler with every Object - to avoid unexpected script terminations and such cryptic error messages.

This example is taken from the AutoIt Help file:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler

Global $CDA = ObjCreate("ShmData")

Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

Endfunc

Try now your code and see what the message says.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

With the error handling I get...

Number is 8000FFFF catastrophic failure.

I modified the global $cda line to Global $CDA = ObjCreate("SHMDATA.ShmDataCtrl.1")

Share this post


Link to post
Share on other sites

"Catastrophic Failure" - wow, haven't seen that one yet :)

It looks like your script fails to create the object at all - with that, there is no hope of doing anything.

All I can think of now is: somehow you got the name wrong - the object name is not "ShmData" at all and I can bet that neither SHMDATA.ShmDataCtrl.1 is not the right one.

I don't have access to documentation so I can't tell you what to use. But YOU can read the documentation, look for VB examples (I am pretty sure that 99% of all *.ocx hjave VB examples) and get the object name from there. Once you get the correct object name, replace that in the AutoIt sample above and if it is right, you won't get any error at creation time.

Question: is the VB code working on your machine? Is the *.ocx installed and registered?


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

The VB code works fine.

The OCX is in the registry, where I got the Sunday's.shmdatactl.1 from in the ProgID entry.

When I run it the IsObj confirms it creates the object.

Thanks for the input BTW!

Share this post


Link to post
Share on other sites

Unfortunately I don't think I can provide any further help to you in this matter.

If the VB code works, the AutoIt should work too using the same object name as VB. I guess it is up to you to get it working.

Try somehow to get the object creation working and I am sure you will get more help afterwards - for now, I am out of ideas. Good luck,


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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