Jump to content

Gotta be an easier way....maybe?


Recommended Posts

I am curious if there is a better/faster way to code all of these except by a massive amount of If statements and Functions. Right now my code works, its just that I am up to about 50 If statements and Functions and have about 200+ more to go if I take that route to write an If statement and Function for every possible combination to come out of the combo boxes. Any help down a better path would be much appreciated.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Dialog", 368, 203, 321, 254)
GUISetIcon("D:\004.ico")
$var1 = GUICtrlCreateCombo("", 16, 24, 73, 25)
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5|Opt6|Opt7|Opt8|Opt9|Opt10", "Opt1")
$var2 = GUICtrlCreateCombo("", 112, 24, 73, 25)
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5", "Opt1")
$var3 = GUICtrlCreateCombo("", 16, 56, 73, 25)
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5|Opt6|Opt7|Opt8|Opt9|Opt10", "Opt1")
$var4 = GUICtrlCreateCombo("", 112, 56, 73, 25)
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5", "Opt1")
$Button1 = GUICtrlCreateButton("Start", 160, 128, 113, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Func ScriptChoose()
    If $var1 = "Opt1" And $var2 = "Opt1" And $var3 = "Opt1" And $var4 = "Opt1" Then $Script = Script1()
EndIf
If $var1 = "Opt1" And $var2 = "Opt1" And $var3 = "Opt1" And $var4 = "Opt2" Then $Script = Script2();As you can tell this will just go on and on and on for a couple hundred If statments
EndFunc

Func Script1()
; This will be a collection of mouse moves, mouse clicks, and send commmands. The mouse movements and mouse clicks will change depending on what options are choosen out of the combo boxes
EndFunc

Func Script2()
;As you notice this will also go on for just as many If statments
    EndFunc



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $Button1
            Call(ScriptChoose())
            Call($Script)
    EndSwitch
WEnd
Link to comment
Share on other sites

I am curious if there is a better/faster way to code all of these except by a massive amount of If statements and Functions.

I am not sure if this will work. Here goes:-

Read Combobox :- $var1 = number(StringTrimLeft ( $var1, 3)) - 1

This should give a result of if $var1 = "Opt1" then $var1 = 0

Same with $var2 = ( number(StringTrimLeft ( $var2, 3)) - 1) * 10

This should give a result of, if $var2 = "Opt1" then $var2 = 0

and if Opt2 selected then $var2 = 10

$var3 = (number(StringTrimLeft ( $var3, 3))- 1) * 100

$var4 = (number(StringTrimLeft ( $var4, 3)) - 1) * 1000

So if $var1 = "Opt1" And $var2 = "Opt1" And $var3 = "Opt1" And $var4 = "Opt1" Then this is the same $var1+ $var2+ $var3+ $var4= 0

Some how call function name "script & $var1+ $var2+ $var3+ $var4 +1 & ( )" ???

So that if $var1 = "Opt5" And $var2 = "Opt1" And $var3 = "Opt9" And $var4 ="Opt3" this equals 4 +0 + 800 + 2000 = 2804 so call script2805()

Its an idea. Good luck.

Link to comment
Share on other sites

Nothing about the script in the OP will work.

1. $var1 will never = "opt1" because it contains the ControlID, not the selection. Use GuiCtrlRead() to get the data.

2. Call() is not required, is out of place here, and is not used correctly.

3. A separate script for each possible combination of selections is not required or desired.

Complex case selection logic should not be attempted if you can't read the value from a control yet. Sorry that's just the way it is...

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Alrighty, I cleaned up the code alittle bit and actually answered one of my questions when re-reading my post. So now I am down to two issues with the code, one of which is the orginial which is; how can I avoid having to write out rather large amount of IF, And, Then statements. Hope this helps in what advise to give.

#include <GUIConstants.au3>
#include "Clicks.au3"; this is a command to reference the .au3 file that holds most all the mouseclick functions to use in the script. 

#Region ### START Koda GUI section ### Form=  
$Form1 = GUICreate("Form1", 219, 571, 193, 115) 
$Label12 = GUICtrlCreateLabel("How many can you hold?", 38, 14, 124, 17)
$input1 = GUICtrlCreateInput("0", 47, 32, 65, 21)
$Label13 = GUICtrlCreateLabel("How many do you want?", 20, 73, 150, 17)
$input2 = GUICtrlCreateInput("", 30, 95, 129, 21)
$Button1 = GUICtrlCreateButton("Start", 48, 528, 81, 25, 0)
$Box_1 = GUICtrlCreateCombo("", 16, 160, 153, 90)
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5|Opt6|Opt7|Opt8|Opt9|Opt10|", "Opt1")
$Box_2 = GUICtrlCreateCombo("", 16, 304, 153, 90)
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5|Opt6|Opt7|Opt8|Opt9|Opt10|", "Opt1")
$Box_3 = GUICtrlCreateCombo("", 14, 364, 153, 90)
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5", "Opt1")
$Label1 = GUICtrlCreateLabel("Where are you getting them from?", 16, 136, 164, 17)
$Label2 = GUICtrlCreateLabel("Where will you them if they are'nt there", 8, 280, 188, 17)
$Label3 = GUICtrlCreateLabel("Where are you stopping at?", 16, 336, 152, 17)
$Label4 = GUICtrlCreateLabel("Where will you drop it off at?", 8, 224, 191, 17)
$Box_4 = GUICtrlCreateCombo("", 16, 248, 177, 90)
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5", "Opt1")
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=  



Dim $nBox_1 = GUICtrlRead($Box_1)
Dim $nBox_2 = GUICtrlRead($Box_2)
Dim $nBox_3 = GUICtrlRead($Box_3)
Dim $nBox_4 = GUICtrlRead($Box_4)

If $nBox_1 = "Opt1" Then
         $Func_1 = Test Function_1()
        EndIf
If $nBox_1 = "Opt2" Then 
         $Func_1 = Test Func_2()

; and so on and so on. 
        





Func Test(); this is the function templete for for what i want it to do


    $count = 0

    Dim $var1 = GUICtrlRead($input1)
    Dim $var2 = GUICtrlRead($input2)
    Dim $Loop = Number(Int(Number($var2) / Number($var1)))
    If Number($var2) < Number($var1) Then
        $Loop = 1
    EndIf
    Dim $H = $var1
    If Number($var2) < Number($var1) Then
        $H = $var2
    EndIf
    
    

    While $count < $Loop

        $count = $count + 1


        $Func_1

        $Func_2

        $Func_3

        $Func_4


    WEnd
    MsgBox(4096, "Script", "Script Completed", 10)


EndFunc ;==>Test



While 1 
    $nMsg = GUIGetMsg()
    
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $nMsg = $Button1
            Test()
            
    EndSelect
WEnd

Each of the options in the combo boxes is a different function. The options in box_1 are the functions for $Func_1, the options in Box_2 are the functions for $Func_2, ect.. Like I said before, Just looking for a way to save myself the pain of writing a lot of If statements. Thanx for the help so far guys. :)

Edited by redjester45
Link to comment
Share on other sites

Alrighty, I cleaned up the code alittle bit and actually answered one of my questions when re-reading my post. So now I am down to two issues with the code, one of which is the orginial which is; how can I avoid having to write out rather large amount of IF, And, Then statements. Hope this helps in what advise to give.

Each of the options in the combo boxes is a different function. The options in box_1 are the functions for $Func_1, the options in Box_2 are the functions for $Func_2, ect.. Like I said before, Just looking for a way to save myself the pain of writing a lot of If statements. Thanx for the help so far guys. ;)

I couldn't make heads or tails of what you wanted to do with the entries and options once you have them, but when collecting many inputs like that, I prefer to use arrays. In this example, the $avInputs array holds the ControlIDs of the input controls, and $avBoxes for the combo boxes. When reading them, all the inputs were read into the $avEntries array, and combo boxes to $avOptions:

#include <GUIConstants.au3>
;#include "Clicks.au3"; this is a command to reference the .au3 file that holds most all the mouseclick functions to use in the script.
#include <array.au3>

Global $avInputs[1] ; Inputs, element [0] not used
Global $avEntries[1] ; Entered values from the inputs
Global $avBoxes[1] ; Combo boxes, element [0] not used
Global $avOptions[1] ; Selected options from combo boxes

$Form1 = GUICreate("Form1", 219, 571, 193, 115)
$Label12 = GUICtrlCreateLabel("How many can you hold?", 38, 14, 124, 17)
_ArrayAdd($avInputs, GUICtrlCreateInput("0", 47, 32, 65, 21))
$Label13 = GUICtrlCreateLabel("How many do you want?", 20, 73, 150, 17)
_ArrayAdd($avInputs, GUICtrlCreateInput("", 30, 95, 129, 21))
$Button1 = GUICtrlCreateButton("Start", 48, 528, 81, 25, 0)
_ArrayAdd($avBoxes, GUICtrlCreateCombo("", 16, 160, 153, 90))
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5|Opt6|Opt7|Opt8|Opt9|Opt10|", "Opt1")
_ArrayAdd($avBoxes, GUICtrlCreateCombo("", 16, 304, 153, 90))
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5|Opt6|Opt7|Opt8|Opt9|Opt10|", "Opt1")
_ArrayAdd($avBoxes, GUICtrlCreateCombo("", 14, 364, 153, 90))
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5", "Opt1")
$Label1 = GUICtrlCreateLabel("Where are you getting them from?", 16, 136, 164, 17)
$Label2 = GUICtrlCreateLabel("Where will you them if they are'nt there", 8, 280, 188, 17)
$Label3 = GUICtrlCreateLabel("Where are you stopping at?", 16, 336, 152, 17)
$Label4 = GUICtrlCreateLabel("Where will you drop it off at?", 8, 224, 191, 17)
_ArrayAdd($avBoxes, GUICtrlCreateCombo("", 16, 248, 177, 90))
GUICtrlSetData(-1, "Opt1|Opt2|Opt3|Opt4|Opt5", "Opt1")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $nMsg = $Button1
            Test()
    EndSelect
WEnd

Func Test(); this is the function templete for for what i want it to do
    ReDim $avEntries[UBound($avInputs)] ; global array of entries to input controls
    ReDim $avOptions[UBound($avBoxes)] ; global array of combo box options
    
    ; Check inputs
    For $n = 1 To UBound($avInputs) - 1
        $avEntries[$n] = GUICtrlRead($avInputs[$n])
    Next
    
    ; Check combo boxes
    For $n = 1 To UBound($avBoxes) - 1
        $avOptions[$n] = GUICtrlRead($avBoxes[$n])
    Next
    
    _ArrayDisplay($avEntries, "Entries to Input controls")
    _ArrayDisplay($avOptions, "Combobox options selected")
EndFunc   ;==>Test

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The script is a gui that wil allow me to run a macro. Input1 is how many of an item I can hold, Input2 is How many items I want.

I have the math for all that figured out and that part works(kinda..theres a small wrinkle I am working on right now). Test() is the actual mouse movements and send commands. Box_1 is basically what reigon I want to pick them up in. Box_2 is where in that reigon I will pick them up at. Box_3 is where I am taking them and Box_4 is where in that reigon I am dropping them off at. Each of those options needs a different set of mouse movements. I can prolably make it work with a lot of If statements but it feels like I am going around my butt to get to my elbow by doing it that way. :) I am pretty sure there is an easier way to do it, but I'm a noob. lol I will look at the changes you made and try to make as much sense as I can out of them. Thank you for the help.

P.S.

Is there any sort of an array tutorial? Been looking for info on arrays but have not found anything that has really made it click yet.

Edited by redjester45
Link to comment
Share on other sites

This is how to use arrays:

; Method one
Dim $stringsp[4]
$array[0] = "One"
$array[1] = "Two"
$array[2] = "Three"
$array[3] = "Four"

; Method two
Dim $array[4] = ["One", "Two", "Three", "Four"]

Copyed from PsaltyDS from another topic, I modified it abit. I thought it shows good how to declare arrays.

EDIT: You can check this out: http://quadryders.com/phpcc/browse.php?cid=3

Edited by LinuZ
Link to comment
Share on other sites

The script is a gui that wil allow me to run a macro. Input1 is how many of an item I can hold, Input2 is How many items I want.

I have the math for all that figured out and that part works(kinda..theres a small wrinkle I am working on right now). Test() is the actual mouse movements and send commands. Box_1 is basically what reigon I want to pick them up in. Box_2 is where in that reigon I will pick them up at. Box_3 is where I am taking them and Box_4 is where in that reigon I am dropping them off at. Each of those options needs a different set of mouse movements. I can prolably make it work with a lot of If statements but it feels like I am going around my butt to get to my elbow by doing it that way. ;) I am pretty sure there is an easier way to do it, but I'm a noob. lol I will look at the changes you made and try to make as much sense as I can out of them. Thank you for the help.

Once you have the inputs collected, you can use Select/Case/EndSelect or Switch/Case/EndSwitch to avoid the long string of If/ElseIf statements.

P.S.

Is there any sort of an array tutorial? Been looking for info on arrays but have not found anything that has really made it click yet.

Look into the AutoIt-1-2-3 tutorial in my sig.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...