Tjalve

COM Error Handler not working for some strange reason

31 posts in this topic

#1 ·  Posted (edited)

Hi Everyone.

Im currently coding script for a BI Tool called Qlikview. Qlikview has a COM API that i use to get data and to manipulate the tool in verius ways. The script in itself is an compiled EXE that can do diffrent tasks depending on what input is put into a txt file. And when this input is entered in the wrong way, the script throws a COM errror. This usually is easy fixed with a COM error handler. But for some reason it wont work im my partucilur case.

I have put the most frequently used QV functions into a UDF witch i call upon in the main script. And when there is a COM error in the main scipt, it works. But when the error is in the UDF (an included au3 file) the COM error handler wont catch the error and the script crashes.

I run this. It works and i get a MSGbox from the COM error handler. The reason for the failiure is that the field "Formfaktor2" does not exists.
 

$object_qv = _qv_open(1)
$o_document = _qv_opendocument($object_qv,"C:\Users\xxxxxx\Documents\Qlikview\xxxxxxx.qvw")
;~ $loop = _qv_field_GetPossibleValues($o_document,"Formfaktor2",$nr_of_returns)
$values = $o_document.Fields("Formfaktor2").GetPossibleValues(300)
    local $array[$values.count + 1]
    $array[0] = $values.count
    for $i = 0 to $values.count - 1
        $array[$i+1] = $values.Item($i).Text
    Next
_ArrayDisplay($array)
Exit

But if i run this:

$object_qv = _qv_open(1)
$o_document = _qv_opendocument($object_qv,"C:\Users\xxxxxx\Documents\Qlikview\xxxxxxxxx.qvw")
$loop = _qv_field_GetPossibleValues($o_document,"Formfaktor2",$nr_of_returns)
Exit

And in the UDF i have this function (same code as above). But then i get  "The requested action with this object has failed.:" on the first row in the function.

func _qv_field_GetPossibleValues($qv_documentobject,$field,$numberofreturns=100)
    $values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)
    local $array[$values.count + 1]
    $array[0] = $values.count
    for $i = 0 to $values.count - 1
        $array[$i+1] = $values.Item($i).Text
    Next
    return $array
EndFunc

The Only difference is that the secound code runs in my UDF isnterad of the main script. But the COM error handler should pick it up anyway. Does anyone jhave any idees? Thansk for your time

Edited by Tjalve

Share this post


Link to post
Share on other sites



Where in the script do you register the error handler, before or after this code is used? How is this function called, and where is it called from.

You're not really giving us any information to work with here.


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

Where in the script do you register the error handler, before or after this code is used? How is this function called, and where is it called from.

You're not really giving us any information to work with here.

My bad.

The COM error handler is initiated at the top of the mainscript (just after the inlcutions) with the following :
 

global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

 and the COm handler is as follows:
 

Func MyErrFunc()
    $HexNumber=hex($oMyError.number,8)
    MsgBox(0,"COM Error","We intercepted a COM Error ! - SKIT OCKSÅ!!!!"       & @CRLF  & @CRLF & _
        "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
        "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
        "err.number is: "         & @TAB & $HexNumber              & @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 _
    )
    SetError(1)  ; to check for after this function returns
    Exit
EndFunc

I have also tried moving the com Error handler to the UDF and initiate it in the start, but it dod not have any effect.

Share this post


Link to post
Share on other sites

try to add COM Error handler as local scope:
 

func _qv_field_GetPossibleValues($qv_documentobject,$field,$numberofreturns=100)
    Local  $oMyError_local = ObjEvent("AutoIt.Error","MyErrFunc")
    $values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)
    local $array[$values.count + 1]
    $array[0] = $values.count
    for $i = 0 to $values.count - 1
        $array[$i+1] = $values.Item($i).Text
    Next
    return $array
EndFunc

 


Wondering who uses AutoIT and what it can be used for ?


ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2017-05-03
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

 

Share this post


Link to post
Share on other sites

try to add COM Error handler as local scope:
 

func _qv_field_GetPossibleValues($qv_documentobject,$field,$numberofreturns=100)
    Local  $oMyError_local = ObjEvent("AutoIt.Error","MyErrFunc")
    $values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)
    local $array[$values.count + 1]
    $array[0] = $values.count
    for $i = 0 to $values.count - 1
        $array[$i+1] = $values.Item($i).Text
    Next
    return $array
EndFunc

 

Good idee. Unfortinently, it didnt work. Still got an error...

Share this post


Link to post
Share on other sites

Anyone else has any idees? I mean, running the fucntion should be the same thing as running it directly the script, right?

Share this post


Link to post
Share on other sites

What version of AutoIT are you using? What OS? Is the script compiled as 32 or 64 bit? Can you duplicate the issue with a more common application (ie: Word, Excel, etc)?

Not sure that any of the above will make a difference, but just trying to help with moving your inquiry along. ;-)

Share this post


Link to post
Share on other sites

Where in the script do you register the error handler, before or after this code is used? How is this function called, and where is it called from.

You're not really giving us any information to work with here.

After all I think @BrewManNH have right.

To check it try to replace you function with this two function:

 

func _qv_field_GetPossibleValues($qv_documentobject,$field,$numberofreturns=100)
    Local  $oMyError_local = ObjEvent("AutoIt.Error","MyErrFunc_SECOND")
    $values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)
    local $array[$values.count + 1]
    $array[0] = $values.count
    for $i = 0 to $values.count - 1
        $array[$i+1] = $values.Item($i).Text
    Next
    return $array
EndFunc

Func MyErrFunc_SECOND()
    $HexNumber=hex($oMyError.number,8)
    MsgBox(0,"COM Error","We intercepted a COM Error ! - SKIT OCKSA!!!!"       & @CRLF  & @CRLF & _
        "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
        "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
        "err.number is: "         & @TAB & $HexNumber              & @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 _
    )
    SetError(1)  ; to check for after this function returns
    Exit
EndFunc

REMARK:
You must place this two function second just after first.

 


Wondering who uses AutoIT and what it can be used for ?


ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2017-05-03
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

After all I think @BrewManNH have right.

To check it try to replace you function with this two function:

 

func _qv_field_GetPossibleValues($qv_documentobject,$field,$numberofreturns=100)
    Local  $oMyError_local = ObjEvent("AutoIt.Error","MyErrFunc_SECOND")
    $values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)
    local $array[$values.count + 1]
    $array[0] = $values.count
    for $i = 0 to $values.count - 1
        $array[$i+1] = $values.Item($i).Text
    Next
    return $array
EndFunc

Func MyErrFunc_SECOND()
    $HexNumber=hex($oMyError.number,8)
    MsgBox(0,"COM Error","We intercepted a COM Error ! - SKIT OCKSA!!!!"       & @CRLF  & @CRLF & _
        "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
        "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
        "err.number is: "         & @TAB & $HexNumber              & @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 _
    )
    SetError(1)  ; to check for after this function returns
    Exit
EndFunc

REMARK:
You must place this two function second just after first.
warning: $oMyError: possibly used before declaration.

Im not 100% i understand how this error funtion works.
The $oMyError variable is defined globaly at the beginning of the script (NOT in the UDF) and should therefor work?

Alright i gave this a try. I added the line to the function (in the UDF) and also added the the function MyErrFunc_SECOUND() into the UDF.

But i just got the error:
warning: $oMyError: possibly used before declaration.

 

So i moved the MyErrFunc_SECOUND() function and pasted into my main script just after the first one. But then i got the same error as befor:
$values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)
$values = $qv_documentobject.Fields($field)^ ERROR

Edited by Tjalve

Share this post


Link to post
Share on other sites

But i just got the error:
warning: $oMyError: possibly used before declaration.

How you declare $oMyError ?
Where you declare $oMyError ?

 

So i moved the MyErrFunc_SECOUND() function and pasted into my main script just after the first one. But then i got the same error as befor:
$values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)
$values = $qv_documentobject.Fields($field)^ ERROR

No, do not move it.
It is good in this place, i mean just after 

Func _qv_field_GetPossibleValues(..)
....
EndFunc

 


Wondering who uses AutoIT and what it can be used for ?


ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2017-05-03
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

How you declare $oMyError ?Where you declare $oMyError ?

 

No, do not move it.It is good in this place, i mean just after 

Func _qv_field_GetPossibleValues(..)
....
EndFunc

 

I found the problem. I declared it at the start of the script, but not befor i included the UDF. And since the func is in the UDF it didt rcognize the varibel. After fixing that, i still got the error from the function:

"C:\Users\*******\Documents\autoit\Qlikview_COM\qlikview.au3" (158) : ==> The requested action with this object has failed.:
$values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)
$values = $qv_documentobject.Fields($field)^ ERROR

 

Just to clerify: I have my mainscript (script.au3) and my UDF (qlikview.au3)

Sqript.au3:

global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

#include <C:\Users\*****\Documents\autoit\Qlikview_COM\qlikview.au3>
#include <array.au3>

$object_qv = _qv_open()
$o_document = _qv_opendocument($object_qv,"C:\Users\*****\Documents\Qlikview\test.qvw")
$loop = _qv_field_GetPossibleValues($o_document,"Formfaktor2",300)
Exit


Func MyErrFunc()
    $HexNumber=hex($oMyError.number,8)
    MsgBox(0,"COM Error","We intercepted a COM Error ! - SKIT OCKSÅ!!!!"       & @CRLF  & @CRLF & _
        "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
        "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
        "err.number is: "         & @TAB & $HexNumber              & @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 _
    )
    SetError(1)  ; to check for after this function returns
    Exit
EndFunc

qlikview.au3

;~ QV OPEN
Func _qv_open()

    Run("C:\Program files\Qlikview\qv.exe","C:\Program files\Qlikview\")
    sleep(5000)
    Local $qv_object = ObjCreate("QlikTech.QlikView")
    if IsObj($qv_object) Then
        sleep(1000)
        return $qv_object
    Else
        SetError(3,"Could not create COM Object")
        return 1
    EndIf

EndFunc


;~ QV Open Document
func _qv_opendocument($qv_object,$qvwfile)

    if IsObj($qv_object) Then

        if FileExists($qvwfile) Then
            $qv_object.OpenDoc($qvwfile)
            return $qv_object.ActiveDocument
        Else
            SetError(2,"File not found")
            return 1
        EndIf

    Else
        SetError(1,"Variable is not an object")
        return 1
    EndIf

EndFunc



;~ Get possible values from a field, based on the current selection
func _qv_field_GetPossibleValues($qv_documentobject,$field,$numberofreturns=100)

    Local  $oMyError_local = ObjEvent("AutoIt.Error","MyErrFunc_SECOND")
    $values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)
    local $array[$values.count + 1]
    $array[0] = $values.count
    for $i = 0 to $values.count - 1
        $array[$i+1] = $values.Item($i).Text
    Next
    return $array

EndFunc



Func MyErrFunc_SECOND()
    $HexNumber=hex($oMyError.number,8)
    MsgBox(0,"COM Error","We intercepted a COM Error ! - SKIT OCKSA!!!!"       & @CRLF  & @CRLF & _
        "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
        "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
        "err.number is: "         & @TAB & $HexNumber              & @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 _
    )
    SetError(1)  ; to check for after this function returns
    Exit
EndFunc

 

Edited by Tjalve

Share this post


Link to post
Share on other sites

Hi all

Maybe you can check if the "field" exist before extracting some datas ?

Func _qv_field_GetPossibleValues($qv_documentobject, $field, $numberofreturns = 100)
    If IsObj($qv_documentobject.Fields($field)) Then 
        $values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)
        Local $array[$values.count + 1]
        $array[0] = $values.count
        For $i = 0 To $values.count - 1
            $array[$i+1] = $values.Item($i).Text
        Next
        Return $array
    EndIf
    Return SetError(0, 0, "")
EndFunc

 

Share this post


Link to post
Share on other sites

Hi all

Maybe you can check if the "field" exist before extracting some datas ?

Func _qv_field_GetPossibleValues($qv_documentobject, $field, $numberofreturns = 100)
    If IsObj($qv_documentobject.Fields($field)) Then 
        $values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)
        Local $array[$values.count + 1]
        $array[0] = $values.count
        For $i = 0 To $values.count - 1
            $array[$i+1] = $values.Item($i).Text
        Next
        Return $array
    EndIf
    Return SetError(0, 0, "")
EndFunc

 

The problem is that it doesnt seem to be a function for that in teh QV API :(

Share this post


Link to post
Share on other sites

Hi all

Maybe you can check if the "field" exist before extracting some datas ?

Func _qv_field_GetPossibleValues($qv_documentobject, $field, $numberofreturns = 100)
    If IsObj($qv_documentobject.Fields($field)) Then 
        $values = $qv_documentobject.Fields($field).GetPossibleValues($numberofreturns)

I would do this with @error not with IsObj.

func _qv_field_GetPossibleValues($qv_documentobject,$field,$numberofreturns=100)
    Local  $oMyError_local = ObjEvent("AutoIt.Error","MyErrFunc_SECOND")
    Local $oField = $qv_documentobject.Fields($field)
    If @error Then MsgBox($MB_ICONERROR, 'VarGetType($oField ) = ' & VarGetType($oField ) & @CRLF & 'VALUE = '& $oField , _
        '@error = ' & @error & @CRLF & '@extended = ' & @extended)
    
    $values = $oField.GetPossibleValues($numberofreturns)
    local $array[$values.count + 1]
    $array[0] = $values.count
    for $i = 0 to $values.count - 1
        $array[$i+1] = $values.Item($i).Text
    Next
    return $array
EndFunc

Func MyErrFunc_SECOND()
    $HexNumber=hex($oMyError.number,8)
    MsgBox(0,"COM Error","We intercepted a COM Error ! - SKIT OCKSA!!!!"       & @CRLF  & @CRLF & _
        "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
        "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
        "err.number is: "         & @TAB & $HexNumber              & @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 _
    )
    SetError(1)  ; to check for after this function returns
    Exit
EndFunc

 


Wondering who uses AutoIT and what it can be used for ?


ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2017-05-03
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)


Wondering who uses AutoIT and what it can be used for ?


ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2017-05-03
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

 

Share this post


Link to post
Share on other sites

 

I would do this with @error not with IsObj.

func _qv_field_GetPossibleValues($qv_documentobject,$field,$numberofreturns=100)
    Local  $oMyError_local = ObjEvent("AutoIt.Error","MyErrFunc_SECOND")
    Local $oField = $qv_documentobject.Fields($field)
    If @error Then MsgBox($MB_ICONERROR, 'VarGetType($oField ) = ' & VarGetType($oField ) & @CRLF & 'VALUE = '& $oField , _
        '@error = ' & @error & @CRLF & '@extended = ' & @extended)
    
    $values = $oField.GetPossibleValues($numberofreturns)
    local $array[$values.count + 1]
    $array[0] = $values.count
    for $i = 0 to $values.count - 1
        $array[$i+1] = $values.Item($i).Text
    Next
    return $array
EndFunc

Func MyErrFunc_SECOND()
    $HexNumber=hex($oMyError.number,8)
    MsgBox(0,"COM Error","We intercepted a COM Error ! - SKIT OCKSA!!!!"       & @CRLF  & @CRLF & _
        "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
        "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
        "err.number is: "         & @TAB & $HexNumber              & @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 _
    )
    SetError(1)  ; to check for after this function returns
    Exit
EndFunc

 

Ive never written an UDF (this is just for my own personal usage) so i would imagine that there are several things that could be done better. Just out of curiosity, why is it better to use @error isntead of isobj?

Share this post


Link to post
Share on other sites

correct. Or more exact: https://community.qlik.com/docs/DOC-2640

The problem is that the API guide is in qvw format (qlikview native file). But i have looked trough it trying to find a way to detemine if a field exists befor i try to read it (as segsested above). But i cannot find anything. My UDF is a lot bigger then this. This is just a piece to illustrate the problem.

And even if i could build around it, i would really like to know why the error handler cannot cacth the error...

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Ive never written an UDF (this is just for my own personal usage) so i would imagine that there are several things that could be done better. Just out of curiosity, why is it better to use @error isntead of isobj?

OCX / ActiveX object can return Object or null or any other kind of return value.
You should first check for @error as this always mean error.
Next you can analyse other issues / cases..

Here you have an example What I would start to do when I was in your place:

Func _qv_field_GetPossibleValues($qv_documentobject, $field, $numberofreturns = 100)
    Local $oMyError_local = ObjEvent("AutoIt.Error", "MyErrFunc_SECOND")
    Local $oField = $qv_documentobject.Fields($field)
    If @error Then
        Return SetError($QLV_ERR_COMERROR, $QLV_EXT_DEFAULT, $QLV_RET_FAILURE)
    ElseIf $oField = Null Then
        Return SetError($QLV_ERR_NULL, $QLV_EXT_DEFAULT, $QLV_RET_FAILURE)
    ElseIf Not IsObj($oField) Then
        Return SetError($QLV_ERR_ISNOTOBJECT, $QLV_EXT_DEFAULT, $QLV_RET_FAILURE)
    Else
        $values = $oField.GetPossibleValues($numberofreturns)
        Local $array[$values.count + 1]
        $array[0] = $values.count
        For $i = 0 To $values.count - 1
            $array[$i + 1] = $values.Item($i).Text
        Next
        Return SetError($QLV_ERR_SUCCESS, $QLV_EXT_DEFAULT, $array)
    EndIf
EndFunc   ;==>_qv_field_GetPossibleValues

Func MyErrFunc_SECOND()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "COM Error", "We intercepted a COM Error ! - SKIT OCKSA!!!!" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & $HexNumber & @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 _
            )
    SetError(1) ; to check for after this function returns
    Exit
EndFunc   ;==>MyErrFunc_SECOND

 

btw.

Read BestCodingPractices and UDF Spec (look in my singature).
As an example start to study my XMLWrapper BETA REWRITE.... 

 

 

Edited by mLipok
some typo and wording

Wondering who uses AutoIT and what it can be used for ?


ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2017-05-03
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

 

Share this post


Link to post
Share on other sites

OCX / ActiveX object can return Object or null or any other kind of return value.
You should first check for @error as this always mean error.Next you can analyse other issues / cases..

Here you have an example What I would start to do when I was in your place:

Func _qv_field_GetPossibleValues($qv_documentobject, $field, $numberofreturns = 100)
    Local $oMyError_local = ObjEvent("AutoIt.Error", "MyErrFunc_SECOND")
    Local $oField = $qv_documentobject.Fields($field)
    If @error Then
        Return SetError($QLV_ERR_COMERROR, $QLV_EXT_DEFAULT, $QLV_RET_FAILURE)
    ElseIf $oField = Null Then
        Return SetError($QLV_ERR_NULL, $QLV_EXT_DEFAULT, $QLV_RET_FAILURE)
    ElseIf Not IsObj($oField) Then
        Return SetError($QLV_ERR_ISNOTOBJECT, $QLV_EXT_DEFAULT, $QLV_RET_FAILURE)
    Else
        $values = $oField.GetPossibleValues($numberofreturns)
        Local $array[$values.count + 1]
        $array[0] = $values.count
        For $i = 0 To $values.count - 1
            $array[$i + 1] = $values.Item($i).Text
        Next
        Return SetError($QLV_ERR_SUCCESS, $QLV_EXT_DEFAULT, $array)
    EndIf
EndFunc   ;==>_qv_field_GetPossibleValues

Func MyErrFunc_SECOND()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "COM Error", "We intercepted a COM Error ! - SKIT OCKSA!!!!" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & $HexNumber & @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 _
            )
    SetError(1) ; to check for after this function returns
    Exit
EndFunc   ;==>MyErrFunc_SECOND

 

btw.

Read BestCodingPractices and UDF Spec (look in my singature).
As an example start to study my XMLWrapper BETA REWRITE.... 

 

 

Great stuff. If i ever decide to "release" this UDF. I will deffentnly read trough all the guidelines.

Share this post


Link to post
Share on other sites

If it is not secret PM it to me.

 


Wondering who uses AutoIT and what it can be used for ?


ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:

Spoiler

Last update: 2017-05-03
Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

 

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

  • Similar Content

    • GMK
      By GMK
      Before upgrading to AutoIt v.3.3.10.2, I had no problems using ObjGet, but now I get a "0x80020006 Unknown name" COM error.  I'm running Windows 7 and the object to which I'm trying to attach is PowerTermPro.Document, which worked fine previously, but not so much now.
      1.  Does anyone know why this error would occur and how to fix it?
      2.  Also, are there any tools available to see which objects are available in the running object table (ROT) and possibly see their ProgID and/or CLSID?