JoymanyMahn Posted May 8, 2007 Share Posted May 8, 2007 Could someone tell (inexperienced) me how to loop through a set of variables? For example: Lets say I want to delete five Registry values. Rather than repeating the logic five times, could it just loop through $RV1 - $RV5 so the code just has to be written once? $RV1 = ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32") $RV2 = ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs") $RV3 = ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU") $RV4 = ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StreamMRU") $RV5 = ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist") RegRead($RV1,"") If @error Then $RV1_Results = ("Error: Key might not be present: " & $RV1) Else RegDelete ($RV1) If @error Then $RV1_Results = ("Problem with deleting key: " & $RV1) Else $RV1_Results = ("Successfully deleted value: " & $RV1) EndIf EndIf MsgBox(4096, "Results", $RV1_Results,) Any help you could offer this newbie would be appreciated. Thank you. Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 8, 2007 Share Posted May 8, 2007 (edited) Like this: $RV = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\" Dim $avRegKeys[5] = ["ComDlg32", "RecentDocs", "RunMRU", "StreamMRU", "UserAssist") $RV_Results = "" For $n = 0 To 4 RegRead($RV, $avRegKeys[$n]) If @error Then $RV_Results &= "Error: Key might not be present: " & $RV1 & $avRegKeys[$n] & @CRLF Else RegDelete($RV & $avRegKeys[$n]) If @error Then $RV_Results &= "Problem with deleting key: " & $RV & $avRegKeys[$n] & @CRLF Else $RV_Results &= "Successfully deleted value: " & $RV & $avRegKeys[$n] & @CRLF EndIf EndIf Next MsgBox(4096, "Results", $RV_Results) Repeat after me: Arrays are our friends, arrays are our friends, arrays are our friends... Edited May 8, 2007 by PsaltyDS 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 Link to comment Share on other sites More sharing options...
Zedna Posted May 8, 2007 Share Posted May 8, 2007 (edited) Action("ComDlg32") Action("RecentDocs") Action("RunMRU") Action("StreamMRU") Action("UserAssist") Func Action($what) $RV1 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\" & $what RegRead($RV1,"") If @error Then $RV1_Results = ("Error: Key might not be present: " & $RV1) Else RegDelete ($RV1) If @error Then $RV1_Results = ("Problem with deleting key: " & $RV1) Else $RV1_Results = ("Successfully deleted value: " & $RV1) EndIf EndIf MsgBox(4096, "Results", $RV1_Results) EndFuncEDIT: Functions are our friends too Edited May 8, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
JoymanyMahn Posted May 8, 2007 Author Share Posted May 8, 2007 Arrays are indeed our friends! And now, thanks to your great example, Im able to take advantage of that new great friendship. Thanks again! I feel like I am actually starting to get some of this stuff :-) 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