Jump to content

complicated IF and FOR statements


gcue
 Share

Recommended Posts

hello.

Posted Image

im trying to find the best/fastest way to query a large array when 1 or more conditions are selected.

required a = 1 out of 2 fields needs to be selected

required b = 1 out of 3 fields needs to be selected

here's what i have so far:

If GUICtrlRead($altiris_site) = "" And GUICtrlRead($altiris_location) = "" Then
        MsgBox(262144, $selection_text, "Please select a site and/or location.")
        Return
    EndIf

    If BitAND(GUICtrlRead($laptops_checkbox), $GUI_UNCHECKED) And BitAND(GUICtrlRead($desktops_checkbox), $GUI_UNCHECKED) And BitAND(GUICtrlRead($gus_checkbox), $GUI_UNCHECKED) Then
        MsgBox(262144, $selection_text, "Please select at least one PC type.")
        Return
    EndIf

    For $x = 1 To UBound($avOut) - 1

    Next

is the fastest way to think of all possible if statements and do for loops within each?

Edited by gcue
Link to comment
Share on other sites

If you just need one to be checked in the B case, you just need to use BitAND(BitOR(GUICtrlRead($Check1), GUICtrlRead($Check2), GUICtrlRead($Check3)), $GUI_CHECKED). You can use also a loop and terminate it if encounter checked checkbox so if $i = 3 for example (depending on the loop counter value )it means that none is check. In first place it's not that useful, you don't win time this way because you'll eventually need to recheck which was indeed checked and thus re-evaluate it.

Just an example:

#include <GUIConstantsEx.au3>

Global $hGUI, $aChecks[100], $btnTest

$hGUI = GUICreate('Test', 500, 400)
$btnTest = GUICtrlCreateButton('&Start', 200, 300, 100, 25)

For $i = 0 To 9
    For $j = 0 To 9
        $aChecks[$i*10+$j] = GUICtrlCreateCheckbox($i*10+$j+1, $i*60+20, $j*25+10, 55, 20)
    Next
Next

GUISetState()
While 1
    Switch GUIGetMsg()
        Case $btnTest
            For $i = 0 To UBound($aChecks) - 1
                If BitAND(GUICtrlRead($aChecks[$i]), $GUI_CHECKED) Then ExitLoop
            Next
            
            If $i = UBound($aChecks) Then
                MsgBox(0x10, 'Error', 'Please check at least one checkbox')
            Else
                MsgBox(0x40, 'Success', '\m/(-.-)\m/')
            EndIf
            
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
GUIDelete()
Edited by Authenticity
Link to comment
Share on other sites

ok im a bit lost.. this is what i have so far

the return values are 1 if they are check.. not sure how to identify which ones are selected and the different possible variations

Edited by gcue
Link to comment
Share on other sites

I guess I'm missing what you're trying to do. Have you figured it out yet?

Thanks,

Jarvis

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

no not yet...

there's got to be a better way!

this is what i have so far (maybe this will help explain what i am trying to do:

im trying to query an array so each of these if statements would have its own FOR loop - aaaggh!!!!

Posted Image

If GUICtrlRead($altiris_site) <> "" And GUICtrlRead($altiris_location) = "" Then
        If BitAND(GUICtrlRead($laptops_checkbox), $GUI_CHECKED) And BitAND(GUICtrlRead($desktops_checkbox), $GUI_UNCHECKED) And BitAND(GUICtrlRead($gus_checkbox), $GUI_UNCHECKED) Then
            MsgBox(0, "", "SITE and LAPTOP selected")
            Return
        EndIf
        If BitAND(GUICtrlRead($laptops_checkbox), $GUI_UNCHECKED) And BitAND(GUICtrlRead($desktops_checkbox), $GUI_CHECKED) And BitAND(GUICtrlRead($gus_checkbox), $GUI_UNCHECKED) Then
            MsgBox(0, "", "SITE and DESKTOP selected")
            Return
        EndIf
        If BitAND(GUICtrlRead($laptops_checkbox), $GUI_UNCHECKED) And BitAND(GUICtrlRead($desktops_checkbox), $GUI_UNCHECKED) And BitAND(GUICtrlRead($gus_checkbox), $GUI_CHECKED) Then
            MsgBox(0, "", "SITE and GUs selected")
            Return
        EndIf

        If BitAND(GUICtrlRead($laptops_checkbox), $GUI_CHECKED) And BitAND(GUICtrlRead($desktops_checkbox), $GUI_CHECKED) And BitAND(GUICtrlRead($gus_checkbox), $GUI_UNCHECKED) Then
            MsgBox(0, "", "SITE and LAPTOP and DESKTOP selected")
            Return
        EndIf
        If BitAND(GUICtrlRead($laptops_checkbox), $GUI_UNCHECKED) And BitAND(GUICtrlRead($desktops_checkbox), $GUI_CHECKED) And BitAND(GUICtrlRead($gus_checkbox), $GUI_CHECKED) Then
            MsgBox(0, "", "SITE and DESKTOP and GUs selected")
            Return
        EndIf
        If BitAND(GUICtrlRead($laptops_checkbox), $GUI_CHECKED) And BitAND(GUICtrlRead($desktops_checkbox), $GUI_UNCHECKED) And BitAND(GUICtrlRead($gus_checkbox), $GUI_CHECKED) Then
            MsgBox(0, "", "SITE and LAPTOP and GUs selected")
            Return
        EndIf

        If BitAND(GUICtrlRead($laptops_checkbox), $GUI_CHECKED) And BitAND(GUICtrlRead($desktops_checkbox), $GUI_CHECKED) And BitAND(GUICtrlRead($gus_checkbox), $GUI_CHECKED) Then
            MsgBox(0, "", "SITE and LAPTOP, DESKTOP, GUs selected")
            Return
        EndIf
    EndIf


    If GUICtrlRead($altiris_site) = "" And GUICtrlRead($altiris_location) <> "" Then
        MsgBox(0, "", "only location selected")
        Return
    EndIf


    If GUICtrlRead($altiris_site) <> "" And GUICtrlRead($altiris_location) <> "" Then
        MsgBox(0, "", "both site and location selected")
        Return
    EndIf
Link to comment
Share on other sites

You can do yourself a favor and assign the content of the controls to a local variables instead of polling their values multiple times where they're not expected to be changed over the course of the check statements. Another thing you can do, is to use a flag variable to would be set to true on every case that a checkbox is checked or an edit control has a content. This way, if by the end of the function the flag(s) is/are false you can end the function differently.

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