Leaderboard
Popular Content
Showing content with the highest reputation on 10/28/2012 in all areas
-
amonkey, That was easier than I thought it would be. Here is a script to order your array as you wish - it should work on unlimited levels: #include <Array.au3> Global $aArray[10][3] = [["01", "Cat01", "0"], ["02", "Cat02", "01"], ["03", "Cat03", "0"], ["04", "Cat04", "03"], ["05", "Cat05", "01"], _ ["06", "Cat06", "05"], ["07", "Cat07", "01"], ["08", "Cat08", "06"], ["09", "Cat09", "04"], ["010", "Cat010", "08"]] ;Create an array to hold the sorted data - we already know the size Global $iCount = UBound($aArray) Global $aSorted_Array[$iCount] ; Now we start a function to run through the array - initially looking for base level entries which will be at level 0 _Find_Level("0", 0, $aSorted_Array) ; And this is what we get when we return _ArrayDisplay($aSorted_Array) Func _Find_Level($sParent, $iLevel, ByRef $aSorted_Array) ; This is the index of the array we will load next Static $iLoad_Index = 0 ; Look for entries that have this parent For $i = 0 To $iCount - 1 If $aArray[$i][2] = $sParent Then ; Found an entry with the correct parent ; Add the required number of "-" $sItem = $aArray[$i][1] For $j = 1 To $iLevel $sItem = "-" & $sItem Next ; And load int into the array - increasing the load index $aSorted_Array[$iLoad_Index] = $sItem $iLoad_Index += 1 ; Now run the function again look for any items that have this item as parent _Find_Level($aArray[$i][0], $iLevel + 1, $aSorted_Array) EndIf Next EndFunc ;==>_Find_LevelAs czardas mentioned above the function is used recursively - if you are not used to doing this, may I recommend reading the Recursion tutorial in the Wiki to find out more. You will also notice that I sized the array before we started. Changing the size of an array (which is what you were doing with _ArrayInsert) uses ReDim which is amazingly slow. So avoiding that function should be done at all costs. You will see that I just kept track of where the next entry should be inserted. Please ask if you have any questions. M231 point
-
Mount ISO by using Autoit ?
MrVietA2 reacted to GordonFreeman for a topic
EZB Topic says 3) Command-line support - A program named isocmd.exe is located in "C:Program FilesUltraISOdrivers" folder, you can use it to mount/unmount ISOs to ISODrive - Print ISODrive letters isocmd -print - Mount command isocmd -mount drive: file_spec Example: isocmd -mount L: "d:isosmycd.iso" - Unmount command isocmd -eject drive: Example: isocmd -eject L: - Change drive letter of ISODrive isocmd -change device# driveLetter: Example: isocmd -change 1 F:1 point -
Try this... Local $image = 'D:Software FullNew folderVS2010Express1.iso'; Disc Image To Load RunWait('C:Program FilesUltraISOdriversIsoCmd.exe -mount F:"' & $image & '"' )1 point
-
Mount ISO by using Autoit ?
MrVietA2 reacted to GordonFreeman for a topic
To run DOS commands, try RunWait(@ComSpec & " /c " & "commandName") ; don't forget " " before "/c"1 point -
Looking for some advice to shorten/cleanup script
Elephant007 reacted to Melba23 for a topic
Elephant007, That is easy (or at least it is when you know how)! In the _WM_COMMAND function (right at the end) change this: Else ; Need only digits $sData = StringUpper(StringRegExpReplace($sData, "[^[:digit:]]", "")) EndIfTo this Else ; Need digits or alpha $sData = StringUpper(StringRegExpReplace($sData, "[^[:alnum:]]", "")) EndIfM231 point -
Looking for some advice to shorten/cleanup script
Elephant007 reacted to Melba23 for a topic
Elephant007, Then I would definitely go for FileInstalling the ini file - then all you need to do to update the various elements would be to amend/overwrite that single file. Delighted I could help - as I said it helped pass a morning when I was confined to my study. Do come back if you run into any problems with it. M231 point -
Looking for some advice to shorten/cleanup script
Elephant007 reacted to Melba23 for a topic
Elephant007, Why do you need to FileInstall the data? Will lots of users be running this? If that is indeed the case then you could always declare the relevant arrays to hold the data within the script itself, like this: Local $aEarlies[4][2] = [[3, 0], _ ["Crockett", 107], _ ["Locust", 117], _ ["Woodson", 125]] For $i = 1 To $aEarlies[0][0] $sEarlies &= "|" & $aEarlies[$i][0] NextIt would mean another code change where we extract the matching computer codename sections, but that is easy to do. What do you think? M231 point -
Looking for some advice to shorten/cleanup script
Elephant007 reacted to Melba23 for a topic
Elephant007, What a nightmare of a script - it must have been one hell of a job to write and will be even worse to update and maintain! Perhaps unsurprisingly, I would do it very differently. Firstly I would put all the required data into an ini file - just save this as "Data.ini" in the same folder as the script: [Campus] Earlies=0 Elementary=0 Middle=0 High=0 Non-Instructional=0 [Earlies] Crockett=107 Locust=117 Woodson=125 [Elementary] Austin=102 Bowie=??? Johnston=113 Martinez=155 Reagan=??? Ward=150 Bassetti=153 Dyess=108 Lee=116 McMurry=080 Taylor=121 Bonham=103 Jackson=112 Long=118 Ortiz=152 [Middle] Clack=047 Madison=044 Craig=048 Mann=045 [High] Abilene=001 Cooper=002 Woodson=008 ATEMS=010 Holland=009 [Non-Instructional] Admin Bldg=201 Planetarium=131 Tech Center=200 Transport=008 Maintenance=251 Purchasing=238 Tech Support=102 Warehouse=238 [Department] Athletics=A Communications=O Fine Arts=N Maintenance=M Bilingual=B Curriculum/Instruction=R Health=H Technology=T Child Nutrition=C Finance/Payroll=F HR/Benefits= R Warehouse=W [Room] Cafe=F Counselor=U Lab=L MILE Cart=M Portable=P Classroom=C Gym=G LRC=R Office=O [User] Admin=A LRC=L Secretary=E Warehouse=W Aide=D Maintenance= M Special Ed=F Band/Music=B Nurses=N Student=S Coach=G Office=o Teacher=T Counselor=C Principals=P Technology=HNow you can easily add, remove or amend the data without having to search for every instance within your script. Now we can write some code which is also a lot easier to maintain and much easier to follow: #region ; Includes #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <ComboConstants.au3> #include <ProgressConstants.au3> #endregion #region ; Setup ; Declare Global variables Global $cButton_Comp, $cButton_Room_Inits, $cProgess_Remote, $cCombo_Type Global $cInput_Comp, $cInput_Room_Inits, $cInput_Remote, $cInput_Name_1 #endregion ; Run function Local $sComputer_Name = Menu01() If @error Then MsgBox(0, "Ooops", "[X] pressed") Else MsgBox(0, "All done", "Renamed to " & $sComputer_Name) EndIf ; Exit Exit Func Menu01() #region ; Read data $sIni = "Data.ini" ; Read the ini section Local $aCampus = IniReadSection($sIni, "Campus") ; Convert into a string to fill the combo Local $sCampus = "" For $i = 1 To $aCampus[0][0] $sCampus &= "|" & $aCampus[$i][0] Next ; And do the same for the other sections Local $aEarlies = IniReadSection($sIni, "Earlies") Local $sEarlies = "" For $i = 1 To $aEarlies[0][0] $sEarlies &= "|" & $aEarlies[$i][0] Next Local $aElementary = IniReadSection($sIni, "Elementary") Local $sElementary = "" For $i = 1 To $aElementary[0][0] $sElementary &= "|" & $aElementary[$i][0] Next Local $aMiddle = IniReadSection($sIni, "Middle") Local $sMiddle = "" For $i = 1 To $aMiddle[0][0] $sMiddle &= "|" & $aMiddle[$i][0] Next Local $aHigh = IniReadSection($sIni, "High") Local $sHigh = "" For $i = 1 To $aHigh[0][0] $sHigh &= "|" & $aHigh[$i][0] Next Local $aNonInstructional = IniReadSection($sIni, "Non-Instructional") Local $sNonInstructional = "" For $i = 1 To $aNonInstructional[0][0] $sNonInstructional &= "|" & $aNonInstructional[$i][0] Next Local $aDepartment = IniReadSection($sIni, "Department") Local $sDepartment = "" For $i = 1 To $aDepartment[0][0] $sDepartment &= "|" & $aDepartment[$i][0] Next Local $aRoom = IniReadSection($sIni, "Room") Local $sRoom = "" For $i = 1 To $aRoom[0][0] $sRoom &= "|" & $aRoom[$i][0] Next Local $aUser = IniReadSection($sIni, "User") Local $sUser = "" For $i = 1 To $aUser[0][0] $sUser &= "|" & $aUser[$i][0] Next #endregion ; Read data #region ; Create GUI ; Create GUI - all items created and hidden until ready Local $hGUI = GUICreate("Test", 500, 560) GUICtrlCreateLabel("Campus Type", 10, 15, 200, 20) $cCombo_Type = GUICtrlCreateCombo("", 10, 40, 200, 20, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, $sCampus) Local $cLabel_Location = GUICtrlCreateLabel("Location", 10, 75, 200, 20) GUICtrlSetState(-1, $GUI_HIDE) Local $cCombo_Location = GUICtrlCreateCombo("", 10, 100, 200, 20, $CBS_DROPDOWNLIST) GUICtrlSetState(-1, $GUI_HIDE) Local $cLabel_Room_Dept = GUICtrlCreateLabel("", 10, 135, 200, 20) GUICtrlSetState(-1, $GUI_HIDE) Local $cCombo_Room_Dept = GUICtrlCreateCombo("", 10, 160, 200, 20, $CBS_DROPDOWNLIST) GUICtrlSetState(-1, $GUI_HIDE) Local $cLabel_Room_Inits = GUICtrlCreateLabel("", 10, 195, 100, 20) GUICtrlSetState(-1, $GUI_HIDE) $cInput_Room_Inits = GUICtrlCreateInput("", 110, 195, 50, 20) GUICtrlSetLimit(-1, 4) GUICtrlSetState(-1, $GUI_HIDE) $cButton_Room_Inits = GUICtrlCreateButton("Accept", 175, 195, 100, 20) GUICtrlSetState(-1, BitOr($GUI_HIDE, $GUI_DISABLE)) Local $cLabel_User = GUICtrlCreateLabel("User", 10, 230, 200, 20) GUICtrlSetState(-1, $GUI_HIDE) Local $cCombo_User = GUICtrlCreateCombo("", 10, 255, 200, 20, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, $sUser) GUICtrlSetState(-1, $GUI_HIDE) Local $cLabel_Comp = GUICtrlCreateLabel("Computer Number", 10, 290, 100, 20) GUICtrlSetState(-1, $GUI_HIDE) $cInput_Comp = GUICtrlCreateInput("", 110, 290, 50, 20) GUICtrlSetLimit(-1, 2) GUICtrlSetState(-1, $GUI_HIDE) $cButton_Comp = GUICtrlCreateButton("Accept", 175, 290, 100, 20) GUICtrlSetState(-1, BitOr($GUI_HIDE, $GUI_DISABLE)) GUIStartGroup() Local $cRadio_Local = GUICtrlCreateRadio(" Local Computer", 10, 380, 200, 20) GUICtrlSetState(-1, $GUI_HIDE) Local $cRadio_Remote = GUICtrlCreateRadio(" Remote Computer", 10, 410, 200, 20) GUICtrlSetState(-1, $GUI_HIDE) $cInput_Remote = GUICtrlCreateInput("", 30, 430, 200, 20) GUICtrlSetState(-1, $GUI_HIDE) $cButton_Remote = GUICtrlCreateButton("Accept", 30, 460, 100, 20) GUICtrlSetState(-1, $GUI_HIDE) Local $sLabel_Checking = GUICtrlCreateLabel("Checking Computer" & @CRLF & "Account Type", 140, 460, 200, 40) GUICtrlSetState(-1, $GUI_HIDE) Local $cButton_Rename = GUICtrlCreateButton("", 260, 380, 200, 100) GUICtrlSetState(-1, $GUI_HIDE) Local $cLabel_Remote = GUICtrlCreateLabel("", 10, 500, 480, 20) GUICtrlSetState(-1, $GUI_HIDE) $cProgess_Remote = GUICtrlCreateProgress(10, 530, 480, 20, $PBS_MARQUEE) GUICtrlSendMsg(-1, $PBM_SETMARQUEE, True, 50) GUICtrlSetState(-1, $GUI_HIDE) ; These are created last as we never want to hide them GUICtrlCreateLabel("Computer Name", 10, 340, 100, 20) GUICtrlCreateLabel("-", 150, 340, 10, 20) GUICtrlCreateLabel("-", 180, 340, 10, 20) GUICtrlCreateLabel("-", 260, 340, 10, 20) $cInput_Name_1 = GUICtrlCreateInput("", 110, 340, 40, 20, $ES_READONLY) $cInput_Name_2 = GUICtrlCreateInput("", 160, 340, 20, 20, $ES_READONLY) $cInput_Name_3 = GUICtrlCreateInput("", 190, 340, 70, 20, $ES_READONLY) $cInput_Name_4 = GUICtrlCreateInput("", 270, 340, 20, 20, $ES_READONLY) $cInput_Name_5 = GUICtrlCreateInput("", 290, 340, 40, 20, $ES_READONLY) GUISetState() #endregion ; Register the input change message to control what happen in the inputs GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") #region ;Main loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) Return SetError(1, 0, 0) Case $cCombo_Type ; Hide all lower level controls _Clear_All_Below($cLabel_Room_Dept, 0) ; Show the next level down GUICtrlSetState($cLabel_Location, $GUI_SHOW) GUICtrlSetState($cCombo_Location, $GUI_SHOW) ; Set the next combo depending on what was selected Switch GUICtrlRead($cCombo_Type) Case "Earlies" GUICtrlSetData($cCombo_Location, $sEarlies) Case "Elementary" GUICtrlSetData($cCombo_Location, $sElementary) Case "Middle" GUICtrlSetData($cCombo_Location, $sMiddle) Case "High" GUICtrlSetData($cCombo_Location, $sHigh) Case "Non-Instructional" GUICtrlSetData($cCombo_Location, $sNonInstructional) EndSwitch Case $cCombo_Location ; Hide all lower level controls _Clear_All_Below($cLabel_Room_Inits, 0) ; Show the next level down GUICtrlSetState($cLabel_Room_Dept, $GUI_SHOW) GUICtrlSetState($cCombo_Room_Dept, $GUI_SHOW) ; Read the combos $sLocation = GUICtrlRead($cCombo_Location) $sType = GUICtrlRead($cCombo_Type) ; Fill in the computer name section by reading the ini file by reading the ini file GUICtrlSetData($cInput_Name_1, IniRead($sIni, $sType, $sLocation, "###")) ; Set the next combo depending on what was selected Switch $sType Case "Non-Instructional" GUICtrlSetData($cLabel_Room_Dept, "Department") GUICtrlSetData($cCombo_Room_Dept, $sDepartment) Case Else GUICtrlSetData($cLabel_Room_Dept, "Room Type") GUICtrlSetData($cCombo_Room_Dept, $sRoom) EndSwitch Case $cCombo_Room_Dept ; Hide all lower level controls _Clear_All_Below($cLabel_Room_Inits, 1) ; Show the next level down GUICtrlSetState($cLabel_Room_Inits, $GUI_SHOW) GUICtrlSetState($cInput_Room_Inits, $GUI_SHOW) GUICtrlSetData($cInput_Room_Inits, "") GUICtrlSetState($cButton_Room_Inits, $GUI_SHOW) ; Read the combo $sRoom_Dept = GUICtrlRead($cCombo_Room_Dept) ; Depending on selection Switch $sType Case "Non-Instructional" ; Fill in the computer name section by reading the ini file GUICtrlSetData($cInput_Name_2, IniRead($sIni, "Department", $sRoom_Dept, "###")) GUICtrlSetData($cLabel_Room_Inits, "User Initials") Case Else ; Fill in the computer name section by reading the ini file GUICtrlSetData($cInput_Name_2, IniRead($sIni, "Room", $sRoom_Dept, "###")) GUICtrlSetData($cLabel_Room_Inits, "Room Number") EndSwitch ; Set focus on the input GUICtrlSetState($cInput_Room_Inits, $GUI_FOCUS) Case $cButton_Room_Inits ; Fill in the computer name section by reading the input GUICtrlSetData($cInput_Name_3, GUICtrlRead($cInput_Room_Inits)) GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE) ; Show the next level down GUICtrlSetState($cLabel_User, $GUI_SHOW) GUICtrlSetState($cCombo_User, $GUI_SHOW) Case $cCombo_User ; Hide all lower level controls _Clear_All_Below($cLabel_Comp, 3) ; Show the next level down GUICtrlSetState($cLabel_Comp, $GUI_SHOW) GUICtrlSetState($cInput_Comp, $GUI_SHOW) GUICtrlSetData($cInput_Comp, "") GUICtrlSetState($cButton_Comp, $GUI_SHOW) ; Read the combo $sUser = GUICtrlRead($cCombo_User) ; Fill in the computer name section by reading the ini file GUICtrlSetData($cInput_Name_4, IniRead($sIni, "User", $sUser, "###")) ; Set focus to the input GUICtrlSetState($cInput_Comp, $GUI_FOCUS) Case $cButton_Comp ; Fill in the computer name section by reading the input GUICtrlSetData($cInput_Name_5, GUICtrlRead($cInput_Comp)) GUICtrlSetState($cButton_Comp, $GUI_DISABLE) ; Show the next level down GUICtrlSetState($cRadio_Local, $GUI_SHOW) GUICtrlSetState($cRadio_Remote, $GUI_SHOW) Case $cRadio_Local ; Hide other Rename controls _Clear_All_Below($cInput_Remote) $sName = GUICtrlRead($cInput_Name_1) & "-" & GUICtrlRead($cInput_Name_2) & "-" & GUICtrlRead($cInput_Name_3) & "-" & GUICtrlRead($cInput_Name_4) & GUICtrlRead($cInput_Name_5) GUICtrlSetData($cButton_Rename, "Change Local Name Now!") ; Show the Rename button GUICtrlSetState($cButton_Rename, $GUI_SHOW) Case $cRadio_Remote ; Hide other Rename controls _Clear_All_Below($cInput_Remote) ; Show the required controls GUICtrlSetState($cInput_Remote, BitOr($GUI_SHOW, $GUI_FOCUS)) GUICtrlSetData($cInput_Remote, "") GUICtrlSetState($cButton_Remote, $GUI_SHOW) Case $cButton_Remote GUICtrlSetState($cLabel_Remote, $GUI_SHOW) ;RunWait("Notepad.exe") GUICtrlSetData($cButton_Rename, "Change Remote Name Now!") ; Show the Rename button GUICtrlSetState($cButton_Rename, $GUI_SHOW) Case $cButton_Rename If GUICtrlRead($cRadio_Local) = 1 Then ; Code to rename MsgBox(0, "Local", "Renaming to: " & $sName) Else ; Show label and progress GUICtrlSetState($cLabel_Remote, $GUI_SHOW) GUICtrlSetState($cProgess_Remote, $GUI_SHOW) ; Code to rename MsgBox(0, "Remote", "Renaming to:" & $sName) EndIf ; Exit GUIDelete($hGUI) Return($sName) EndSwitch WEnd #endregion EndFunc Func _Clear_All_Below($cCID, $iIndex = 5) ; Force the "Accept" buttons to disabled GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE) GUICtrlSetState($cButton_Comp, $GUI_DISABLE) ; Hode all controls after the one passed For $i = $cCid To $cProgess_Remote GUICtrlSetState($i, $GUI_HIDE) Next ; Empty the computer name inputs as required For $i = $iIndex To 4 GUICtrlSetData($cInput_Name_1 + $i, "") Next EndFunc ;==>_Clear_All_Below Func _WM_COMMAND($hWnd, $MsgID, $wParam, $lParam) Local $nID = BitAND($wParam, 0xFFFF) Local $nNotifyCode = BitShift($wParam, 16) ; Has the input changed If $nNotifyCode = $EN_CHANGE Then Switch $nID Case $cInput_Room_Inits $sData = GUICtrlRead($cInput_Room_Inits) If GUICtrlRead($cCombo_Type) = "Non-Instructional" Then ; Need only uppercase alpha $sData = StringUpper(StringRegExpReplace($sData, "[^[:alpha:]]", "")) Else ; Need only digits $sData = StringUpper(StringRegExpReplace($sData, "[^[:digit:]]", "")) EndIf GUICtrlSetData($cInput_Room_Inits, $sData) ; And we need 4 of them If StringLen($sData) = 4 Then ; Enable button GUICtrlSetState($cButton_Room_Inits, $GUI_ENABLE) Else ; Disable button GUICtrlSetState($cButton_Room_Inits, $GUI_DISABLE) EndIf Case $cInput_Comp ; Need 2 digits only $sData = GUICtrlRead($cInput_Comp) $sData = StringRegExpReplace(GUICtrlRead($cInput_Comp), "[^[:digit:]]", "") GUICtrlSetData($cInput_Comp, $sData) If StringLen($sData) = 2 Then GUICtrlSetState($cButton_Comp, $GUI_ENABLE) Else GUICtrlSetState($cButton_Comp, $GUI_DISABLE) EndIf Case $cInput_Remote ; No idea what you want here EndSwitch EndIf EndFuncThis gives me the same results as your script when I test it - although I have not been through every possible combination. I have commented the script liberally so I hope you can follow it without problem, but please do ask if you have any questions. And thanks for filling in an empty morning while the wife had friends around for coffee. M231 point -
Looking for some advice to shorten/cleanup script
Elephant007 reacted to PlayHD for a topic
Use a GuiCtrlSetOnEvent Example : http://pastebin.com/ZpgUWCr71 point -
Looking for some advice to shorten/cleanup script
Elephant007 reacted to PhoenixXL for a topic
your code is really very badly written [never mind] never use radio or checkboxes to fire an event, use a button instead In your case the button gets greyed before even using1 point