luvmachine Posted June 24, 2006 Posted June 24, 2006 Okay, so my script will change size on the GUI based on how many keys you have in the ini file. Its designed to go up to 20 keys but because I designed it that way it gives me errors saying my subscript dimension has been exceded. If anyone has a clue how to fix the error or atleast tidy up my code so it doesn't have to be so long it would be very much appreciated. expandcollapse popup#include <GuiConstants.au3> $h = 0 $arra = IniReadSection("something.ini", "Programs") $button1 = 0 $button2 = 0 $button3 = 0 $button4 = 0 $button5 = 0 $button6 = 0 $button7 = 0 $button8 = 0 $button9 = 0 $button10 = 0 $button11 = 0 $button12 = 0 $button13 = 0 $button14 = 0 $button15 = 0 $button16 = 0 $button17 = 0 $button18 = 0 $button19 = 0 $button20 = 0 For $a = 1 to $arra[0][0] $h = $h + 1 If $h = 20 Then ExitLoop Next $h = (($h * 34) + 4) GuiCreate("", 100, $h) For $b = 1 to $arra[0][0] Select Case $button1 = 0 $button1 = GuiCtrlCreateButton($arra[1][0], 4, 4, 92, 30) Case $button2 = 0 $button2 = GuiCtrlCreateButton($arra[2][0], 4, 38, 92, 30) Case $button3 = 0 $button3 = GuiCtrlCreateButton($arra[3][0], 4, 72, 92, 30) Case $button4 = 0 $button4 = GuiCtrlCreateButton($arra[4][0], 4, 106, 92, 30) Case $button5 = 0 $button5 = GuiCtrlCreateButton($arra[5][0], 4, 140, 92, 30) Case $button6 = 0 $button6 = GuiCtrlCreateButton($arra[6][0], 4, 174, 92, 30) Case $button7 = 0 $button7 = GuiCtrlCreateButton($arra[7][0], 4, 208, 92, 30) Case $button8 = 0 $button8 = GuiCtrlCreateButton($arra[8][0], 4, 242, 92, 30) Case $button9 = 0 $button9 = GuiCtrlCreateButton($arra[9][0], 4, 276, 92, 30) Case $button10 = 0 $button10 = GuiCtrlCreateButton($arra[10][0], 4, 310, 92, 30) Case $button11 = 0 $button11 = GuiCtrlCreateButton($arra[11][0], 4, 344, 92, 30) Case $button12 = 0 $button12 = GuiCtrlCreateButton($arra[12][0], 4, 378, 92, 30) Case $button13 = 0 $button13 = GuiCtrlCreateButton($arra[13][0], 4, 412, 92, 30) Case $button14 = 0 $button14 = GuiCtrlCreateButton($arra[14][0], 4, 446, 92, 30) Case $button15 = 0 $button15 = GuiCtrlCreateButton($arra[15][0], 4, 480, 92, 30) Case $button16 = 0 $button16 = GuiCtrlCreateButton($arra[16][0], 4, 514, 92, 30) Case $button17 = 0 $button17 = GuiCtrlCreateButton($arra[17][0], 4, 548, 92, 30) Case $button18 = 0 $button18 = GuiCtrlCreateButton($arra[18][0], 4, 582, 92, 30) Case $button19 = 0 $button19 = GuiCtrlCreateButton($arra[19][0], 4, 616, 92, 30) Case $button20 = 0 $button20 = GuiCtrlCreateButton($arra[20][0], 4, 650, 92, 30) EndSelect Next GuiSetState() While 1 $mess = GuiGetMsg() Select Case $mess = $GUI_EVENT_CLOSE Exit Case $mess = $button1 Run($arra[1][1]) Case $mess = $button2 Run($arra[2][1]) Case $mess = $button3 Run($arra[3][1]) Case $mess = $button4 Run($arra[4][1]) Case $mess = $button5 Run($arra[5][1]) Case $mess = $button6 Run($arra[6][1]) Case $mess = $button7 Run($arra[7][1]) Case $mess = $button8 Run($arra[8][1]) Case $mess = $button9 Run($arra[9][1]) Case $mess = $button10 Run($arra[10][1]) Case $mess = $button11 Run($arra[11][1]) Case $mess = $button12 Run($arra[12][1]) Case $mess = $button13 Run($arra[13][1]) Case $mess = $button14 Run($arra[14][1]) Case $mess = $button15 Run($arra[15][1]) Case $mess = $button16 Run($arra[16][1]) Case $mess = $button17 Run($arra[17][1]) Case $mess = $button18 Run($arra[18][1]) Case $mess = $button19 Run($arra[19][1]) Case $mess = $button20 Run($arra[20][1]) EndSelect Wend As for the ini, have it in same folder and named "something.ini" [Programs] prog1 = prog1location prog2 = prog2location prog3 = prog3location
PsaltyDS Posted June 24, 2006 Posted June 24, 2006 Okay, so my script will change size on the GUI based on how many keys you have in the ini file. Its designed to go up to 20 keys but because I designed it that way it gives me errors saying my subscript dimension has been exceded. If anyone has a clue how to fix the error or atleast tidy up my code so it doesn't have to be so long it would be very much appreciated. CODE#include <GuiConstants.au3> $h = 0 $arra = IniReadSection("something.ini", "Programs") $button1 = 0 $button2 = 0 $button3 = 0 $button4 = 0 $button5 = 0 $button6 = 0 $button7 = 0 $button8 = 0 $button9 = 0 $button10 = 0 $button11 = 0 $button12 = 0 $button13 = 0 $button14 = 0 $button15 = 0 $button16 = 0 $button17 = 0 $button18 = 0 $button19 = 0 $button20 = 0 For $a = 1 to $arra[0][0] $h = $h + 1 If $h = 20 Then ExitLoop Next $h = (($h * 34) + 4) GuiCreate("", 100, $h) For $b = 1 to $arra[0][0] Select Case $button1 = 0 $button1 = GuiCtrlCreateButton($arra[1][0], 4, 4, 92, 30) Case $button2 = 0 $button2 = GuiCtrlCreateButton($arra[2][0], 4, 38, 92, 30) Case $button3 = 0 $button3 = GuiCtrlCreateButton($arra[3][0], 4, 72, 92, 30) Case $button4 = 0 $button4 = GuiCtrlCreateButton($arra[4][0], 4, 106, 92, 30) Case $button5 = 0 $button5 = GuiCtrlCreateButton($arra[5][0], 4, 140, 92, 30) Case $button6 = 0 $button6 = GuiCtrlCreateButton($arra[6][0], 4, 174, 92, 30) Case $button7 = 0 $button7 = GuiCtrlCreateButton($arra[7][0], 4, 208, 92, 30) Case $button8 = 0 $button8 = GuiCtrlCreateButton($arra[8][0], 4, 242, 92, 30) Case $button9 = 0 $button9 = GuiCtrlCreateButton($arra[9][0], 4, 276, 92, 30) Case $button10 = 0 $button10 = GuiCtrlCreateButton($arra[10][0], 4, 310, 92, 30) Case $button11 = 0 $button11 = GuiCtrlCreateButton($arra[11][0], 4, 344, 92, 30) Case $button12 = 0 $button12 = GuiCtrlCreateButton($arra[12][0], 4, 378, 92, 30) Case $button13 = 0 $button13 = GuiCtrlCreateButton($arra[13][0], 4, 412, 92, 30) Case $button14 = 0 $button14 = GuiCtrlCreateButton($arra[14][0], 4, 446, 92, 30) Case $button15 = 0 $button15 = GuiCtrlCreateButton($arra[15][0], 4, 480, 92, 30) Case $button16 = 0 $button16 = GuiCtrlCreateButton($arra[16][0], 4, 514, 92, 30) Case $button17 = 0 $button17 = GuiCtrlCreateButton($arra[17][0], 4, 548, 92, 30) Case $button18 = 0 $button18 = GuiCtrlCreateButton($arra[18][0], 4, 582, 92, 30) Case $button19 = 0 $button19 = GuiCtrlCreateButton($arra[19][0], 4, 616, 92, 30) Case $button20 = 0 $button20 = GuiCtrlCreateButton($arra[20][0], 4, 650, 92, 30) EndSelect Next GuiSetState() While 1 $mess = GuiGetMsg() Select Case $mess = $GUI_EVENT_CLOSE Exit Case $mess = $button1 Run($arra[1][1]) Case $mess = $button2 Run($arra[2][1]) Case $mess = $button3 Run($arra[3][1]) Case $mess = $button4 Run($arra[4][1]) Case $mess = $button5 Run($arra[5][1]) Case $mess = $button6 Run($arra[6][1]) Case $mess = $button7 Run($arra[7][1]) Case $mess = $button8 Run($arra[8][1]) Case $mess = $button9 Run($arra[9][1]) Case $mess = $button10 Run($arra[10][1]) Case $mess = $button11 Run($arra[11][1]) Case $mess = $button12 Run($arra[12][1]) Case $mess = $button13 Run($arra[13][1]) Case $mess = $button14 Run($arra[14][1]) Case $mess = $button15 Run($arra[15][1]) Case $mess = $button16 Run($arra[16][1]) Case $mess = $button17 Run($arra[17][1]) Case $mess = $button18 Run($arra[18][1]) Case $mess = $button19 Run($arra[19][1]) Case $mess = $button20 Run($arra[20][1]) EndSelect Wend As for the ini, have it in same folder and named "something.ini" [Programs] prog1 = prog1location prog2 = prog2location prog3 = prog3location You can do this in less code so it will handle any number of programs/buttons from the .ini file: expandcollapse popup#include <GuiConstants.au3> ; $aPrograms = 2D array of programs read from .ini file ; [0][0] = count ; [n][0] = name, and [n][1] = path $aPrograms = IniReadSection("something.ini", "Programs") If @Error Then MsgBox(16, "Error!", "Error reading .ini file! Exiting...") Exit EndIf ; $aButtons = 1D array of button control IDs Dim $aButtons[$aPrograms[0][0]+1] ; Calculate GUI height based on number of buttons $Gui_Ht = (($aPrograms[0][0] * 34) + 4) ; Create GUI and save handle $hGUI = GuiCreate("", 100, $Gui_Ht) ; Create buttons, saving confrol IDs to $aButtons array For $p = 1 to $aPrograms[0][0] $aButtons[$p] = GuiCtrlCreateButton($aPrograms[$p][0], 4, ($p * 34)+4, 92, 30) Next ; Show the GUI GuiSetState() ; Message loop for GUI While 1 $mess = GuiGetMsg() If $mess = $GUI_EVENT_CLOSE Then Exit For $p = 1 to $aPrograms[0][0] If $mess = $aButtons[$p] Then Run($aPrograms[$p][1] ExitLoop EndIf Next Wend I would redo it for event mode if you don't want an annoying flashing effect on your GUI. 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
luvmachine Posted June 25, 2006 Author Posted June 25, 2006 (edited) Thank you so much, I went to reply to say thanks yesterday just after you posted that but my connection here at work flipped out on me. Can't believe I didn't think to use the button variables as an array >.> Again... thanks.. however you had the sweetest of all coding errors. . . the off by 1 -.- $aButtons[$p] = GuiCtrlCreateButton($aPrograms[$p][0], 4, ($p * 34)+4, 92, 30) Should be: $aButtons[$p] = GuiCtrlCreateButton($aPrograms[$p][0], 4, (($p - 1) * 34)+4, 92, 30) Edited June 25, 2006 by luvmachine
PsaltyDS Posted June 25, 2006 Posted June 25, 2006 ...however you had the sweetest of all coding errors. . . the off by 1 -.- $aButtons[$p] = GuiCtrlCreateButton($aPrograms[$p][0], 4, ($p * 34)+4, 92, 30) Should be: $aButtons[$p] = GuiCtrlCreateButton($aPrograms[$p][0], 4, (($p - 1) * 34)+4, 92, 30) Sweet oily fishpaste! Now I have to flog myself 32 times with a strip of whale blubber... let this be a lesson to you: Coffee before code! 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now