Sign in to follow this  
Followers 0
FaridAgl

Read & Write as Bool

14 posts in this topic

You know, in AutoIt we don't need to declare datatype, BTW we have something like Number(), Int(), Hex(), String() etc that are useful in some cases,

I was thinking about Bool() as well.

Why? Let me explain.

I have a GUI (It's just an example), it has some CheckBoxes on it, i want to save each CheckBox's values on Exit:

If Checked Then IniWrite(1)
Else IniWrite(0)

And then read it on Start:

If IniRead() = 1 Then Checked
Else Unchecked

It's OK right?

But if we have a Bool() command we can do it like this:

IniWrite(Bool(CheckBox))

And on Start:

same as previus.

I know in AutoIt 0 = False and any other numbers are True.

Maybe it doesn't make any sense in this example, but i'm sure there are so many better usage for it.

I'm wondering why there isn't a Bool() command while we have Int(), Number() etc.

It's simple to make a User-Function for it, in fact i'm doing it for myself, but i just want to know do you thing it can be a good option for AutoIt or not?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Something like this?:

Func Bool(Const $var)
    If $var = 0 Then Return 0
    Return 1
EndFunc

Maybe even:

Func Bool(Const ByRef $checkbox)
    If GUICtrlRead($checkbox) = $GUI_CHECKED Then
        Return 1
    ElseIf GUICtrlRead($checkbox) = $GUI_UNCHECKED
        Return 0
    EndIf
EndFunc

#include <GuiConstantSex.au3>

                        GUICreate           ('',            100,    100,    500,    500)
Global Const $cb      = GUICtrlCreateCheckbox("Click Me",    10,        10)
Global Const $display = GUICtrlCreateLabel   ('',            10,        40,        10,        20)

GUISetState(@SW_SHOWNORMAL)

display_state(Bool($cb))

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cb
            display_state(Bool($cb))
    EndSwitch
WEnd

Func Bool(Const ByRef $checkbox)
    If GUICtrlRead($checkbox) = $GUI_CHECKED Then
        Return 1
    ElseIf GUICtrlRead($checkbox) = $GUI_UNCHECKED Then
        Return 0
    EndIf
EndFunc

Func display_state(Const $state)
    GUICtrlSetData($display, $state)
EndFunc
Edited by LaCastiglione

Share this post


Link to post
Share on other sites

Well, thanks. I coded something like that.

I noticed that AutoIt counts strings as True, is it OK?

$var = "blah blah blah"
If $var Then MsgBox(0, '', '')

And it shows the MsgBox.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You are probably right about that.

But the question is, is this a good suggestion for a native Autoit function?

For me it is not, since it's trivial to make it yourself.

There are so many good Functions in AutoIt that we can code them ourselves, what about removing all of them from AutoIt?

Edited by D4RKON3

Share this post


Link to post
Share on other sites

There are so many good Functions in AutoIt that we can code them ourselves, what about removing all of them from AutoIt?

It's a question if nothing else

my answer is no.

If they did, what do you think autoit would be?


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Hi all,

AutoIt uses the following conventions for true/false:

Numbers: 0 = False, everything else = True

Strings: "" = False, any string with content = True

Boolean: Well you can guess that! ;)

Basically you must be careful with strings (which are returned by several AutoIt functions) as a literal string "0" will be regarded as True. If you want store a Boolean in a file as 0/1, you need to use Number on it when you read it back to make sure you get the correct interpretation. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks Malba,

The information you gave us is enough for me to understand how AutoIt handles Boolean.

I'm going to play with that.

End of Thread of me.

Share this post


Link to post
Share on other sites

D4RKON3,

I thought I posted a reply - who is this Malba guy? :)

Just kidding - glad I could help.

;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Oh sorry, i meant Melba,

Actually i'm searching for a good glasses, maybe i made another thread for it!!!

Thanks again.

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