ahmet Posted May 13, 2011 Share Posted May 13, 2011 Yes , you do, because until you have two loops and until you don't exit second one nothing from inside first one is happening or you ca use a new variable.Take a look here managing multiple GUIs Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 13, 2011 Author Share Posted May 13, 2011 (edited) Thanks, that will definately come in handy! Could you help me with creating another array from 'IniReadSection'? In my config i have a 'load' option where i need to get the values from the named section(in this case the preset title) and then set each controls value with the relevant data..[Loaded from the menu created in the previous array you helped me with] (i'm most likely going to add quite a bit more later on as I start finalizing the config..) [Menu>Preset 1] Section example: [Preset 1] Adapter=Local Area Connection IPAddress=1.1.1.1 SubnetMask=2.2.2.2 DefaultGateway=3.3.3.3 PreferredDNS=4.4.4.4 AlternateDNS=5.5.5.5 Would i be able to reference to the 'key=value' in each case? or is it simpler to keep it attached to the 'array index'? Edited May 13, 2011 by katoNkatoNK Link to comment Share on other sites More sharing options...
ahmet Posted May 13, 2011 Share Posted May 13, 2011 (edited) Check my first post. _ArrayDisplay might help you to better understand arrays. Edited May 13, 2011 by ahmet Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 13, 2011 Author Share Posted May 13, 2011 I've managed to do the array but ran into another problem What check can i add to this code, to avoid the error of the element being a 'non-array' element or having no subscripts if the entry doesn't exist? I get the error on $sRead[2]~ to [6]~ if they aren't in the file. Func Load_pX() Local $sRead GUICtrlSetData($pTitle, $pReadx) $sRead = IniReadSection($sFile, $pReadx) If FileExists($sFile) Then If IsArray($sRead) Then If $sRead[1][0] = "Adapter" Then GUICtrlSetData($aTitle, $sRead[1][1]) EndIF If $sRead[2][0] = "IPAddress" Then _GUICtrlIPAddress_Set($IP_ADDRESS, $sRead[2][1]) EndIf If $sRead[3][0] = "SubnetMask" Then _GUICtrlIPAddress_Set($SUBNET_MASK, $sRead[3][1]) EndIf If $sRead[4][0] = "DefaultGateway" Then _GUICtrlIPAddress_Set($DEFAULT_GATEWAY, $sRead[4][1]) EndIf If $sRead[5][0] = "PreferredDNS" Then _GUICtrlIPAddress_Set($PREFERRED_DNS, $sRead[5][1]) EndIf If $sRead[6][0] = "AlternateDNS" Then _GUICtrlIPAddress_Set($ALTERNATE_DNS, $sRead[6][1]) EndIf Else MsgBox(0, "Preset Read Error!", "The selected preset could not be found!") EndIf EndIf Endfunc Link to comment Share on other sites More sharing options...
ahmet Posted May 14, 2011 Share Posted May 14, 2011 IsArray only checks if variable is a string. If key(s) are missing from section the array size changes.You can use UBound to check size of an array, but I suggest using IniRead to read a key value from a section. Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 20, 2011 Author Share Posted May 20, 2011 Hi again Everything has been working great up till now.. The list is loaded without any problems, but if i add another [section] to the ini, it adds it BUT instead of just adding the new [section] it re-adds the existing presets again.. Here's the final part of my script for the menu-array: Global $sFile = @ScriptDir & "\LazyIP.inc" Global $pRead = IniReadSectionNames($sFile) Global $pReadx, $pReadt Global $pX_gui[2] = [9999, 9999] Global $pX_tray[2] = [9999, 9999] Global $pX_dList[2] = [9999, 9999] Global $pX_List[2] = [9999, 9999] Global $pX_Current, $pX_New, $pX_Last From the function: If FileExists($sFile) Then If IsArray($pRead) Then _Get_pX($sFile) Else If MsgBox(1, "Preset Read Error!", "No existing presets for this config were found!" & @CRLF & @CRLF & "Open 'New Preset' dialog?") = 1 Then _NewPreset() EndIf EndIf EndIf From the function's 'While 1': If FileExists($sFile) Then If IsArray($pRead) Then $pX_Current = IniReadSectionNames($sFile) $pX_New = "" For $i = 1 To $pX_Current[0] $pX_New = $pX_New & $pX_Current[$i] Next If $pX_New <> $pX_Last Then _Get_pX($sFile) EndIf EndIf EndIf Func _Get_pX($sFile) ;Get available/existing presets from source file ~ Set in preset menu. If FileExists($sFile) Then If IsArray($pRead) Then Global $pX_gui[$pRead[0] + 1] Global $pX_tray[$pRead[0] + 1] Global $pX_dList[$pRead[0] + 1] Global $pX_List[$pRead[0] + 1] For $i = 0 To UBound($pX_gui) - 1 GUICtrlDelete($pX_gui[$i]) Next For $i = 0 To UBound($pX_tray) - 1 TrayItemDelete($pX_tray[$i]) Next For $i = 0 To UBound($pX_dList) - 1 GUICtrlDelete($pX_dList[$i]) Next For $i = 0 To UBound($pX_List) - 1 GUICtrlDelete($pX_List[$i]) Next $pRead = IniReadSectionNames($sFile) For $i = 1 To $pRead[0] $pX_gui[$i] = GUICtrlCreateMenuItem($pRead[$i], $pLoad) $pX_tray[$i] = TrayCreateItem($pRead[$i], $tPreset) $pX_dList[$i] = GUICtrlSetData($DeleteName, $pRead[$i]) $pX_List[$i] = GUICtrlSetData($ToPreset, $pRead[$i]) Next $pX_Last = "" For $i = 1 To $pRead[0] $pX_Last = $pX_Last & $pRead[$i] Next EndIf EndIf EndFunc ;==>Get_pX Link to comment Share on other sites More sharing options...
ahmet Posted May 20, 2011 Share Posted May 20, 2011 In the function _Get_pX() you (re)declare $pX_gui and pX_tray arrays and their values are reseted so guictrldelete() and TrayItemDelete() do not delete anything. Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 20, 2011 Author Share Posted May 20, 2011 (edited) Mm..strange lol It was working a few days ago, but even with the 'List' & 'dList' having the same setup they're working fine when updating.. I'm not too sure what you mean, are you talking about the 'Global' declare? I used your example without changing anything, except adding more menu's.. Edited May 20, 2011 by katoNkatoNK Link to comment Share on other sites More sharing options...
ahmet Posted May 20, 2011 Share Posted May 20, 2011 Yes, I am talking about 'Global' declare. First you need to delete MenuItems and then redeclare variables. Just put your first two for loops before the Global declarations. I think that it should fix things. Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 20, 2011 Author Share Posted May 20, 2011 ye knew it was going to fix it even before trying , thanks for pointing it out Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 23, 2011 Author Share Posted May 23, 2011 Hi ahmet I'm having a problem differentiating between arrays when clicking on the 'array' from the MenuItem.. Case $pX_gui[1] To $pX_gui[UBound($pX_gui) - 1] ;~some action Case $pX_dList[1] To $pX_dList[UBound($pX_dList) - 1] ;~some action The items load fine, except they overlap ($px_gui's array fills both MenuItem's, and if i remove $px_gui's list then $px_dlist's items fill both the menu's) I've tried having them read from different variables '=GUICtrlRead($msg, 1)' which didn't work.. (It's the same layout as my previous problem but with all the 'Global' declared after the 'For..Next') And this line: $pX_dList[$i] = GUICtrlCreateMenuItem($pRead[$i], $pDelete) Thanks in advance Link to comment Share on other sites More sharing options...
ahmet Posted May 23, 2011 Share Posted May 23, 2011 What is $px_dlist? I do not understand you good. If you can put some code because I can not even guess or try to explain better. Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 23, 2011 Author Share Posted May 23, 2011 Thats the only line i've changed, and then also put the 'Global' declare after the 'For..Next loops' All the rest is the same as i posted in In short, the gui seems to have trouble telling the difference between these two: Case $pX_gui[1] To $pX_gui[UBound($pX_gui) - 1] ;~some action Case $pX_dList[1] To $pX_dList[UBound($pX_dList) - 1] ;~some action Link to comment Share on other sites More sharing options...
ahmet Posted May 24, 2011 Share Posted May 24, 2011 pX_dList array doesn't contain control IDs. It contains return value from GUICtrlSetData which can be -1, 0, 1, so you shpuld remove the Case with this array from Switch statement. Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 24, 2011 Author Share Posted May 24, 2011 (edited) Ok, then pX_gui wouldn't work either?I placed a msgbox to test it and displays the menuitem that i clicked on fine..(but 'pX_gui's msgbox displays when i click on 'pX_dList' - the right text but not the right menu..)So u'r saying, that these case statements:Case $pX_gui[1] To $pX_gui[UBound($pX_gui) - 1] ;~some action Case $pX_dList[1] To $pX_dList[UBound($pX_dList) - 1] ;~some actiondon't point to these handles created?For $i = 1 To $pRead[0] $pX_gui[$i] = GUICtrlCreateMenuItem($pRead[$i], $pLoad) $pX_dList[$i] = GUICtrlCreateMenuItem($pRead[$i], $pDelete) NextIt was reading 'pX_gui' without any problems before i added, 'pX_dList'.I've tried 'GUIGetMsg(1)' but doesn't seem to work..and i'm not sure what else can be used. Edited May 24, 2011 by katoNkatoNK Link to comment Share on other sites More sharing options...
ahmet Posted May 24, 2011 Share Posted May 24, 2011 Try creating different loops for each array. Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 24, 2011 Author Share Posted May 24, 2011 solved, thank you Link to comment Share on other sites More sharing options...
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