Sign in to follow this  
Followers 0
Chimaera

Checkbox and Array issue

12 posts in this topic

Hi all

I have a few checkboxes that are checked and if ALL are empty when a button is pressed a msg ensues to get user to tick first.

Global $aCheckKeys[6] = [5, $Checkbox_1, $Checkbox_2, $CheckBox_3, $CheckBox_4, $CheckBox_5]
For $i = 1 To $aCheckKeys[$i]
Next

If $aCheckKeys[$i] = $GUI_UNCHECKED Then
    SplashTextOn(" Install Check ", " Please Tick Required Product " & @CRLF & @CRLF & _
      " To Install Files ", 300, 80, -1, -1, 0, "Tahoma", 10, 600)
     Sleep(2000)
     SplashOff()

But it doesnt work if you press it a couple of times you get the message but one press only doesnt work?? and is it checking all the checkboxes?

One small odditty as well i had to add this

Global $Checkbox_1, $Checkbox_2, $CheckBox_3, $CheckBox_4, $CheckBox_5

outside of the button section even though i global the array, anyone know why it needed both?

Share this post


Link to post
Share on other sites



Chimaera,

I would do it this way: :oops:

#include <GUIConstantsEx.au3>

Global $aCheck[5]

$hGUI = GUICreate("Test", 500, 500)

For $i = 0 To 4
    $aCheck[$i] = GUICtrlCreateCheckbox("Check " & $i, 10, 10 + (30 * $i), 100, 20)
Next

$hButton = GUICtrlCreateButton("Go", 10, 300, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            ; Set a flag
            $fEmpty = True
            ; Now look and see if soemthing is checked
            For $i = 0 To 4
                If GUICtrlRead($aCheck[$i]) = $GUI_CHECKED Then
                    ; If it is then clear the flag
                    $fEmpty = False
                    ; No point in looking any further
                    ExitLoop
                EndIf
            Next
            ; If the flag is still set then nothing is checked
            If $fEmpty Then
                SplashTextOn(" Install Check ", " Please Tick Required Product " & @CRLF & @CRLF & _
                        " To Install Files ", 300, 80, -1, -1, 0, "Tahoma", 10, 600)
                Sleep(2000)
                SplashOff()
            EndIf
    EndSwitch

WEnd

Any use? :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I suggest you post the code.

there doesn't seem to be anything relevant there.

i agree we'd have to see the code but i do see a couple of things wrong (maybe)

[font=monospace]

[url="http://www.autoitscript.com/autoit3/docs/keywords.htm"][color="#0000ff"]Global $aCheckKeys[6] = [5, $Checkbox_1, $Checkbox_2, $CheckBox_3, $CheckBox_4, $CheckBox_5]
For $i = 1 To $aCheckKeys[$i]
Next

If $aCheckKeys[$i] = $GUI_UNCHECKED Then
    SplashTextOn(" Install Check ", " Please Tick Required Product " & @CRLF & @CRLF & _
      " To Install Files ", 300, 80, -1, -1, 0, "Tahoma", 10, 600)
     Sleep(2000)
     SplashOff()[/color][/url][/font][font=monospace]

first, theres nothing in your For loop so it's useless.

second,(related to the first) since the If statment is outside of the For loop $i is only going to equal the last number it gets to which would be 5

the reson you are probably being required to Global the $Checkbox_1, $Checkbox_2, $CheckBox_3, $CheckBox_4, $CheckBox_5 is because your pobably calling then in your script at a point where autoit sees a chance that theres a possibility for them not to be declared causing a fatal error and a script crash. also you may have this "Opt("MustDeclareVars", 0)" in your script somewere near the top set to 1 ;0=no, 1=require pre-declare

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I suggest you post the code.

there doesn't seem to be anything relevant there.

17 scripts all tied together way to much to post

Thanks for that melba Ive ended up with this

Case $GuiMsg = $InstallButton
            $fEmpty = True
   Global $aCheckKeys[6] = [5, $Checkbox_1, $Checkbox_2, $CheckBox_3, $CheckBox_4, $CheckBox_5]
   For $i = 1 To 5
             If $aCheckKeys[$i] = $GUI_CHECKED Then
                    $fEmpty = False
                    ExitLoop
                EndIf
; Do some other stuff here ..
            If $fEmpty Then
                SplashTextOn(" Install Check ", " Please Tick Required Product " & @CRLF & @CRLF & _
                    " To Install Files ", 300, 80, -1, -1, 0, "Tahoma", 10, 600)
                Sleep(2000)
                SplashOff()

But ive hit a snag, whilst it checks them sort of how its supposed to it is checking for the All condition only if all 5 are empty can it trigger as it stands it checks one then the next etc

So it wont work as it stands

Its basically just a check for the idiots that don't tick any checkboxes and go straight to the install button. is there a way to check all 5 at once or add them together?

This is how i was doing it before and what i was trying to simplify to an array as i have a load more checkboxes to add

If GUICtrlRead($Checkbox_1 = $GUI_UNCHECKED And $Checkbox_2 = $GUI_UNCHECKED And $CheckBox_3 = $GUI_UNCHECKED And $CheckBox_4 = $GUI_UNCHECKED And $CheckBox_5 = $GUI_UNCHECKED) Then

the reson you are probably being required to Global the $Checkbox_1, $Checkbox_2, $CheckBox_3, $CheckBox_4, $CheckBox_5 is because your pobably calling then in your script at a point where autoit sees a chance that theres a possibility for them not to be declared causing a fatal error and a script crash. also you may have this "Opt("MustDeclareVars", 0)" in your script somewere near the top set to 1 ;0=no, 1=require pre-declare

Ok ive not really used for next much

i actually use this after advice from guinness

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7

Thanks for all the comments

Edited by Chimaera

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

i actually use this after advice from guinness

Great!

Edit: Also about your little 'snag' I'm not following as with Melba's example it will show a warning if no checkboxes are checked.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

Im not saying it doesnt show a warning my problem is it goes through them one by one so i get the warning but 5 times, i need it to check and only if all 5 are empty give the warning

if 1 is ticked and 4 are not it must do nothing

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I get the warning once, look at Melba's version again. Take the If statement (If $fEmpty Then) out of the loop & then you'll get it only once.

And also if you're using Variables e.g. $Checkbox1, $Checkbox2 then you can use a For Loop like this >>

For $i = $Checkbox1 To $Checkbox5
     ....
Next
Which is basically $i = ControlID number of Checkbox 1 to ControlID number of Checkbox 5 Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

You're welcome, but I would do as Melba did with mapping the ControlID returned from GUICtrlCreateCheckbox to an Array item and look at Variable Scope, because with the small snippet you've provided shows you're declaring a Global Variable within a Function, this should be declared at the top of the Script, unless it should be in Local scope?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

Ill try and have a look, unfortunately this script has grown beyond the ridiculous, with one main script with 16 includes and im just starting to look at making it more streamlined

Unfortunately the control ids i think are on the includes not the main and they aren't all active at same time, its very hard to explain, they are modules and i turn them off an on depending on the product to be installed.

Within a few secs i can change one set of products for another set but it also brings more complexity and i haven't been able to come up with a better way...yet

But ill revisit melbas idea and see what can be done

Share this post


Link to post
Share on other sites

It still shouldn't matter about the ControlID's. But trial & error as you know is the best way to really learn AutoIt.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

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  
Followers 0