Jump to content

Read & Write as Bool


Recommended Posts

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?

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

D4RKON3,

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

Just kidding - glad I could help.

;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • 7 years later...
  • Moderators

@ur You've been around long enough to know better than to resurrect old threads, especially after just shy of 8 years. I doubt the OP, who hasn't even been online for a year, is still trying to find the answer to this.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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