Jump to content
Sign in to follow this  
zbatev

Embed VBScript into AutoIT

Recommended Posts

zbatev

Hi all...

I have a script that works well in VBScript it uses a com object I tried to translate it into AutoIt some parts work but some don't so I was just thinking of embedding the VBS into my AutoIt code... I dont know if this is the best implementation but im trying to use Scriptomatic but I am getting this error:

I am using the latest version of AutoIT in a windowsXP service pack 3 setup

C:\Documents and Settings\zzz\My Documents\Downloads\scriptomatic.au3(27,117) : WARNING: $WS_OVERLAPPEDWINDOW: possibly used before declaration.
GuiCreate("AutoIt Scriptomatic Tool", 684, 561,(@DesktopWidth-684)/2, (@DesktopHeight-561)/2 , $WS_OVERLAPPEDWINDOW +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\zzz\My Documents\Downloads\scriptomatic.au3(27,131) : WARNING: $WS_VISIBLE: possibly used before declaration.
GuiCreate("AutoIt Scriptomatic Tool", 684, 561,(@DesktopWidth-684)/2, (@DesktopHeight-561)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\zzz\My Documents\Downloads\scriptomatic.au3(27,149) : WARNING: $WS_CLIPSIBLINGS: possibly used before declaration.
GuiCreate("AutoIt Scriptomatic Tool", 684, 561,(@DesktopWidth-684)/2, (@DesktopHeight-561)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\zzz\My Documents\Downloads\scriptomatic.au3(27,117) : ERROR: $WS_OVERLAPPEDWINDOW: undeclared global variable.
GuiCreate("AutoIt Scriptomatic Tool", 684, 561,(@DesktopWidth-684)/2, (@DesktopHeight-561)/2 , $WS_OVERLAPPEDWINDOW +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\zzz\My Documents\Downloads\scriptomatic.au3 - 1 error(s), 3 warning(s)
Edited by zbatev

Share this post


Link to post
Share on other sites
hannes08

From the errors you get you'll need to do a

#include <WindowsConstants.au3>

on top of your code. But I don't see where the link between your text and the error messages you posted is. :mellow:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
zbatev

My first attempt does not work... so i guess my question now is that...

What would be the best way to integrate my VBScript as it is - a vbscript into AutoIT?

If it is not possible my last option would be to call it as an external code shellexecute either as a .vbs or as a .exe

Share this post


Link to post
Share on other sites
water

Can you post the code in VB that you try to translate to AutoIt? As AutoIt is very VB like I assume it should be possible to do what you need in AutoIt.

It's possible to include VB code in AutoIt (haven't done it myself but seen it on the forum) but you have to be careful not to make any errors when embedding and debugging might be a bit complex.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
zbatev

First off this code is automating login and report generation for Avaya CMS application.

The problem is that the conflict is within the scope of the object that i'm using and i doubt you could simulate that but I hope you could still help me out with this

Here is the AutoIT translation that I made for the code, I was able to create a Server and log in to it but I'm getting an error in this line:

$info = $cmsServer.Reports.Reports($reportPath & $reportName)

But I'm afraid the succeeding lines might also get an error.

Dim $cmsApplication
Dim $cmsServer
Dim $cmsConnection
Dim $cmsReport

Dim $info
Dim $rc

Dim $myLog
Dim $myPass
Dim $myServer
Dim $reportPath
Dim $reportName
Dim $reportPrompt11
;Dim reportPrompt12
;Dim reportPrompt13
Dim $reportPrompt21
;Dim reportPrompt22
;Dim reportPrompt23
Dim $exportPath
Dim $exportName

;Create Objects
$cmsApplication = ObjCreate("ACSUP.cvsApplication")
$cmsServer = ObjCreate("ACSUPSRV.cvsServer")
$cmsConnection = ObjCreate("ACSCN.cvsConnection")
$cmsReport = ObjCreate("ACSREP.cvsReport")

; Assigns Variables
$myLog = "username"
$myPass = "password"

$myServer = "11.11.11.11"
$reportPath = "Real-Time\Queue/Agent\"
$reportName = "Queue/Top Agent Status"
$reportPrompt11 = "Split/Skill"
$reportPrompt21 = "9999"
$exportPath = "S:\Somewhere\In\The\HardDrive"
$exportName = "Queue.txt"

$cmsConnection.bAutoRetry = True

;On Error Resume Next

If $cmsApplication.CreateServer($myLog, $myPass, "", $myServer, False, "ENU", $cmsServer, $cmsConnection) Then
msgbox(0,"msg","server created!")
If $cmsConnection.Login($myLog, $myPass, $myServer, "ENU") Then
msgbox(0,"msg","successfully logged in!")
Else
msgbox(0,"msg","login error")
EndIf
Else
msgbox(0,"msg","connection error")
EndIf

$cmsServer.Reports.ACD = 1
$info = $cmsServer.Reports.Reports($reportPath & $reportName)
If $info=0 Then
msgbox(0,"msg","Report not found: " & $reportPath & $reportName)
Else
;On Error Resume Next

$rc = $cmsServer.Reports.CreateReport($info, $cmsReport)
If $rc Then
    $rc = $cmsReport.SetProperty($reportPrompt11, $reportPrompt21)
    $rc = $cmsReport.ExportData($exportPath & "\" & $exportName, 94, 0, True, True, True)
    $cmsReport.Quit
    msgbox(0,"msg","report created!")
Else
    msgbox(0,"msg","report NOT created!")
EndIf

$cmsServer.ActiveTasks.Remove($cmsReport.TaskID)
$cmsApplication.Servers.Remove($cmsServer.ServerKey)

EndIf

$cmsConnection.Logout
$cmsConnection.Disconnect
$cmsServer.Connected = False
Edited by zbatev

Share this post


Link to post
Share on other sites
water

You need to do some more error checking. When working with objects an COM error handler makes debugging much easier. Can you post a screenshot of the MsgBox you get?

Global $cmsApplication, $cmsServer, $cmsConnection, $cmsReport
Global $info, $rc

Global $myLog, $myPass, $myServer
Global $reportPath, $reportName, $reportPrompt11, $reportPrompt21
Global $exportPath, $exportName

;Create Objects
$cmsApplication = ObjCreate("ACSUP.cvsApplication")
if @error <> 0 then Msgbox(16, "", "Error creating ACSUP.cvsApplication object")
$cmsServer = ObjCreate("ACSUPSRV.cvsServer")
if @error <> 0 then Msgbox(16, "", "Error creating ACSUPSRV.cvsServer object")
$cmsConnection = ObjCreate("ACSCN.cvsConnection")
if @error <> 0 then Msgbox(16, "", "Error creating ACSCN.cvsConnection object")
$cmsReport = ObjCreate("ACSREP.cvsReport")
if @error <> 0 then Msgbox(16, "", "Error creating ACSREP.cvsReport object")

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

; Assigns Variables
$myLog = "username"
$myPass = "password"

$myServer = "11.11.11.11"
$reportPath = "Real-Time\Queue/Agent\"
$reportName = "Queue/Top Agent Status"
$reportPrompt11 = "Split/Skill"
$reportPrompt21 = "9999"
$exportPath = "S:\Somewhere\In\The\HardDrive"
$exportName = "Queue.txt"

$cmsConnection.bAutoRetry = True

;On Error Resume Next

If $cmsApplication.CreateServer($myLog, $myPass, "", $myServer, False, "ENU", $cmsServer, $cmsConnection) Then
msgbox(0,"msg","server created!")
If $cmsConnection.Login($myLog, $myPass, $myServer, "ENU") Then
msgbox(0,"msg","successfully logged in!")
Else
msgbox(0,"msg","login error")
EndIf
Else
msgbox(0,"msg","connection error")
EndIf

$cmsServer.Reports.ACD = 1
$info = $cmsServer.Reports.Reports($reportPath & $reportName)
If $info=0 Then
msgbox(0,"msg","Report not found: " & $reportPath & $reportName)
Else
;On Error Resume Next

$rc = $cmsServer.Reports.CreateReport($info, $cmsReport)
If $rc Then
    $rc = $cmsReport.SetProperty($reportPrompt11, $reportPrompt21)
    $rc = $cmsReport.ExportData($exportPath & "\" & $exportName, 94, 0, True, True, True)
    $cmsReport.Quit
    msgbox(0,"msg","report created!")
Else
    msgbox(0,"msg","report NOT created!")
EndIf

$cmsServer.ActiveTasks.Remove($cmsReport.TaskID)
$cmsApplication.Servers.Remove($cmsServer.ServerKey)

EndIf

$cmsConnection.Logout
$cmsConnection.Disconnect
$cmsServer.Connected = False

; This is my custom defined error handler
Func MyErrFunc()

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"      & @CRLF  & @CRLF & _
            "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
            "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: "       & @TAB & hex($oMyError.number,8)  & @CRLF & _
            "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
            "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
            "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
            "err.helpfile is: "     & @TAB & $oMyError.helpfile     & @CRLF & _
            "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )

Endfunc
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
zbatev

Thanks for helping me out:

It seems that the is no problem creating the Objects however this is the error that I got(from the console) and program terminates itself:

$info = $cmsServer.Reports.Reports($reportPath & $reportName)

$info = ^ ERROR

And just to let you know, this is working in its VBScript form.

Edited by zbatev

Share this post


Link to post
Share on other sites
water

Could you please post the complete error message you get?

This just displays where the error is but now what problem Autoit has.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
zbatev

Oh sorry here it is:

>Running:(3.3.6.1):C:\Program Files\AutoIt3\autoit3.exe "C:\AutoITattempt.au3"   
C:\AutoITattempt.au3 (49) : ==> Error in expression.:
$info = $cmsServer.Reports.Reports($reportPath & $reportName)
$info = ^ ERROR
->12:24:15 AutoIT3.exe ended.rc:1
>Exit code: 1    Time: 50.908
Edited by zbatev

Share this post


Link to post
Share on other sites
BrewManNH

Can you post the exact VBscript you're using? Not the translated-to-AutoIt version?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
zbatev

This is the actual vbscript:

Dim cmsApplication
Dim cmsServer
Dim cmsConnection
Dim cmsReport

Dim info
Dim rc

Dim myLog
Dim myPass
Dim myServer
Dim reportPath
Dim reportName
Dim reportPrompt11
Dim reportPrompt21
Dim exportPath
Dim exportName

'Create Objects
Set cmsApplication = CreateObject("ACSUP.cvsApplication")
Set cmsServer = CreateObject("ACSUPSRV.cvsServer")
Set cmsConnection = CreateObject("ACSCN.cvsConnection")
Set cmsReport = CreateObject("ACSREP.cvsReport")


' Assigns Variables
myLog = "theuser"
myPass = "thepassword"

myServer = "1.2.3.4"
reportPath = "Real-Time\Queue/Agent\"
reportName = "Queue/Top Agent Status"
reportPrompt11 = "Split/Skill"
reportPrompt21 = "1234"
exportPath = "S:\Somewhere\In\The\HardDrive"
exportName = "QueueRTP.txt"

cmsConnection.bAutoRetry = True




On Error Resume Next

If cmsApplication.CreateServer(myLog, myPass, "", myServer, False, "ENU", cmsServer, cmsConnection) Then
    If cmsConnection.Login(myLog, myPass, myServer, "ENU") Then
        msgbox "successfully logged in!"
    Else
        MsgBox "login error"
    End If
Else
    MsgBox "connection error"
End If

cmsServer.Reports.ACD = 1
Set info = cmsServer.Reports.Reports(reportPath & reportName)
If info Is Nothing Then
    MsgBox "Report not found: " & reportPath & reportName
Else

On Error Resume Next

rc = cmsServer.Reports.CreateReport(info, cmsReport)
If rc Then
    rc = cmsReport.SetProperty(reportPrompt11, reportPrompt21)
    rc = cmsReport.ExportData(exportPath & "\" & exportName, 94, 0, True, True, True)
    cmsReport.Quit
    WriteStuff.Close
End If

cmsServer.ActiveTasks.Remove cmsReport.TaskID
cmsApplication.Servers.Remove cmsServer.ServerKey
Set cmsReport = Nothing
End If
Set info = Nothing

cmsConnection.Logout
cmsConnection.Disconnect
cmsServer.Connected = False

Set cmsReport = Nothing
Set cmsServer = Nothing
Set cmsConnection = Nothing
Set cmsApplication = Nothing

msgbox "done!"
Edited by zbatev

Share this post


Link to post
Share on other sites
zbatev

I've also tried it without the On Error Resume Next and there was NO Error encountered.

This really puzzles me... I believe the object's properties does not changes over which script or programming code accesses it right? like it might be different if its with VBScript, Visual Basic, AutoIt or any other language...

But one thing that I'm also considering here is that with AutoIT, it managed to create a server and log in to the server that it created but when it comes to that line($info = $cmsServer.Reports.Reports($reportPath & $reportName))... it fails... hmmmmm.... been struggling with this for a couple of days now.

Edited by zbatev

Share this post


Link to post
Share on other sites
ProgAndy

Could you try the beta-version of AutoIt? There were some changes and bugfixes for COM-objects


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
BrewManNH

Is the $reportpath under the script directory? The way it's written, unless I'm mistaken, it is as a relative path to either the working directory, or to the script directory. Another thing you might want to do is to enclose the $reportpath & $reportname in quotes because you have spaces in them it might be throwing the script off. Also, correct the backslashes and forward slashes in the path/file name variables, it shouldn't have an effect but it might also be throwing the script off, you'd need to change all of the forward slashes to back slashes.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
zbatev

Could you try the beta-version of AutoIt? There were some changes and bugfixes for COM-objects

Unfortunately I can't try this now... I'm in the office and there are some restrictions imposed I need to borrow some admin access first.

Is the $reportpath under the script directory? The way it's written, unless I'm mistaken, it is as a relative path to either the working directory, or to the script directory. Another thing you might want to do is to enclose the $reportpath & $reportname in quotes because you have spaces in them it might be throwing the script off. Also, correct the backslashes and forward slashes in the path/file name variables, it shouldn't have an effect but it might also be throwing the script off, you'd need to change all of the forward slashes to back slashes.

Sorry for the confusion but these are not directories rather a way how the object points to the report (like a directory system) think of it as a main menu\sub menu\sub sub menu.... but im tracking a different report right now where there is no forward slash in it... oooops it just ended and I've got the same error....

Hmmm....

Edited by zbatev

Share this post


Link to post
Share on other sites
ProgAndy

Unfortunately I can't try this now... I'm in the office and there are some restrictions imposed I need to borrow some admin access first.

Aren't you allowed to download and execute applications? There is a package which does not need installation. Then run the AuotIt3.exe in this package and choose your script in the dialog.

It would also be of help if you could publish the documentation of the object.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
zbatev

Aren't you allowed to download and execute applications? There is a package which does not need installation. Then run the AuotIt3.exe in this package and choose your script in the dialog.

It would also be of help if you could publish the documentation of the object.

Hi I already tried this but it doesn't also work but I noticed 1 thing:

Is there a Set syntax equivalent in AutoIT from vbscript, for example how should I translate this?

;vbscript
Set info = $msServer.Reports.Reports(reportPath & reportName)

;autoit(is this correct?)
$info = $cmsServer.Reports.Reports($reportPath & $reportName)

I think this is the reason why I'm getting an error.

Edited by zbatev

Share this post


Link to post
Share on other sites
PsaltyDS

AutoIt does not use the "Set" keyword to assign object variable types. You translated it correctly by just putting "$" in front of the variable names and dropping "Set" completely.

(Possible typo: you changed $msServer. to $cmsServer., was that intentional?)

:mellow:

P.S. You should add a COM Error Handler too. See help file under "Obj/COM Reference" or under ObjEvent() for examples.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
zbatev

I give up already. tried every possibility...

I guess I'm back to my first question.... what would be the best way to embed vbscript codes into autoit?

Edited by zbatev

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.