Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/15/2025 in all areas

  1. What exactly leads you to this conclusion? This cannot be deduced from your following text. All of this can be explained perfectly by the fact that there are specific rules for converting other data types to the Boolean data type. There is nothing explicitly against the existence of a corresponding dedicated Boolean data type. Nope - if that were the case, they would behave exactly the same way - but they don't: ConsoleWrite("compare with int type: " & ("0" = retInt() ? True : False) & @CRLF) ConsoleWrite("compare with bool type: " & ("0" = retBool() ? True : False) & @CRLF) Func retInt() Return 1 EndFunc Func retBool() Return True EndFunc The following are also converted to False during conversion to Boolean: Global $aArray[1] Global $mMap[] If $aArray Then MsgBox(0, "", "Array = True") If $mMap Then MsgBox(0, "", "Map = True") If ObjCreate("Scripting.Dictionary") Then MsgBox(0, "", "Object = True") If Default Then MsgBox(0, "", "Default = True") If Ptr(0x0) Then MsgBox(0, "", "Ptr(0) = True") If DllStructCreate("CHAR[1]") Then MsgBox(0, "", "DllStruct = True") If ConsoleWrite Then MsgBox(0, "", "Function pointer = True") Basically, this discussion only touches superficially on logical expressions in AutoIt. In fact, the behavior is only a consequence of the real topic: Implicit data type conversions in AutoIt: AutoIt (like many other languages) is a dynamically typed language. In other words, variables do not have a fixed data type; instead, this can be changed at will during the lifetime of the variable. Nevertheless, variables can be linked together as desired using operators. But internally, at the machine level, only identical data types can be linked together. For example, addition is only possible between two Int32s and not between a Double and an Int32, etc. Therefore, one task of the AutoIt interpreter in operations with multiple operands or when the operation requires a specific target data type is to align the different data types with each other. AutoIt defines fixed rules for how certain data types are converted into others. Integers, for example, are converted to floats by considering the value as the integer part of the resulting float. How exactly certain data types are converted to the Boolean data type (yes, Boolean is explicitly listed as a separate data type) is described in part in the >>AutoIt help<<. Specifically, it says the following, for example: This explains exactly the behavior you described above. And we're not even talking about logical expressions yet - it's just about implicit data type conversion. If you keep in mind that logical operators and the if branch must have the expression as a Boolean, it quickly becomes clear that this is not actually about the behavior of logical expressions, but rather that they are only a consequence of the implicit data type conversion of other data types to the Boolean data type. In summary: The behavior described above describes the effects of implicit conversion of other data types to the Boolean data type. Everything described can be explained completely by this. However, I do not see the slightest indication in the description that AutoIt should not have a dedicated boolean data type.
    3 points
  2. 💡 Did You Know AutoIt’s Truthiness Rules Can Surprise You? Did you know that in AutoIt an empty string is considered False, but the string "0" is treated as True? Or that Not $variable might not behave the way you expect? 🔍 Understanding Logical Expression Evaluation in AutoIt When working with AutoIt, one subtle but important point is how values are converted and evaluated in logical expressions. 👉 AutoIt does have a dedicated Boolean type (True/False). True and False are not just integers — they belong to the Boolean type, as VarGetType(True) shows. However, AutoIt is a dynamically typed language and performs implicit type conversions. Numbers, strings, arrays, maps, and other data types can all be converted into a Boolean when required (e.g., in If or While statements). This is why Boolean behavior can sometimes look surprising if you expect stricter typing. 1️⃣ Boolean Values in AutoIt AutoIt defines two Boolean constants: True and False. Internally, they often behave like 1 and 0, but they are a separate data type. Example:   Local $v1 = True Local $v2 = False ConsoleWrite(VarGetType($v1) & " / " & VarGetType($v2) & @CRLF) ; Outputs: Boolean / Boolean Compare returning integers vs. Booleans:   Func retInt() Return 1 EndFunc Func retBool() Return True EndFunc ConsoleWrite(VarGetType(retInt()) & @CRLF) ; Int32 ConsoleWrite(VarGetType(retBool()) & @CRLF) ; Boolean 2️⃣ Truthiness Rules (Implicit Conversion) When a value is evaluated in a Boolean context (If, While, Not, etc.), AutoIt converts it to a Boolean according to fixed rules. "" (empty string) → False 0 (numeric) → False Any other non-empty string → True Any non-zero number → True But that’s not all. Other types can also convert to False: Empty array Empty map Default Ptr(0) Certain invalid DllStruct values Function pointers when not valid ✅ Examples:   If "" Then MsgBox(0, "Test", "This will NOT show") ; False If "hello" Then MsgBox(0, "Test", "This WILL show") ; True If 0 Then MsgBox(0, "Test", "This will NOT show") ; False If -1 Then MsgBox(0, "Test", "This WILL show") ; True Global $aArray[1] If $aArray Then MsgBox(0, "", "Array = True") ; Won’t show, empty array = False 3️⃣ What Does Not Do? The Not operator inverts the Boolean value of its operand.   ConsoleWrite(Not "" & @CRLF) ; 1 (True) ConsoleWrite(Not "abc" & @CRLF) ; 0 (False) ConsoleWrite(Not 0 & @CRLF) ; 1 (True) ConsoleWrite(Not 123 & @CRLF) ; 0 (False) 👉 In plain words: Not $variable = “is this variable empty, zero, or otherwise converted to False?” 4️⃣ Real Example: UDF _PathFull In the standard UDF File.au3, the function _PathFull contains this line:   If Not $sRelativePath Or $sRelativePath = "." Then Return $sBasePath This handles two cases: $sRelativePath is "" → return the base path. $sRelativePath is "." → return the base path (current directory). It works because AutoIt treats an empty string as False. 5️⃣ Common Pitfalls ❌ Pitfall 1: Thinking False is just 0   Local $x = False If $x Then MsgBox(0, "Result", "Will this show?") ; Will not run, but VarGetType(False) = Boolean, not Int32 ❌ Pitfall 2: Forgetting that "0" (string) is True   If "0" Then MsgBox(0, "Result", "This WILL show!") ; Non-empty string = True ; But numeric 0 would be False. ❌ Pitfall 3: Misunderstanding Not   Local $val = "hello" If Not $val Then MsgBox(0, "Result", "Will this show?") ; Never runs because "hello" converts to True EndIf ✅ Key Takeaways AutoIt has a Boolean type (True/False). In logical expressions, values of other types are implicitly converted to Boolean. Conversion rules: "" and 0 → False Empty array, empty map, Default, Ptr(0) and similar → False Everything else → True Not $var = “is this variable False after conversion?” 📝 Conclusion Understanding AutoIt’s implicit type conversion to Boolean is essential for writing reliable conditions. 👉 Pro Tip: Use implicit truthiness for quick checks, but when clarity matters, be explicit: Use StringLen() to check if a string is empty. Use =, <>, etc. for precise comparisons. Use VarGetType() to confirm whether you’re working with Boolean or another type. This ensures your intent is clear and avoids bugs caused by AutoIt’s flexible but sometimes surprising rules. 💬 Final Note: If I’ve misunderstood or overlooked something, please share your thoughts — I’d be happy to update and improve this article!
    2 points
  3. UDF and DLL updated! See post#1. The DLLs are too big to post it here. You can find it on my 1Drv! Feel free to post examples here!
    2 points
  4. Thanks that solved my issue!😁
    1 point
  5. I found that replacing "xA6" with "¦" in lines 265 and 296 of WinAPIDiag.au3 file in AutoIt Include folder fixed the problem. But I'm not certain whether this change has any impact on other workings of the file.
    1 point
  6. RTFC

    BuildPartitionTable

    Yes, IOCTL_DISK_GET_LENGTH_INFO is a non-destructive read-only operation without any buffers; it's just a harmless query.
    1 point
  7. I compiled Zint v2.15.09 source and it has 30 functions! ZBarcode_BarcodeName|0x0001CBA0 ZBarcode_Buffer|0x0001CC20 ZBarcode_Buffer_Vector|0x0001CC60 ZBarcode_Cap|0x0001CCA0 ZBarcode_Clear|0x0001D270 ZBarcode_Create|0x0001D390 ZBarcode_Default_Xdim|0x0001D3C0 ZBarcode_Delete|0x0001D5D0 ZBarcode_Dest_Len_ECI|0x0001D630 ZBarcode_Encode|0x0001D6D0 ZBarcode_Encode_File|0x0001D710 ZBarcode_Encode_File_and_Buffer|0x0001DB00 ZBarcode_Encode_File_and_Buffer_Vector|0x0001DB50 ZBarcode_Encode_File_and_Print|0x0001DBA0 ZBarcode_Encode_Segs|0x0001DBE0 ZBarcode_Encode_Segs_and_Buffer|0x0001E890 ZBarcode_Encode_Segs_and_Buffer_Vector|0x0001E8F0 ZBarcode_Encode_Segs_and_Print|0x0001E950 ZBarcode_Encode_and_Buffer|0x0001E990 ZBarcode_Encode_and_Buffer_Vector|0x0001EA10 ZBarcode_Encode_and_Print|0x0001EA90 ZBarcode_HaveGS1SyntaxEngine|0x0001EAF0 ZBarcode_NoPng|0x0001EB00 ZBarcode_Print|0x0001EB10 ZBarcode_Reset|0x0001EC30 ZBarcode_Scale_From_XdimDp|0x0001ECA0 ZBarcode_UTF8_To_ECI|0x0001EE80 ZBarcode_ValidID|0x0001EF40 ZBarcode_Version|0x0001EF80 ZBarcode_XdimDp_From_Scale|0x0001EF90 I will update the code in the next days. I compiled also a x64 Zint DLL but I don't know if it is working yet...
    1 point
  8. with _Timer_SetTimer() that will check every e.g.: 1000ms , if the application is running. If it is running it will do nothing, if it is not running it will remove the links example: #include <Timers.au3> #include <GUIConstantsEx.au3> #include <Array.au3> HotKeySet("{ESC}", "_Exit") ; exit HotKeySet("{HOME}", "_Display") ; Display $aApps array HotKeySet("{END}", "_NewApp") ; Run one more notepad (as new example app) Global $MyAppsDir = @ScriptDir & "\MyApps" Global $aApps[0][2] ; We need a GUI to make AutoIt timers work, as the Timers.au3 library is linked to GUI messages. Global $hGUI = GUICreate("My Timer need one GUI", 100, 100) GUISetState(@SW_HIDE) ; set timer to check every nnn Local $i_TimerInterval = 1000 _Timer_SetTimer($hGUI, $i_TimerInterval, "_TimerCheck") ; Run some example apps _RunApp("notepad") _RunApp("notepad") _RunApp("notepad") ; show result of fake symlink ShellExecute($MyAppsDir) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _Exit() Func _RunApp($sName) ShellExecute($sName) Sleep(200) Local $hWnd = WinGetHandle("[ACTIVE]") ConsoleWrite("$hWnd=" & $hWnd & @CRLF) If Not FileExists($MyAppsDir) Then DirCreate($MyAppsDir) Local $sPath = $MyAppsDir & "\" & $hWnd & ".txt" Local $sFill = $hWnd & "|" & $sPath _ArrayAdd($aApps, $sFill) ; fake symlink FileWrite($sPath, $hWnd) EndFunc ;==>_RunApp ; Timer call back function Func _TimerCheck($hWnd, $iMsg, $iIDTimer, $iTime) #forceref $hWnd, $iMsg, $iIDTimer, $iTime If IsArray($aApps) Then Local $sRange = "" For $i = 0 To UBound($aApps) - 1 If Not WinExists(HWnd($aApps[$i][0])) Then ConsoleWrite("found:" & $aApps[$i][0] & @CRLF) FileDelete($aApps[$i][1]) $sRange &= $i & ";" EndIf Next If $sRange <> "" Then $sRange = StringTrimRight($sRange, 1) ConsoleWrite("$sRange=" & $sRange & @CRLF) _ArrayDelete($aApps, $sRange) If @error Then ConsoleWrite("_ArrayDelete @error:" & @error & @CRLF) EndIf EndIf EndFunc ;==>_TimerCheck ; --- HotKeySet functions --- Func _NewApp() _RunApp("notepad") EndFunc ;==>_NewApp Func _Exit() ConsoleWrite("Killed All Timers? " & _Timer_KillAllTimers($hGUI) & @CRLF) GUIDelete($hGUI) DirRemove($MyAppsDir, 1) Exit EndFunc ;==>_Exit Func _Display() If WinExists("$aApps") Then WinClose("$aApps") Else _ArrayDisplay($aApps, "$aApps") EndIf EndFunc ;==>_Display
    1 point
  9. Jon

    AutoIt v3.3.18.0 Released

    AutoIt v3.3.18.0 has been released - mainly a UDF release. Thanks to @jpm and the MVPs who were responsible for the majority of code in this version. Download it here. Complete list of changes: History
    1 point
  10. RTFC

    BuildPartitionTable

    @Olex: you're very welcome, and welcome to the AutoIt forums! Re GPT, I currently lack the hardware to develop this, but I'll soon be acquiring a new workhorse, and if that is UEFI-enabled I may be able to add this functionality in future (I guess that's progress, gotta keep running just to stay in the same place), However, to be honest, it's not the top item on my todo list at the moment, being an MBR dinosaur myself (asteroid? what asteroid?) But as my work environment is upgraded, I may suddenly develop an urgent need for it, in which case I'll post it here, of course.
    1 point
×
×
  • Create New...