Jump to content

Recommended Posts

Posted (edited)

I'm trying to use System.Convert.ToBoolean just for no good reason other than to learn. Here is what I tried:

With this $convert is an object...

Global $convert = ObjCreate("System.Object")

If IsObj($convert) Then
    ConsoleWrite("$convert is an object." & @LF)
    ConsoleWrite($convert.ToBoolean(23.15) & @LF)
EndIf

Error:

C:\Users\Matthew\Desktop\New AutoIt v3 Script.au3 (13) : ==> The requested action with this object has failed.:
ConsoleWrite($convert.ToBoolean(23.15) & @LF)
ConsoleWrite($convert.ToBoolean(23.15) ^ ERROR

$convert is not an object...

Global $convert = ObjCreate("System.Convert")

If IsObj($convert) Then
    ConsoleWrite("$convert is an object." & @LF)
    ConsoleWrite($convert.ToBoolean(23.15) & @LF)
EndIf

I tried this variation too:

Global $convert = ObjCreate("System.Object")

If IsObj($convert) Then
    ConsoleWrite("$convert is an object." & @LF)
    ConsoleWrite($convert.Convert.ToBoolean(23.15) & @LF)
EndIf

Here is the error message:

C:\Users\Matthew\Desktop\New AutoIt v3 Script.au3 (13) : ==> The requested action with this object has failed.:
ConsoleWrite($convert.System.Convert.ToBoolean(23.15) & @LF)
ConsoleWrite($convert.System^ ERROR

As well as this one:

Global $convert = ObjCreate("System.Convert")

If IsObj($convert) Then
    ConsoleWrite("$convert is an object." & @LF)
    ConsoleWrite($convert.ToBoolean(23.15) & @LF)
EndIf

And quite a few other things I could think of but none of them seem to work.

If you could just give me a pointer in the right direction?

Edited by jaberwocky6669
Posted (edited)

It appears you are trying to use a .NET class which isn' as simple as cut and paste for AutoIt. Based on the example in the here, it would not be difficult to make your own function to do the conversions described.

ConsoleWrite(_ToBoolean(16.33)&@CRLF)
ConsoleWrite(_ToBoolean(-24)&@CRLF)
ConsoleWrite(_ToBoolean(0)&@CRLF)
ConsoleWrite(_ToBoolean("12")&@CRLF)
ConsoleWrite(_ToBoolean("12.7")&@CRLF)
ConsoleWrite(_ToBoolean("")&@CRLF)
ConsoleWrite(_ToBoolean("1String")&@CRLF)
ConsoleWrite(_ToBoolean("True")&@CRLF)
ConsoleWrite(_ToBoolean("false")&@CRLF)


Func _ToBoolean($obj)
    If Not $obj Then SetError(1,0,0)
    If IsArray($obj) Then SetError(2,0,0)
    If IsString($obj) then
        If Not StringCompare("true",$obj) Then Return True
        If Not StringCompare("false",$obj) Then Return False
        SetError(3,0,0)
    EndIf
    If IsNumber($obj) then
        If $obj <> 0 Then
            Return True
        Else
            Return False
        EndIf
    EndIf
EndFunc
Edited by spudw2k
Posted (edited)

Yeah, this is true. I was just wondering if I could have access to all of the other things the class provides, but that's a no go then. So, there's no way or it's just complicated? I didn't need to use any of those functions, just trying to learn more about windows and programming.

Ok, I think I'm beginning to understand a little more. If it isn't WIndows API or COM then you can't do it with a scripting language?

Edited by jaberwocky6669
Posted

Ok, I think I'm beginning to understand a little more. If it isn't WIndows API or COM then you can't do it with a scripting language?

As far as what AutoIt is designed for, yes (and dll calls); but that's not to say that some folks do some crazy stuff with AutoIt. (Resources, Embedded DLL and EXE, Object Oriented Programming, Service Control Manager, etc...)

Posted (edited)

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
  • Recently Browsing   0 members

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