Jump to content

autoit error


Recommended Posts

i have a script with the following code

/code


Local $oVBS = ObjCreate("ScriptControl")
$oVBS.language = "VBScript"
Global Const $Nothing = $oVBS.eval("Nothing")
$oVBS = $Nothing

/endcode

 

this code works on my computers and some other users but on some users

the following error comes up

line 44 (file   "name of the script.au3...for security reasons cant supply the name)

$oVBS.language = "VBScript"

$oVBS^error

error: variable muist be of type "object"

note: users do have autoit installed

 

 

Link to comment
Share on other sites

from dalehohm feb 23,2008

So, here is a way to make the Nothing value available in AutoIt:

 

 

Local $oVBS = ObjCreate("ScriptControl")
$oVBS.language = "VBScript"
Global Const $Nothing = $oVBS.eval("Nothing")
$oVBS = $Nothing

 

$Nothing is then available to use anywhere in your script.

 

so why does this not work for some users?

 

 

 

Link to comment
Share on other sites

  • Developers

Look at example 2 in the helpfile as I would assume you should know by now how to test for success of a function! ;) 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I assume Jos is referring to example 2 of ObjCreate: https://www.autoitscript.com/autoit3/docs/functions/ObjCreate.htm

That being said, things aren't working because ObjCreate("ScriptControl") is failing, and most likely it's failing on some computers and not others because of.... 64-bit!

I tried your script (checking if ObjCreate actually worked) and it failed when run as default, which is in x64 mode. When I added #AutoIt3Wrapper_UseX64=n putting it into 32-bit code mode, it worked just fine. 

Give it a shot with adding #AutoIt3Wrapper_UseX64=n at the top of your code, and see if it works. Also as Jos mentioned, definitely add some If @error then... sections to your code to make sure that each step is working.

I also recommend checking out the example 1 for https://www.autoitscript.com/autoit3/docs/functions/ObjEvent.htm as it allows you to replace the AutoIt error handler with your own, which can give you some more information on what errors you're getting. For me when running the code as x64, it said: "Class not registered"

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

  • 2 weeks later...

yes the same msg

line 44 (file   "name of the script.au3...for security reasons cant supply the name)

$oVBS.language = "VBScript"

$oVBS^error

error: variable muist be of type "object"

note: users do have autoit installed

 

is it possible that scriptcontrol is not installed on the computer, how could you find out?

 

Link to comment
Share on other sites

 

@serena_knight You need to check the objects to see if they initialize successfully or fail.

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("! COM Error !  Number: 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
    Return SetError(1, 0, 0)
EndFunc   ;==>_ErrFunc

Global $oScriptControl_IsReady = 0, $oVBS = ObjCreate("ScriptControl")

If IsObj($oVBS) Then $oScriptControl_IsReady = 1

Global $iNothing
If $oScriptControl_IsReady Then
    $oVBS.language = "vbscript"
    $iNothing = $oVBS.eval("Nothing")
EndIf
Global Const $Nothing = $iNothing

ConsoleWrite("ScriptControl is available: " & $oScriptControl_IsReady & " > IsObj= " & IsObj($oVBS) & " > $Nothing= " & $Nothing & @CRLF)

 

You need to add this Variable and function at the beginning of the script, it will skip and continue running the program without stopping the program and giving an object error!

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("! COM Error !  Number: 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
    Return SetError(1,0,0)
EndFunc   ;==>_ErrFunc

 

Edited by Trong
make better

Regards,
 

Link to comment
Share on other sites

How about this, what is your goal? Do you need "ScriptControl"? What's the purpose of what you're trying to do? What are you going to do with this "Nothing" variable? As mentioned I can get the ScriptControl working, setting the language and getting "Nothing" all without errors, but I don't understand what the point is. You haven't provided any more information on your errors, we don't know what you actually want to do, so you're not going to get much help if you don't help us.

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

ok i am working with an excel spreadsheet. i want to detect if specfic strings exist in a cell, like "empid"

so i check in the script if "empid" has been retrived, if it is nothing then i msg and error.

here is a real example

$cells = $currentworksheet.cells

if $cells = $nothing Then
    msgbox(0,"","problem with ref to cells")
    $oexcel.Workbooks(1).Close
    $oexcel.quit
    Exit
EndIf

Edited by serena_knight
Link to comment
Share on other sites

I think that you'll need to include more of your script, it's best if you can provide a script that someone else here on the forum can run, without having to modify it (and while creating it you may yourself fix your problem by simplifying it). When you post code you could also use the code button to make it more readable: 

 

 

From what you've posted though is there a reason why you can't do one of these:

; I don't use the Excel UDF, but this seems like you're doing things the hard way
$cells = $currentworksheet.cells
; I would suggest instead to use the Excel UDF, and do this:
Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A1") ; Read data from a single cell (string for single cell, array for range)


; Choose one of these:
;=====================
If $sResult = '' Then DoNothing()
;=====================
If $sResult <> '' Then DoNothing()
;=====================
If StringLen($sResult) >= 1 Then DoNothing()
;=====================
Switch $sResult
    Case 'Value1'
        DoSomething()
    Case Else
        DoNothing()
EndSwitch
;=====================
$nothing = ''
If $sResult == $nothing Then DoNothing()
;=====================

Also, I recommend that if you're working with Excel, you at least try out the Excel UDF first, instead of whatever you're doing: https://www.autoitscript.com/autoit3/docs/libfunctions/Excel Management.htm

https://www.autoitscript.com/wiki/Excel_UDF

 

We ought not to misbehave, but we should look as though we could.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...