PDowning Posted June 4, 2013 Share Posted June 4, 2013 (edited) You may recognize this from the "looping thru an array" thread from yesterday. Thanks to those that provided a working result. I didn't want to unmark the thread as answered because it technically was answered. Now I am improving the script. Now it will loop thru the array, compare the computer name to the array entries and if they MATCH, then strip the leading character, and run an msi with a new value tacked on the end for a variable. Will this do what I am expecting? Thanks to Firefox and mikell for the code snippets. For $i = 0 to UBound($RoomArray)-1 If $RoomArray[$i] = $RoomNumber Then $sRoomNumb = StringTrimLeft($RoomArray[$i], 1) $RunMSI = "i:\Utilities\Lanschool\Student.msi" ShellExecuteWait($RunMSI, "/passive Channel=",$sRoomNumb) ExitLoop Next Edited June 4, 2013 by PDowning Link to comment Share on other sites More sharing options...
FireFox Posted June 4, 2013 Share Posted June 4, 2013 (edited) You understood the main thing, but there is some mistakes. $RunMSI = "i:\Utilities\Lanschool\Student.msi" For $i = 0 to UBound($RoomArray) -1 If $RoomArray[$i] = $RoomNumber Then $sRoomNumb = StringTrimLeft($RoomArray[$i], 1) ShellExecuteWait($RunMSI, "/passive Channel=" & $sRoomNumb) ExitLoop ;comment this if you want to run all matching MSIs EndIf NextBr, FireFox. Edited June 4, 2013 by FireFox Link to comment Share on other sites More sharing options...
Solution PDowning Posted June 4, 2013 Author Solution Share Posted June 4, 2013 You understood the main thing, but there is some mistakes. $RunMSI = "i:\Utilities\Lanschool\Student.msi" For $i = 0 to UBound($RoomArray) -1 If $RoomArray[$i] = $RoomNumber Then $sRoomNumb = StringTrimLeft($RoomArray[$i], 1) ShellExecuteWait($RunMSI, "/passive Channel=" & $sRoomNumb) ExitLoop ;comment this if you want to run all matching MSIs EndIf Next Br, FireFox. The & ... always forget that little piece of knowledge. Thanks. And why did you pull the msi declaration out of the loop? Just for readability or efficiency? Paul Link to comment Share on other sites More sharing options...
FireFox Posted June 4, 2013 Share Posted June 4, 2013 Efficiency, no need to assign the same thing in your variable.Furthermore, it would be worse if you would declare it in a loop, don't forget to declare all your variables (it's a good coding practice especially to AutoIt).Br, FireFox. Link to comment Share on other sites More sharing options...
PDowning Posted June 6, 2013 Author Share Posted June 6, 2013 (edited) Here I am again with more of this array looping and whatnot. This time I think I have it straight but wanted you wonder-coders to hit me with a hammer if it's not. #include <Array.au3> Local $RoomNumber = StringLeft(@Computername, 3) Local $TeacherString = StringInStr(@ComputerName, "tw") Global $RoomArray[4] = ["E16", "E14", "E25", "W55"] Local $Index = _ArraySearch($RoomArray, $RoomNumber) ;searches the $sToFind in $aRoomArray $RunStudentMSI = "i:\Utilities\Lanschool\Student.msi" $RunTeacherMSI = "i:\Utilities\Lanschool\teacher.msi" If FileExists("C:\Program Files\LanSchool\student.exe") Then ;if file exists, exit script;program already installed Exit Else If $Index = -1 Then ;if not equal to array entries, install Lanschool-Student on Channel 1 ShellExecuteWait($RunStudentMSI, "/passive Channel=1") EndIf EndIf For $i = 0 to UBound($RoomArray)-1 ;Loop thru the roomarray and compare to computername If $RoomArray[$i] = $RoomNumber Then ;if it matches, strip the 1st char, run the msi with the room number appended to $sRoomNumb = StringTrimLeft($RoomArray[$i], 1) ;the channel option ShellExecuteWait($RunStudentMSI, "/passive Channel=" & $sRoomNumb) ExitLoop EndIf Next If FileExists("C:\Program Files\Lanschool\teacher.exe") Then ;if file exists, exit script, program already installed Exit Else If $TeacherString = -1 Then ;if not equal, then run the teacher install with the room number appended ShellExecuteWait($RunTeacherMSI, "/passive channel=" $sRoomNumb) EndIf EndIf It's the last section that I need affirmation on. I want to take the computername, compare and see if the string "TW" is in it, if so, run that msi with the current roomnumber from the array. Edit: I don't mind posting my whole code, nothing secret about it, and no clause in my employment that says anything I come up with is the employers property :-) Edited June 6, 2013 by PDowning Link to comment Share on other sites More sharing options...
FireFox Posted June 6, 2013 Share Posted June 6, 2013 That's almost it. Read carrefuly the helpfile concerning the StringInStr function.Failure: Returns 0 if substring not found.So your wrong line becomes :If $TeacherString = 0 ThenBr, FireFox. Link to comment Share on other sites More sharing options...
PDowning Posted June 10, 2013 Author Share Posted June 10, 2013 (edited) That's almost it. Read carrefuly the helpfile concerning the StringInStr function. Failure: Returns 0 if substring not found. So your wrong line becomes :If $TeacherString = 0 Then Br, FireFox. So by reading the help, then "The count parameter must be longer than the substring being searched for." I need: stringinstr(@computername, 4, 2). but there lies a problem. the Computename is going to be i.e. e16-tw-<serial>. the substring being searched for is "tw", so my count has to be 3? Edit: or Stringinstr(@computername, "tw", 4, 2, 0, 1) ? Edited June 10, 2013 by PDowning Link to comment Share on other sites More sharing options...
FireFox Posted June 10, 2013 Share Posted June 10, 2013 Nope. Read carefully the helpfile. The 3rd parameter is for the case sense, and the maximum value is two. I'm almost sure you don't need the last two parameters for your script. Br, FireFox. Link to comment Share on other sites More sharing options...
PDowning Posted June 10, 2013 Author Share Posted June 10, 2013 Oops, got the numbers in the wrong order ... Stringinstr(@computername, "tw", 0, 1, 4, 2) - corrected string?? Link to comment Share on other sites More sharing options...
FireFox Posted June 10, 2013 Share Posted June 10, 2013 Again your code is incorrect, the last parameter is not the length of your substring (which has no utility here) but the position in the string where the functions stops. Link to comment Share on other sites More sharing options...
PDowning Posted June 10, 2013 Author Share Posted June 10, 2013 Then I'm not understanding fully for some reason, please bear with me. According to the help, my parameters are correct. 0 = casesense(not sensitive), 1 = 1st occurence, 4 = position to start counting, 2 = 2 chars to search after position start. How is that incorrect? And no, I'm not asking for anyone to do it for me, just trying to understand why it's not right. Link to comment Share on other sites More sharing options...
BrewManNH Posted June 10, 2013 Share Posted June 10, 2013 Well for one thing, the substring you're looking for starts at position #5, not 4, so it will never be found. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
FireFox Posted June 10, 2013 Share Posted June 10, 2013 Kind of things I never remember when I do a stringleft/right with stringinstr if I have to add a -1 or not Link to comment Share on other sites More sharing options...
PDowning Posted June 10, 2013 Author Share Posted June 10, 2013 Well for one thing, the substring you're looking for starts at position #5, not 4, so it will never be found. Ahh. I thought it started couting at the position AFTER position 4. Gotcha. Link to comment Share on other sites More sharing options...
mikell Posted June 10, 2013 Share Posted June 10, 2013 Hem, testing the presence or not of the string "tw" is not enough ? Local $TeacherString = StringInStr(@ComputerName, "tw") If not $TeacherString Then ... ; means '= 0' , failure, doesn't match If $TeacherString Then ... ; means '<> 0' , success, matches Link to comment Share on other sites More sharing options...
PDowning Posted June 10, 2013 Author Share Posted June 10, 2013 Hem, testing the presence or not of the string "tw" is not enough ? Local $TeacherString = StringInStr(@ComputerName, "tw") If not $TeacherString Then ... ; means '= 0' , failure, doesn't match If $TeacherString Then ... ; means '<> 0' , success, matches I was going by what the others had said that my stringinstr was incorrect. Link to comment Share on other sites More sharing options...
FireFox Posted June 10, 2013 Share Posted June 10, 2013 (edited) I told you to replace this line :If $TeacherString = -1 ThenBy this one :If $TeacherString = 0 ThenOn the reply #6. Then you gave an incorrect use of StringInStr, I never told that you were using it badly (at least the function itself). Edited June 10, 2013 by FireFox Link to comment Share on other sites More sharing options...
PDowning Posted June 11, 2013 Author Share Posted June 11, 2013 (edited) I told you to replace this line : If $TeacherString = -1 Then By this one :If $TeacherString = 0 Then On the reply #6. Then you gave an incorrect use of StringInStr, I never told that you were using it badly (at least the function itself). I'm still learning this ... I'll get it one day Edited June 11, 2013 by PDowning 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