Jump to content

Show checkbox if fileexists


Recommended Posts

I am trying to build a GUI that will show a checkbox if a particular file exists. If the file does not exist, the checkbox is hidden. The code below sort of works. This is stripped down from a much larger project.

When I run this if a file named test.txt is not on the desktop, no checkbox. If the file is there, then the checkbox appears. However, the checkbox disappears for good as soon as I move my mouse over it or on the same horizontal plane as the checkbox. Hoping someone can help.

;-----------------------------INCLUDES----------------------------------------------------------

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>

;------------------------------VARIABLES--------------------------------------------------------

Dim $extrabutton, $adsi, $main, $add_adsi, $select, $msg

;------------------------------MAIN--------------------------------------------------------

Opt('MustDeclareVars', 1)

$main = GUICreate("Purpose", 380, 270)
GUICtrlCreateLabel("Identify the reason", 55, 10)
$select = GUICtrlCreateButton("Select", 145, 230, 90)
$adsi = GUICtrlCreateCheckbox("Enable ADSI",15,190,375)
$extrabutton = GUICtrlCreateCheckbox("Enable sweetness",100,190,375)
GUICtrlSetState($extrabutton,$gui_hide)
    If FileExists(@DesktopDir & '\test.txt') Then
    GUICtrlSetState($extrabutton,$gui_show)
EndIf

GUISetState()

While 1

    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop
        Case $msg = $select And GUICtrlRead($adsi) = $GUI_CHECKED
            $add_adsi = True
            ContinueCase
    EndSelect
WEnd
Link to comment
Share on other sites

Something like this?

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>

Global $iButton, $iExtra = -1 ; Make sure you set the variable to negative else GUIGetMsg() will fail since it's always returning 0 if no activity.


GUICreate("Purpose", 380, 270)
GUICtrlCreateLabel("Identify the reason.", 5, 10)
$iButton = GUICtrlCreateButton("Select", 145, 230, 90)
GUICtrlCreateCheckbox("Enable ADSI", 15, 190)

If FileExists(@DesktopDir & '\Test.txt') Then
    $iExtra = GUICtrlCreateCheckbox("Enable Sweetness", 100, 190)
EndIf
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop

        Case $iButton
            If _IsChecked($iExtra) Then
                MsgBox(64, "Checked!", "Example.")
            EndIf

    EndSwitch
WEnd

Func _IsChecked($iControlID)
    Return GUICtrlRead($iControlID) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

And I would recommend using Local & Global deceleration in the future, so for Global you would use if the Variable is required elsewhere & Local if only required in the Function.

Edit: Removed Width!

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

you are correct cserrins! The checkbox get disappers when i move the cusrso. when i searched in forum i got a look on below link. Will it be happening? i am using Autoit 3.3.6.1 version.

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

Whoops, I was being an idiot :) >> I removed the Width.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>

Global $iButton, $iExtra = -1 ; Make sure you set the variable to negative else GUIGetMsg() will fail since it's always returning 0 if no activity.


GUICreate("Purpose", 380, 270)
GUICtrlCreateLabel("Identify the reason.", 5, 10)
$iButton = GUICtrlCreateButton("Select", 145, 230, 90)
GUICtrlCreateCheckbox("Enable ADSI", 15, 190)

If FileExists(@DesktopDir & '\Test.txt') Then
    $iExtra = GUICtrlCreateCheckbox("Enable Sweetness", 100, 190)
EndIf
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop

        Case $iButton
            If _IsChecked($iExtra) Then
                MsgBox(64, "Checked!", "Example.")
            EndIf

    EndSwitch
WEnd

Func _IsChecked($iControlID)
    Return GUICtrlRead($iControlID) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

OR reduce the Width to something like 100.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>

Global $iButton, $iExtra = -1 ; Make sure you set the variable to negative else GUIGetMsg() will fail since it's always returning 0 if no activity.


GUICreate("Purpose", 380, 270)
GUICtrlCreateLabel("Identify the reason.", 5, 10)
$iButton = GUICtrlCreateButton("Select", 145, 230, 90)
GUICtrlCreateCheckbox("Enable ADSI", 15, 190, 100)

If FileExists(@DesktopDir & '\Test.txt') = 0 Then
    $iExtra = GUICtrlCreateCheckbox("Enable Sweetness", 100, 190, 100)
EndIf
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop

        Case $iButton
            If _IsChecked($iExtra) Then
                MsgBox(64, "Checked!", "Example.")
            EndIf

    EndSwitch
WEnd

Func _IsChecked($iControlID)
    Return GUICtrlRead($iControlID) = $GUI_CHECKED
EndFunc   ;==>_IsChecked
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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