Jump to content
Sign in to follow this  
quickbeam

if-then headscratcher

Recommended Posts

Here's something that isn't making sense.  I have a variable that is false, and it prints as false, but when I do the if-then, it acts as true.

Func SetConfigGui($cfgIndex)

    Local $kludgeVar = $UseStampVal[$cfgIndex]  ; interpreter seems to have a problem here
    ConsoleWrite ("=> Setting GUI settings for config " & $cfgIndex & ", use stamp: " & $kludgeVar & ", key ref: " & $UDKeyRefVal[$cfgIndex] & @CRLF)

    If $kludgeVar = True Then
        If $kludgeVar = False Then
            ConsoleWrite ("We got system issues" & @CRLF)
        EndIf
        ConsoleWrite ("Stamp Val:" & $StampVal[$cfgIndex] & ", kludge " & $kludgeVar & @CRLF)
    Else
    ; never reached
 :
 :
 :

EndFunc

Produces:

Quote

=> Setting GUI settings for config 2, use stamp: False, key ref: None
Stamp Val:FFFFFFFFFFFFFFFFFFFFFFFF, kludge False

I added the kludge variable just to eliminate the possibility of the index doing something weird.

Share this post


Link to post
Share on other sites

Check the type of $kludgeVar. When it is a string then you get True.
 

$var = "False"
If $var = True Then ConsoleWrite( "**" & @CRLF)
ConsoleWrite(VarGetType($var) & @CRLF)

$var = False
If $var = True Then ConsoleWrite( "**" & @CRLF)
ConsoleWrite(VarGetType($var) & @CRLF)

 


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

Wow, how'd I get this far and not know that?  I use different variables the same way, I hadn't noticed a problem, but now I'm going to have double-check everything.

Thanks!

Share this post


Link to post
Share on other sites

BTW, this lump of code doesn't make any sense.

If $kludgeVar = True Then
        If $kludgeVar = False Then
            ConsoleWrite ("We got system issues" & @CRLF)
        EndIf
        ConsoleWrite ("Stamp Val:" & $StampVal[$cfgIndex] & ", kludge " & $kludgeVar & @CRLF)
    Else

If $kludgevar were false, it would never get to the second test to check if it's false, and if it's true, the second test would fail. So what exactly would it accomplish with these 2 tests?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
1 hour ago, quickbeam said:

Wow, how'd I get this far and not know that?  I use different variables the same way, I hadn't noticed a problem, but now I'm going to have double-check everything.

Thanks!

I learnt that the hard way :sweating:

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