Legacy99 Posted June 27, 2007 Share Posted June 27, 2007 Hey All, I'm really new at this and maybe I'm going about this the wrong way, I'm hoping someone can help. I'm trying match part of a computers name from an array to the actual computer name and do some task if it matches the department. For example if computer name is dept1-joeblow then reset local password to this, if computername is Site2-johndoe then reset local password to that (the event is irrelevant, it's just an example) Here is what I got $arrDeptCodes = _ArrayCreate("Dept1-", "Dept2-", "Site1-", "Site2-", "core1-", "core2-") For $i = $arrDeptCodes to $arrDeptCodes $n = StringRegExp(@ComputerName, $i) If $n = 1 Then;Gets a Match MsgBox (1, "Match", "Match = " & $i & @ComputerName) Else; No Match MsgBox (1, "No Match", "Not = " & $i & @ComputerName) EndIf Next The problem is that the first dept does not display and it $n gets set to 1 when it should be 0. The rest of the values are always 0. I really can't wrap my head around this one for some reason. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 28, 2007 Moderators Share Posted June 28, 2007 (edited) You need to have an understanding of arrays first. $arrDeptCodes = _ArrayCreate("Dept1-", "Dept2-", "Site1-", "Site2-", "core1-", "core2-")oÝ÷ Øæï¬'+y«^±©Ú®¶²¶¬¢w¡jÎrدyé^éí³Ka® ®¶sdf÷"b33c¶Òb33c¶'$FWD6öFW2Fòb33c¶'$FWD6öFWoÝ÷ Øò¢êeiÇjg¬±¨npØcºËtߦ«¬7©´*zȧܨ» .ÛzØZ¶+b±¹ZK(ÊæÚ²'¬k(§Z+Ó~¢oÝ÷ ÛMúÊ'µ¨§²Ø^rêëz{gºfÞ®íéh¢Ê'jëh×6$arrDeptCodes[6] = ["Dept1-","Dept2-","Site1-","Site2-","core1-","core2-"] For $i = 0 To UBound($arrDeptCodes) - 1 ; UBound contains the number of elements in the 1 dimensional array If StringRegExp(@ComputerName, $arrDeptCodes[$i] & '.+?') Then ; If @ComputerName Contains $arrDeptCodes[ElementNumber] First, and more characters to follow Then MsgBox (1, "Match", "Match = " & $i & @ComputerName) Else; No Match MsgBox (1, "No Match", "Not = " & $i & @ComputerName) EndIf Next I typed this in the reply box, so don't know if there are any mistakes Edit: Damn forum makes nearly impossible to edit CODE!!! Edited June 28, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
weaponx Posted June 28, 2007 Share Posted June 28, 2007 Legacy was pretty close with his own code. $arrDeptCodes = _ArrayCreate("Dept1-", "Dept2-", "Site1-", "Site2-", "core1-", "core2-") For $i in $arrDeptCodes Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 28, 2007 Moderators Share Posted June 28, 2007 Legacy was pretty close with his own code. $arrDeptCodes = _ArrayCreate("Dept1-", "Dept2-", "Site1-", "Site2-", "core1-", "core2-") For $i in $arrDeptCodesNo he wasn't... might want to re-look at the "whole" picture... Changing the method of the loop doesn't make it "close". Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
weaponx Posted June 28, 2007 Share Posted June 28, 2007 What I posted was close to his for loop declaration. I just prefer to use a For In on a one dimensional array. Link to comment Share on other sites More sharing options...
Legacy99 Posted June 28, 2007 Author Share Posted June 28, 2007 Hi guys, Thanks for the input. This is a huge learning curve. I tried both suggestions and came up with this that works, execpt, the pattern is case senstive. The computer name must match the case of the array. For example, if the computer is named dept1- it does not match. How do I overcome that hurdle? $arrDeptCodes = _ArrayCreate("Dept1-", "Dept2-", "Site1-", "Site2-", "core1-", "core2-") $n = 0 For $i = 0 to UBound($arrDeptCodes) -1 $display_dept = $arrDeptCodes[$i] $n = StringRegExp(@ComputerName, $display_dept, 0) If $n = 1 Then MsgBox (1, "Match", "MATCH: N= " & $n & ' computer= ' & @ComputerName & " i= " & $i);This output is for my sanity Else MsgBox (1, "No Match", "NO MATCH: N= " & $n & ' computer= ' & @ComputerName & " i= " & $i);Same here. EndIf Next Link to comment Share on other sites More sharing options...
weaponx Posted June 28, 2007 Share Posted June 28, 2007 #include <Array.au3> $arrDeptCodes = _ArrayCreate("Dept1-", "Dept2-", "Site1-", "Site2-", "core1-", "core2-") For $i in $arrDeptCodes $n = StringRegExp(@ComputerName, "(?i)" & $arrDeptCodes[$i], 0) If $n Then MsgBox (1, "Match", "MATCH: N= " & $n & ' computer= ' & @ComputerName & " i= " & $i);This output is for my sanity ExitLoop EndIf Next If NOT $n Then MsgBox (1, "No Match", "NO MATCH: N= " & $n & ' computer= ' & @ComputerName & " i= " & $i);Same here. Link to comment Share on other sites More sharing options...
Legacy99 Posted June 28, 2007 Author Share Posted June 28, 2007 After talking with a friend about this (Thanks JR) he suggested: $pcname = StringUpper(@ComputerName) $n = StringRegExp($pcname, $display_dept, 0) and replace all the @ComputerName with $pcname. It works for my needs. Thanks guys. Link to comment Share on other sites More sharing options...
Legacy99 Posted June 28, 2007 Author Share Posted June 28, 2007 @weaponx. the [$i] in line $n = StringRegExp(@ComputerName, "(?i)" & $arrDeptCodes[$i], 0) is passing the dept name not the row number so I always get a fail.Tell me if I'm wrong but it would litererally read "test string"=%computername% in the array "arrDeptCodes" @ row Dept1 with pattern Dept1, @ row Dept2 with pattern Dept2, etc. In the msgbox, $i = core2- every time since it's the last in the array. Am I crazy or is that what it's doing? Regardless if I'm crazy, very interesting stuff.Thanks Link to comment Share on other sites More sharing options...
weaponx Posted June 28, 2007 Share Posted June 28, 2007 oops sorry #include <Array.au3> $arrDeptCodes = _ArrayCreate("Dept1-", "Dept2-", "Site1-", "Site2-", "core1-", "core2-") For $i in $arrDeptCodes $n = StringRegExp(@ComputerName, "(?i)" & $i, 0) If $n Then MsgBox (1, "Match", "MATCH: N= " & $n & ' computer= ' & @ComputerName & " i= " & $i);This output is for my sanity ExitLoop EndIf Next If NOT $n Then MsgBox (1, "No Match", "NO MATCH: N= " & $n & ' computer= ' & @ComputerName & " i= " & $i);Same here. Link to comment Share on other sites More sharing options...
Legacy99 Posted June 28, 2007 Author Share Posted June 28, 2007 Hey no worries man, I was just trying to understand what you did, not beat up on you. Thanks for the input. After I seen the edit I should have just looked at it closer and figured it out myself, it makes total sense now so all is not lost. I really want to understand it, not just blindly copy and paste. PS- it does work your way too Link to comment Share on other sites More sharing options...
weaponx Posted June 28, 2007 Share Posted June 28, 2007 No problem. Your previous method was just continuing the loop even if a match was found and I don't think thats what you wanted. If you need any other help aside from the topic I can probably help. 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