Jump to content

Scripting Problems


Aceguy
 Share

Recommended Posts

basically, this script listens to a preset key stoke (2). and start the timer. but it has muliple lines, see script.

#include<GUIConstants.au3>
#include<Array.au3>
#include<Misc.au3>


Opt("GUIOnEventMode", 1)


$Form1 = GUICreate("Form1", 266, 74, 312, 456, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$add = GUICtrlCreateButton("Add", 8, 8, 49, 25, 0)
GUIctrlSetOnEvent(-1,"add_row")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$remove = GUICtrlCreateButton("Remove", 64, 8, 49, 25, 0)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$save = GUICtrlCreateButton("Save List", 120, 8, 57, 25, 0)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Combo1 = GUICtrlCreateCombo("Combo1", 8, 40, 73, 25)
GUICtrlSetData(-1, "CTRL|ALT")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Combo2 = GUICtrlCreateCombo("Combo2", 88, 40, 73, 25)
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|0")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$name = GUICtrlCreateInput("name", 184, 8, 73, 21)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Combo3 = GUICtrlCreateCombo("Combo3", 168, 40, 81, 25)
GUICtrlSetData(-1, "10 Secs|15 Secs|30 Secs|45 Secs|1 Min|1 Min 30 secs|2 Mins|3 Min|4 Mins|5 Mins|10 Mins|15 Mins|30 Mins|2 Hrs")
GUICtrlSetResizing(-1, $GUI_DOCKALL)

dim $group_i[1]
dim $Label_i[1]
dim $Input_i[1]
dim $i_key[1]
dim $i_key_a[1]
dim $i_key_b[1]
$bY=0


GUISetState(@SW_SHOW)


While 1
    
    for $c= 0 to $group_i[0]
    if _IsPressed($i_key_a[$c]) and _IsPressed($i_key_b[$c])then
        
        MsgBox(0,"","yay",1)
    EndIf
    Next
    Sleep(100)
WEnd

Func add_row()
If guictrlread($name) <> "name" and GUICtrlRead($Combo1) <> "Combo1" and GUICtrlRead($Combo2) <> "Combo2" and GUICtrlRead($Combo3) <> "Combo3" then
$Ypos = WinGetPos("Form1")

$group_i[0] += 1
$Label_i[0] += 1
$Input_i[0] += 1
$i_key_a[0]+=1
$i_key_b[0]+=1

ReDim $group_i[$group_i[0] + 1]
ReDim $Label_i[$Label_i[0] +1]
ReDim $Input_i[$Input_i[0] +1]
redim $i_key_a[$i_key_a[0] +1]
ReDim $i_key_b[$i_key_b[0]+1]

$group_i[$group_i[0]] = $Group_i = GUICtrlCreateGroup(GUICtrlRead($Combo1)&"+"&GUICtrlRead($Combo2), 8, 72+$bY, 249, 49)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Label_i[$Label_i[0]] = GUICtrlCreateLabel(GUICtrlRead($name), 56, 88+$bY, 125, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Input_i[$Input_i[0]] = GUICtrlCreateInput("", 16, 88+$bY, 33, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
GUICtrlSetBkColor(-1, 0x008000)
GUICtrlSetCursor (-1, 7)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

if GUICtrlRead($Combo1) = "CTRL" then $i_key_a[$i_key_a[0]]=11
if GUICtrlRead($Combo1) = "ALT" then $i_key_a[$i_key_a[0]]=12
if GUICtrlRead($Combo2) = '1' then $i_key_b[$i_key_b[0]]=31
if GUICtrlRead($Combo2) = '2' then $i_key_b[$i_key_b[0]]=32
if GUICtrlRead($Combo2) = '3' then $i_key_b[$i_key_b[0]]=33
if GUICtrlRead($Combo2) = '4' then $i_key_b[$i_key_b[0]]=34
if GUICtrlRead($Combo2) = '5' then $i_key_b[$i_key_b[0]]=35
if GUICtrlRead($Combo2) = '6' then $i_key_b[$i_key_b[0]]=36
if GUICtrlRead($Combo2) = '7' then $i_key_b[$i_key_b[0]]=37
if GUICtrlRead($Combo2) = '8' then $i_key_b[$i_key_b[0]]=38
if GUICtrlRead($Combo2) = '9' then $i_key_b[$i_key_b[0]]=39
if GUICtrlRead($Combo2) = '0' then $i_key_b[$i_key_b[0]]=30
$bY += 55

WinMove("Form1",'',$Ypos[0],$Ypos[1],$Ypos[2],$Ypos[3]+55)
Else
MsgBox(0,"","Boxes not set",0)
EndIf
EndFunc

is there a better way to do this.

or am what im doing not possible.

Edited by Aceguy
Link to comment
Share on other sites

This syntax is wrong:

$group_i[$group_i[0]] = $Group_i = GUICtrlCreateGroup(GUICtrlRead($Combo1)&"+"&GUICtrlRead($Combo2), 8, 72+$bY, 249, 49)oÝ÷ Ø­×hzÉ÷öÙ"rG«®ì¢{2Ö±rËkjxº{.­à!ëbµ8^±ç(Ú)z¶­¢ºÞ¶ê籦è¢WÊ&¥ªÞ¢«jب)í¢Ø^~*쵫­¢+ØÀÌØíôÄ(ÀÌØíôÈ(ÀÌØíôÀÌØíôÀÌØí()
½¹Í½±]É¥Ñ ÅÕ½ÐíÕèÀÌØíôÅÕ½ÐìµÀìÀÌØíµÀìÅÕ½ÐìÀÌØíôÅÕ½ÐìµÀìÀÌØíµÀìÅÕ½ÐìÀÌØíôÅÕ½ÐìµÀìÀÌØíµÀì1

So $c equals the result of comparing $a = $b.

In your script, $group_i[$group_i[0]] is being set to a boolean value returned from comparing $Group_i = CuiCtrlCreateGroup(...). Now $Group_i is an array (AutoIt variable names are not case sensitive) so its value is 0 in a compare, and GuiCtrlCreateGroup() returns a ControlID, so the result of the compare is False (unless GuiCtrlCreateGroup() fails). So you are setting the last element of $group_i to False.

Probably not what you intended!

:D

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

thanks for your reply.

i intended that line to be

$group_i[$group_i[0]] = GUICtrlCreateGroup(GUICtrlRead($Combo1)&"+"&GUICtrlRead($Combo2), 8, 72+$bY, 249, 49)

However, i perfoms really badly, you can set the first one ok, but after that, it all goes horribly wrong.

Link to comment
Share on other sites

thanks for your reply.

i intended that line to be

$group_i[$group_i[0]] = GUICtrlCreateGroup(GUICtrlRead($Combo1)&"+"&GUICtrlRead($Combo2), 8, 72+$bY, 249, 49)

However, i perfoms really badly, you can set the first one ok, but after that, it all goes horribly wrong.

Your For/Next loop is testing the count in [0] as one of the _IsPressed() codes, should start at $c = 1. Tweaked it to make it less annoying to run for testing:

#include<GUIConstants.au3>
#include<Array.au3>
#include<Misc.au3>

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 266, 74, 312, 456)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

GUICtrlSetResizing(-1, $GUI_DOCKALL)
$add = GUICtrlCreateButton("Add", 8, 8, 49, 25, 0)
GUICtrlSetOnEvent(-1, "add_row")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$remove = GUICtrlCreateButton("Remove", 64, 8, 49, 25, 0)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$save = GUICtrlCreateButton("Save List", 120, 8, 57, 25, 0)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Combo1 = GUICtrlCreateCombo("Combo1", 8, 40, 73, 25)
GUICtrlSetData(-1, "CTRL|ALT")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Combo2 = GUICtrlCreateCombo("Combo2", 88, 40, 73, 25)
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|0")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$name = GUICtrlCreateInput("name", 184, 8, 73, 21)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Combo3 = GUICtrlCreateCombo("Combo3", 168, 40, 81, 25)
GUICtrlSetData(-1, "10 Secs|15 Secs|30 Secs|45 Secs|1 Min|1 Min 30 secs|2 Mins" & _
        "|3 Min|4 Mins|5 Mins|10 Mins|15 Mins|30 Mins|2 Hrs")
GUICtrlSetResizing(-1, $GUI_DOCKALL)

Dim $group_i[1]
Dim $Label_i[1]
Dim $Input_i[1]
Dim $i_key[1]
Dim $i_key_a[1]
Dim $i_key_b[1]
$bY = 0

GUISetState(@SW_SHOW)

While 1
    For $c = 1 To $group_i[0]
        If _IsPressed($i_key_a[$c]) And _IsPressed($i_key_b[$c]) Then
            ConsoleWrite("Debug: Triggered on $c = " & $c & "  $i_key_a[$c] = " & $i_key_a[$c] & _
                    " And $i_key_b[$c] = " & $i_key_b[$c] & @LF)
        EndIf
    Next
    Sleep(100)
WEnd

Func add_row()
    If GUICtrlRead($name) <> "name"  And GUICtrlRead($Combo1) <> "Combo1"  And _
            GUICtrlRead($Combo2) <> "Combo2"  And GUICtrlRead($Combo3) <> "Combo3"  Then
        $Ypos = WinGetPos("Form1")

        $group_i[0] += 1
        $Label_i[0] += 1
        $Input_i[0] += 1
        $i_key_a[0] += 1
        $i_key_b[0] += 1

        ReDim $group_i[$group_i[0] + 1]
        ReDim $Label_i[$Label_i[0] + 1]
        ReDim $Input_i[$Input_i[0] + 1]
        ReDim $i_key_a[$i_key_a[0] + 1]
        ReDim $i_key_b[$i_key_b[0] + 1]

        $group_i[$group_i[0]] = GUICtrlCreateGroup(GUICtrlRead($Combo1) & "+" & _
                GUICtrlRead($Combo2), 8, 72 + $bY, 249, 49)
        GUICtrlSetResizing(-1, $GUI_DOCKALL)
        $Label_i[$Label_i[0]] = GUICtrlCreateLabel(GUICtrlRead($name), 56, 88 + $bY, 125, 24)
        GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
        GUICtrlSetResizing(-1, $GUI_DOCKALL)
        $Input_i[$Input_i[0]] = GUICtrlCreateInput("", 16, 88 + $bY, 33, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
        GUICtrlSetBkColor(-1, 0x008000)
        GUICtrlSetCursor(-1, 7)
        GUICtrlSetResizing(-1, $GUI_DOCKALL)

        If GUICtrlRead($Combo1) = "CTRL"  Then $i_key_a[$i_key_a[0]] = "11"
        If GUICtrlRead($Combo1) = "ALT"  Then $i_key_a[$i_key_a[0]] = "12"
        If GUICtrlRead($Combo2) = '1'  Then $i_key_b[$i_key_b[0]] = "31"
        If GUICtrlRead($Combo2) = '2'  Then $i_key_b[$i_key_b[0]] = "32"
        If GUICtrlRead($Combo2) = '3'  Then $i_key_b[$i_key_b[0]] = "33"
        If GUICtrlRead($Combo2) = '4'  Then $i_key_b[$i_key_b[0]] = "34"
        If GUICtrlRead($Combo2) = '5'  Then $i_key_b[$i_key_b[0]] = "35"
        If GUICtrlRead($Combo2) = '6'  Then $i_key_b[$i_key_b[0]] = "36"
        If GUICtrlRead($Combo2) = '7'  Then $i_key_b[$i_key_b[0]] = "37"
        If GUICtrlRead($Combo2) = '8'  Then $i_key_b[$i_key_b[0]] = "38"
        If GUICtrlRead($Combo2) = '9'  Then $i_key_b[$i_key_b[0]] = "39"
        If GUICtrlRead($Combo2) = '0'  Then $i_key_b[$i_key_b[0]] = "30"
        $bY += 55

        WinMove("Form1", '', $Ypos[0], $Ypos[1], $Ypos[2], $Ypos[3] + 55)
    Else
        MsgBox(0, "", "Boxes not set", 0)
    EndIf
EndFunc   ;==>add_row

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:D

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