Jump to content
Sign in to follow this  
Robdog1955

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.

Share this post


Link to post
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 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
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

Share this post


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

Share this post


Link to post
Share on other sites

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

Share this post


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

Share this post


Link to post
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!


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
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)

 


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

Share this post


Link to post
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 2020-09-05 - Version 1.5.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites
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.
  :)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...