Shonnie Posted March 26, 2008 Posted March 26, 2008 Was hoping that I could use a For loop, but now that I think of it I don't see how I actually could use a For loop. For ever checkbox that is checked, do something associated to that particular box. So, basically I have a nice little GUI, and I have 2 checkboxes. What I would like to do is, when the Button is clicked, it will see how many checkboxes are checked, grab those boxes names, and then stash them in an array Complicated? P.S. Coming back to AutoIt from C++ is like drunk driving
monoceres Posted March 26, 2008 Posted March 26, 2008 I'm getting tired (meaning I'm writing bad code), but here's an easy way #include <GUIConstants.au3> #include <array.au3> Dim $checked[1] Dim $checkboxes[2] Dim $text[2]=["Checkbox 1","Checkbox 2"] GUICreate("Test window",200,100) $button=GUICtrlCreateButton("Click me",1,1) $checkboxes[0]=GUICtrlCreateCheckbox($text[0],1,25) $checkboxes[1]=GUICtrlCreateCheckbox($text[1],1,50) GUISetState() Do $msg=GUIGetMsg() If $msg=$button Then For $i=0 To 1 Step 1 If GUICtrlRead($checkboxes[$i])=$GUI_CHECKED Then _ArrayAdd($checked,$text[$i]) $checked[0]+=1 EndIf Next _ArrayDisplay($checked,"Checked checkboxes") EndIf Until $msg=$GUI_EVENT_CLOSE Broken link? PM me and I'll send you the file!
Shonnie Posted March 26, 2008 Author Posted March 26, 2008 (edited) Egh, yeaaah but the only problem with that is I'm going to have about 500+ checkboxes, or basically one for every "Item Code" found here : http://www.d2help.com/docs/itemcodes.htmSo that's a lot of code. I'll do it this way until I find a better way, thanks much Edit : Also, can I make Tabs inside of Tabs? That would be awesome Edited March 26, 2008 by Shonnie
monoceres Posted March 26, 2008 Posted March 26, 2008 With a bit of modding my code works just fine Just give me a second to fix it Broken link? PM me and I'll send you the file!
monoceres Posted March 26, 2008 Posted March 26, 2008 (edited) Done! This will make a checkbox of every line of text in a textfile named "stuff.txt" expandcollapse popup#include <GUIConstants.au3> #include <array.au3> Dim $text[1] $fhandle=FileOpen("stuff.txt",0) while 1 $temp=FileReadLine($fhandle) If $temp="" Then ExitLoop _ArrayAdd($text,$temp) $text[0]+=1 WEnd Dim $checked[1] Dim $checkboxes[$text[0]+1] GUICreate("Test window",800,600) $button=GUICtrlCreateButton("Click me",1,1) Dim $left=10, $top=35 For $i=1 To $text[0] Step 1 $checkboxes[$i]=GUICtrlCreateCheckbox($text[$i],$left,$top) $checkboxes[0]+=1 $top+=25 If $top>(600-25) Then $top=35 $left+=75 EndIf Next GUISetState() Do $msg=GUIGetMsg() If $msg=$button Then ReDim $checked[1] $checked[0]=0 For $i=1 To $checkboxes[0] Step 1 If GUICtrlRead($checkboxes[$i])=$GUI_CHECKED Then _ArrayAdd($checked,$text[$i]) $checked[0]+=1 EndIf Next _ArrayDisplay($checked,"Checked checkboxes") EndIf Until $msg=$GUI_EVENT_CLOSE Well I'm going to bed now, it's 3:06 AM in Sweden now Edited March 26, 2008 by monoceres Broken link? PM me and I'll send you the file!
Shonnie Posted March 26, 2008 Author Posted March 26, 2008 (edited) Ok, now it gets a little more complicated, and by that I mean, I have to cross reference OTHER checkboxes to affect what THESE checkboxes will have in them Example : 1 checkbox for the Item, 1 checkbox to determine if it's Unique, and then a Dropbox to determine what quality it is. I have messed around a bit, heres my current source : expandcollapse popup#include <GUIConstants.au3> #include <array.au3> Opt("TrayAutoPause", 1);dont pause on tray click $Pickit = "PickItem.lua" $Priority = 10 Global $GoldAmount Dim $sCode[1] _ReadItems(1) Dim $Checked[1] Dim $Checkboxes[$sCode[0] + 1] Dim $CheckboxLeft = 10, $CheckboxTop = 55 $GUI = GUICreate("Awesom-O Pickit Writer", 400, 220, -1, -1, $WS_POPUP+$WS_BORDER) GUISetBkColor(0xFFFFFF) GUICtrlCreateLabel("Awesom-O Pickit Writer", 0, 5, 400, 15, $ES_CENTER, $GUI_WS_EX_PARENTDRAG) $Tab1 = GUICtrlCreateTab(0, 20, 400, 178) $TabSheet1 = GUICtrlCreateTabItem("Home") $TabSheet2 = GUICtrlCreateTabItem("Helms") For $i = 1 To $sCode[0] Step 1 $Checkboxes[$i] = GUICtrlCreateCheckbox($sCode[$i], $CheckboxLeft, $CheckboxTop) $Checkboxes[0] += 1 $CheckboxTop += 20 If $CheckboxTop > (200 - 25) Then $CheckboxTop = 55 $CheckboxLeft += 75 EndIf Next $TabSheet3 = GUICtrlCreateTabItem("Torso") $TabSheet4 = GUICtrlCreateTabItem("Shields") $TabSheet5 = GUICtrlCreateTabItem("Gloves") $TabSheet6 = GUICtrlCreateTabItem("Belts") $TabSheet7 = GUICtrlCreateTabItem("Weapons") $TabSheet8 = GUICtrlCreateTabItem("Class Specific") $TabSheet9 = GUICtrlCreateTabItem("Misc") $GoldLabel = GUICtrlCreateLabel("Gold: ", 10, 60) $GoldInput = GUICtrlCreateInput("1000", 40, 55) ;$Meow = GUICtrlCreateCombo("item1", 10, 60, 120) ;GUICtrlSetData(-1,"item2|item3") GUICtrlCreateTabItem("") $Status = GUICtrlCreateLabel("Ready", 5, 200, 100, 30) GUICtrlSetColor(-1, 0x2B80E6) $Exit = GUICtrlCreateButton("", 375, 200, 22, 17, 0) GUICtrlSetBkColor(-1, 0xFF0000) $Generate = GUICtrlCreateButton("", 350, 200, 22, 17, 0) GUICtrlSetBkColor(-1, 0x00FF00) GUISetState() Do $Msg = GUIGetMsg() Switch $Msg Case $Tab1 $ActiveTab = GUICtrlRead($Tab1) _ReadItems($ActiveTab) Case $Generate ReDim $Checked[1] $Checked[0] = 0 FileDelete($Pickit) _WritePickitStart() For $i = 1 To $Checkboxes[0] Step 1 If GUICtrlRead($Checkboxes[$i]) = $GUI_CHECKED Then $Code = StringRight($sCode[$i], 3) _ArrayAdd($Checked, $Code) _WriteItems($Code) $Checked[0] += 1 EndIf Next _WritePickitEnd() Case $Exit Exit EndSwitch Until $Msg = $GUI_EVENT_CLOSE Func _ReadItems($FileNumber) $Helms = FileOpen("Items/Helms.txt", 0) While 1 $Temp = FileReadLine($Helms) If $Temp = "" Then ExitLoop _ArrayAdd($sCode, $Temp) $sCode[0] += 1 WEnd EndFunc ;==>_ReadItems Func _WritePickitStart();Writes the start and first few lines FileWriteLine($Pickit, "function pickItem(item)");Always starts here $GoldAmount = GUICtrlRead($GoldInput) FileWriteLine($Pickit, ' if item.baseItem.code == "gld" and item.stats[0].Value > ' & $GoldAmount & ' then') FileWriteLine($Pickit, " return " & $Priority) EndFunc ;==>_WritePickit Func _WriteItems($ItemCode);Writes the items individual lines FileWriteLine($Pickit, ' elseif item.baseItem.code == "' & $ItemCode & '" then') FileWriteLine($Pickit, " return " & $Priority) EndFunc ;==>_WriteItems Func _WritePickitEnd();Writes the finish FileWriteLine($Pickit, " end");Always ends here FileWriteLine($Pickit, "end") EndFunc ;==>_WritePickit Also I got a small problem, when it I space my checkboxes some of them get overlayed, which you cant see unless you run it :S Edited March 26, 2008 by Shonnie
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