mtmartis 0 Posted August 5, 2011 I am always confused bewtween Dim,local,Global. Basically, I want to run a function that calls a Global variable, but a If-then is used to determine the path of that Global variable. I am guessing even though the global variable gets declared in a If/Then statement, I still can't declare a global variable with the same name twice. And if that is the case, is there a way around this? No matter if the computer name begins with "USA" or not, it always moves the PC to the first $sTargetOU.#include <AD.au3> If StringInStr(@ComputerName,"USA") Then Global $sTargetOU = "OU=1,DC=domain,DC=com" Else Global $sTargetOU = "OU=2,DC=domain,DC=com" EndIf ;Connect to Active Directory _AD_Open() ;Get FQDN of current machine name Global $sObject = _AD_SamAccountNameToFQDN(@ComputerName & "$") ;Move current machine to OU location Global $iValue = _AD_MoveObject($sTargetOU, $sObject) ; Close Connection to the Active Directory _AD_Close()#FYI,he AD functions I am using are by the author, Water, posted here: Share this post Link to post Share on other sites
pieeater 1 Posted August 5, 2011 using StringCompare() might be what your looking for [spoiler]My UDFs: Login UDF[/spoiler] Share this post Link to post Share on other sites
Scriptonize 1 Posted August 5, 2011 You should use it like this: #include <AD.au3> Global $sTargetOU, $sObject, $iValue If StringInStr(@ComputerName,"USA") Then $sTargetOU = "OU=1,DC=domain,DC=com" Else $sTargetOU = "OU=2,DC=domain,DC=com" EndIf ;Connect to Active Directory _AD_Open() ;Get FQDN of current machine name $sObject = _AD_SamAccountNameToFQDN(@ComputerName & "{:content:}quot;) ;Move current machine to OU location $iValue = _AD_MoveObject($sTargetOU, $sObject) ; Close Connection to the Active Directory _AD_Close() If you learn from It, it's not a mistake Share this post Link to post Share on other sites
PsaltyDS 42 Posted August 5, 2011 Your method is awkward, but works fine for me: Global $aStrings[3] = ["USA12345", "12345", "123USA45"] For $n = 0 To UBound($aStrings) - 1 If StringInStr($aStrings[$n], "USA") Then Global $sTargetOU = "OU=1,DC=domain,DC=com" Else Global $sTargetOU = "OU=2,DC=domain,DC=com" EndIf ConsoleWrite($n & ": String = " & $aStrings[$n] & "; $sTargetOU = " & $sTargetOU & @LF) Next This would be a better way to do that check, though: Global $sTargetOU = "OU=1,DC=domain,DC=com" If Not StringInStr(@ComputerName, "USA") Then $sTargetOU = "OU=2,DC=domain,DC=com" 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 Share this post Link to post Share on other sites
mtmartis 0 Posted August 8, 2011 Thanks for the replies, my scripting skills are still pretty raw, it helps to see the proper structure syntax you've all provided. Share this post Link to post Share on other sites
shornw 3 Posted August 8, 2011 Apologies if this is a stupid question....but can you tell me where the _AD stuff is coming from. I dont have AD.au3 in my include folder either. I am currently using V3.3.6.1, which I believe is the latest version. Thanks [font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font] Share this post Link to post Share on other sites
AdmiralAlkex 126 Posted August 8, 2011 Apologies if this is a stupid question....but can you tell me where the _AD stuff is coming from. I dont have AD.au3 in my include folder either. I am currently using V3.3.6.1, which I believe is the latest version.ThanksThere's a link in the first post .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Share this post Link to post Share on other sites