FaT3oYCG Posted June 25, 2009 Share Posted June 25, 2009 (edited) ok so i have a file that has a list of things that are under a higherarchy and need to be sorted into alphabetical order. the format of each item is either -, --, or --- then 3 or four parts seperated by a . and then on some but not all a () at the end. Example list: -a.a --a.a.a() --a.a.b() --a.a.c() --a.a.d ---a.a.d.a() ---a.a.d.b() -a.b --a.b.a() --a.b.b() --a.b.c() --a.b.d ---a.b.d.a() ---a.b.d.b() etc. for about 17 different sections the problem that i also have is that they need to be put into an array so that each one is held in a variable so that it can be used to populate a menu with the data and for further referencing the item throughout the program. i have tried code with array add etc but i just cant seem to get it to work and i dont think the way i am doing it is the best anyway. Dim $array[1][1][1] $filehandle = FileOpen(@ScriptDir & "\file.txt", 0) If $filehandle <> -1 Then $a = 1 $b = 1 $c = 1 While @error <> -1 If @error <> 1 Then $line = FileReadLine($filehandle) If StringLeft($line, 3) == "---" Then _ArrayAdd($array[$a][$b][$c], StringRight($line, StringLen($line) - 3)) $c += 1 ElseIf StringLeft($line, 2) == "--" Then _ArrayAdd($array[$a][$b][$c], StringRight($line, StringLen($line) - 2)) $b += 1 ElseIf StringLeft($line, 1) == "-" Then _ArrayAdd($array[$a][$b][$c], StringRight($line, StringLen($line) - 1)) $a += 1 Else MsgBox(0, "Error", "Failed to read file, incorrect format") EndIf EndIf WEnd EndIf FileClose($filehandle) any help appreciated. Edited June 25, 2009 by FaT3oYCG Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right. Link to comment Share on other sites More sharing options...
water Posted June 25, 2009 Share Posted June 25, 2009 A hierarchy is best displayed in a TreeView. Here you can find a script to read a file like yours and display it in a TreeView.The coding to populate the input file for the TreeView should be quite simple. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
FaT3oYCG Posted June 25, 2009 Author Share Posted June 25, 2009 i need to put my items into a menu though and looking at that there isnt anything that would help me? Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right. Link to comment Share on other sites More sharing options...
water Posted June 25, 2009 Share Posted June 25, 2009 (edited) The basic problem is, that _ArrayAdd onyl supports 1 dimensional arrays. So you would have to expand the array yourself. This can be done using ReDim $array. Another problem in your script is that when you increment $a you have to reset $b and $c to 1 and so on Edited June 25, 2009 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
FaT3oYCG Posted June 25, 2009 Author Share Posted June 25, 2009 how would i display or read the contents of the array i seem to get an error every time i try. Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right. Link to comment Share on other sites More sharing options...
water Posted June 25, 2009 Share Posted June 25, 2009 I modified my previous posting. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
FaT3oYCG Posted June 25, 2009 Author Share Posted June 25, 2009 after a lot more searching, solution: expandcollapse popup#include <GUIConstants.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> #include <Array.au3> #include <File.au3> Dim $pgeLuaFunctionsArray[1] _FileReadToArray(@ScriptDir & "\PGE Lua Function List.txt", $pgeLuaFunctionsArray) $pgeMenu = GUICtrlCreateMenu("PGE Functions") $level_1 = "" $level_2 = "" $level_3 = "" For $i = 1 To UBound($pgeLuaFunctionsArray) - 1 If StringLeft($pgeLuaFunctionsArray[$i], 3) = "---" Then If StringRight($pgeLuaFunctionsArray[$i], 2) = "()" Then $pgeLuaFunctionsArray[$i] = GUICtrlCreateMenuItem($pgeLuaFunctionsArray[$i], $level_2) Else $pgeLuaFunctionsArray[$i] = GUICtrlCreateMenu($pgeLuaFunctionsArray[$i], $level_2) EndIf $level_3 = $pgeLuaFunctionsArray[$i] ElseIf StringLeft($pgeLuaFunctionsArray[$i], 2) = "--" Then If StringRight($pgeLuaFunctionsArray[$i], 2) = "()" Then $pgeLuaFunctionsArray[$i] = GUICtrlCreateMenuItem($pgeLuaFunctionsArray[$i], $level_1) Else $pgeLuaFunctionsArray[$i] = GUICtrlCreateMenu($pgeLuaFunctionsArray[$i], $level_1) EndIf $level_2 = $pgeLuaFunctionsArray[$i] $level_3 = "" ElseIf StringLeft($pgeLuaFunctionsArray[$i], 1) = "-" Then If StringRight($pgeLuaFunctionsArray[$i], 2) = "()" Then $pgeLuaFunctionsArray[$i] = GUICtrlCreateMenuItem($pgeLuaFunctionsArray[$i], $pgeMenu) Else $pgeLuaFunctionsArray[$i] = GUICtrlCreateMenu($pgeLuaFunctionsArray[$i], $pgeMenu) EndIf $level_1 = $pgeLuaFunctionsArray[$i] $level_2 = "" $level_3 = "" Else MsgBox(0, "Error", "Failed to read function line: " & $i & ", incorrect format") EndIf Next $mainMenu = _GUICtrlMenu_GetMenu($frmMain) $itemPGE = _GUICtrlMenu_GetItemSubMenu($mainMenu, 0) For $i = 0 To 14 $ItemPGESub = _GUICtrlMenu_GetItemSubMenu($itemPGE, $i) _GUICtrlMenu_SetMenuHeight($ItemPGESub, 220) Next GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd cba changing the code it has all of the variable that i used if you cant understand then just change them fore something more relevant. you can just run that code and it will work dont know if some of the headders are needed but they are in my main script. enjoy. Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right. 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