Jump to content

Help understanding True False


Recommended Posts

Can some one explain this bit of code. I thought True was like 1 and False  0. But apparently it is more than that. Here is the code I'm looking at.

If ValidUserPassword($sUsername, $sDomain, $sPassword) == "True" Then Something

Func ValidUserPassword($sUsername, $sDomain, $sPassword)
    Local $bValid = True
    RunAs($sUsername, $sDomain, $sPassword, 2, @ComSpec & " /c  echo test", @SystemDir, @SW_Hide)
    If @Error Then $bValid = False
    Return $bValid
EndFunc
 

How is $bValid equal to a text string?

I want to understand instead of just using the code.

Link to comment
Share on other sites

The first statement is wrong. The function returns a binary boolean value (True/False) so you should check for a binary boolean value:

If ValidUserPassword($sUsername, $sDomain, $sPassword) = True Then Something

 

Edited by water
Fixed

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@water I think the correct terminology is a the function returns a Boolean value.

You can simplify the statement 

 

If ValidUserPassword($sUsername, $sDomain, $sPassword) Then Something

 

Saludos

Link to comment
Share on other sites

But it works. If I understand what you are saying, it should not work. That's why I'm asking the question. I can't understand how it could work. I found the code in the forum and thought well if this works, I don't understand what I thought I did. By the way guys thanks for getting back with me so soon. 

Link to comment
Share on other sites

  • Developers

Helpfile:

Quote
        Comparison operators (case insensitive if used with strings except for ==)
= Tests if two values are equal. e.g. If $var = 5 Then    (true if $vVar equals 5). Case insensitive when used with strings. See Note below about comparing mixed datatypes.
== Tests if two strings are equal. Case sensitive. The left and right values are converted to strings if they are not strings already. This operator should only be used if string comparisons need to be case sensitive.

Might give a hint. :)

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

Yeah, I had looked up the "==" part but did not think a boolean value ie. True or False could be converted into a string. Maybe I do not understand what a boolean value is within the context of AutoIt. I am not a programmer so I hope you will forgive my lack of training. My training comes from you guys and I appreciate you more than you could know. I would be lost without you. That said I would like to especially thank Waters. I have used AD.au3 extensively! But also Melba23, trancexx, UEZ... too many to list...

Anyway, I found that:

MsgBox(0, "Debug", "$bValid = " & $bValid)

Where $bValid is True

yields: $bValid = True

So I guess it is text...

Please correct me if I'm not seeing this correctly.

Link to comment
Share on other sites

When you concatenate/append/join something to a "string", the other datatypes (such as Booleans, Integers) are converted to strings as well :)

P.S Boolean is simply a datatype, like integers (numbers). Only 2 values are possible, True or False!

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

*The result is represented as a string, you can still muck around and perform ugly operations while smooshing things together.

$s = "string"
$n = number(5)
$v = $s &- $n
msgbox(0, '' , $v)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

4 hours ago, Robdog1955 said:

That said I would like to especially thank Waters. I have used AD.au3 extensively!

Glad you like my UDF :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Developers
7 hours ago, Robdog1955 said:

but did not think a boolean value ie. True or False could be converted into a string.

AutoIt3 does things to make it easier and more forgiving ... so in this case:

case VAR_BOOL:
            if (m_bValue)
                _tcscpy(szTemp, _T("True") );
            else
                _tcscpy(szTemp, _T("False") );
            break;

Jos ;)

 

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

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...