gleem Posted June 30, 2006 Share Posted June 30, 2006 (edited) I am trying to search a string for a line... I see that StringInStr is what I want.. however, I went to the example and try running it. it returns the value of ten. am I doing something wrong? $result = StringInStr("I am a String", "RING") MsgBox(0, "Search result:", $result) $location = StringInStr("How much wood could a woodchuch chuch is a woodchuck could chuck wood?", "wood", 0, 3) ; Find the 3rd occurance of "wood" ---- I guess I should reclairfy..... what I want to do is this $varinput = ("user3") $string = ("|user1|user2|user3|user4|user5") I want to create a loop that if user3 is found in string then it tells me about it Edited June 30, 2006 by gleem Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 30, 2006 Moderators Share Posted June 30, 2006 (edited) What are you trying to return? It shows you it starts on the 10 character... Edit:$string = "I am a String" $result = StringInStr($string, "RING") MsgBox(0, "Search result:", StringMid($string, $result)) Edited June 30, 2006 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...
Moderators SmOke_N Posted June 30, 2006 Moderators Share Posted June 30, 2006 I guess I should reclairfy..... what I want to do is this $varinput = ("user3") $string = ("|user1|user2|user3|user4|user5") I want to create a loop that if user3 is found in string then it tells me about it Yeah that makes it clearer: $varinput = ("user3") $string = ("|user1|user2|user3|user4|user5") If StringInStr($string, $varinput) Then MsgBox(64, 'Info:', 'String Was Found') 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...
herewasplato Posted June 30, 2006 Share Posted June 30, 2006 (edited) What are you trying to return? It shows you it starts on the 10 character...in other words: I am a String 123456789^ the word RING starts in the 10th position You would have to add your own MsgBox to see "woodchuck example". Edit:@gleem, I saw that you were posting again - I should have waited for the clarification... but SmOke_N is taking care of you. Edited June 30, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
gleem Posted June 30, 2006 Author Share Posted June 30, 2006 (edited) Hey Smoke.. actually, this has to do with the code modifcation you did for me a while back. This is how the code sits now expandcollapse popup;---------------------------------------------------------------------------------------------------------------------------------- ; SGI Power Station Generator ;---------------------------------------------------------------------------------------------------------------------------------- Func FunctionGenerator() ; Create Message to let user know that Generator is running GUICreate("SGI Power Station Generator", 460, 90) GUICtrlCreateLabel("Please wait while SGI Power Station Everyone List and Target List is being generated.", 30, 20, 580, 200) $progressbar = GUICtrlCreateProgress (10,50,440,20) GUISETSTATE() ; Erase Data In Everyone List and Target List Fileopen($mainpath & "\Data\EveryoneList.txt", 2) FileWrite($mainpath & "\Data\EveryoneList.txt", "") FileClose($mainpath & "\Data\EveryoneList.txt") Fileopen($mainpath & "\Data\TargetList.txt", 2) FileWrite($mainpath & "\Data\TargetList.txt", "") FileClose($mainpath & "\Data\TargetList.txt") $progressbarcount = 1 GUICtrlSetData ($progressbar,$progressbarcount) Sleep(2000) $progressbarcount = 10 GUICtrlSetData ($progressbar,$progressbarcount) Sleep(3000) ; Generate Everyone List $EveryoneListDir = ($mainpath & "\Data") $progressbarcount = 10 GUICtrlSetData ($progressbar,$progressbarcount) ;delete last listing Filedelete(@Tempdir & "\b.tmp") ;gets the computer list and a few other things RunWait(@ComSpec & ' /c net view > ' & @TempDir & '\a.tmp',"", @SW_HIDE) Sleep(300) ;open the file for working $file = FileOpen(@TempDir & "\a.tmp", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "QT - Error", "Unable to open file.") Exit EndIf ;Creates new file in which the result will be written FileOpen(@TempDir & "\b.tmp", 1) ; Read in lines of text until the EOF is reached in file a.tmp While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ;find the string "\\" $result = StringInStr($line,"\\") if $result = 1 Then ;find next blank $blankpos = StringInStr($line," ") ;Find length of line $len = StringLen($line) ;calculate from what position to Trim string to the right $len = $len - $blankpos ;Trim all characters after the computer name $line = StringTrimRight($line, $len) ;Trim the // $line = StringTrimLeft($line,2) ; Re-Trim White Spaces To Right $line = StringStripWS ($line, 2) ;Write to Everyonelist File FileWrite($EveryoneListDir & "\EveryoneList.txt", $line & @CRLF) EndIf GUICtrlSetData ($progressbar,$progressbarcount) $progressbarcount = $progressbarcount + 1 If $progressbarcount > 75 Then $progressbarcount = 75 EndIf Wend FileClose($file) FileDelete(@TempDir & "\a.tmp") Sleep(1000) $progressbarcount = 85 GUICtrlSetData ($progressbar,$progressbarcount) Sleep(2000) $progressbarcount = 90 GUICtrlSetData ($progressbar,$progressbarcount) Sleep(2000) $progressbarcount = 95 GUICtrlSetData ($progressbar,$progressbarcount) ; Compare Everyonelist to White List and Generate Target List Local $WhiteListLocation = $mainpath & '\Data\WhiteList.txt', $EveryoneListLocation = $mainpath & '\Data\EveryoneList.txt' Local $TargetListLocation = $mainpath & '\Data\TargetList.txt' Local $nWhiteArray = '', $nEveryoneArray = '', $aNamesToNotAddSDL = '' If Not _FileReadToArray($WhiteListLocation, $nWhiteArray) Then Exit If Not _FileReadToArray($EveryoneListLocation, $nEveryoneArray) Then Exit For $EveryoneCount = 1 To UBound($nEveryoneArray) - 1 For $WhiteCount = 1 To UBound($nWhiteArray) - 1 If $nEveryoneArray[$EveryoneCount] = $nWhiteArray[$WhiteCount] Then $aNamesToNotAddSDL &= $nEveryoneArray[$EveryoneCount] & Chr(01) EndIf Next Next If $aNamesToNotAddSDL <> '' Then $NameFileOpen = FileOpen($TargetListLocation, 2) If StringInStr($aNamesToNotAddSDL, Chr(01)) Then $aNamesToNotAddSDL = StringSplit(StringTrimRight($aNamesToNotAddSDL, 1), Chr(01)) Local $IsOk = True For $AddCount = 1 To UBound($nEveryoneArray) - 1 For $DontAddCount = 1 To UBound($aNamesToNotAddSDL) - 1 If $nEveryoneArray[$AddCount] = $aNamesToNotAddSDL[$DontAddCount] Then $IsOk = False ExitLoop EndIf Next If $IsOk Then FileWriteLine($TargetListLocation, $nEveryoneArray[$AddCount]) EndIf $IsOk = True Next EndIf FileClose($NameFileOpen) Else $NameFileOpen = FileOpen($TargetListLocation, 2) For $AddCount = 1 To UBound($nEveryoneArray) - 1 FileWriteLine($TargetListLocation, $nEveryoneArray[$AddCount]) Next FileClose($NameFileOpen) EndIf $progressbarcount = 100 GUICtrlSetData ($progressbar,$progressbarcount) EndFunc What I want to change is instead of the list being... name1 name2 name3 name4 I want it to be name1|name2|name3|name4 I am sure you can tell that I am trying to do a gui list item Edited June 30, 2006 by gleem Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 30, 2006 Moderators Share Posted June 30, 2006 Are you trying to do the list for the bad names or good? If I remember right there were 2 lists... anyway... this should give you an idea on how to do it:$Main = GUICreate('Some GUI', 200, 100) $Combo = GUICtrlCreateCombo('', 10, 10, 180, 100) $Button = GUICtrlCreateButton('Populate', 65, 40, 60, 30) GUISetState() While 1 $Msg = GUIGetMsg() Select Case $Msg = - 3 Exit Case $Msg = $Button _PopulateCombo($Combo, WinList()) EndSelect Sleep(10) WEnd Func _PopulateCombo($hwndCTRLID, $vInfo) Local $sStoreForCombo = '' For $iCount = 1 To UBound($vInfo) - 1 If $vInfo[$iCount][0] <> '' Then $sStoreForCombo &= $vInfo[$iCount][0] & '|' ; Here is what you would change, if I used Chr(01), then replace that with '|' Next GUICtrlSetData($hwndCTRLID, $sStoreForCombo) EndFunc 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...
gleem Posted June 30, 2006 Author Share Posted June 30, 2006 Yes.. I have since changed the names... I have it set up so... its now Everyone List | White List | Target List and what its functio is Everyone List - White List = Target List Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 30, 2006 Moderators Share Posted June 30, 2006 Yes.. I have since changed the names... I have it set up so... its nowEveryone List | White List | Target Listand what its functio isEveryone List - White List = Target ListOk, well regardless, you should be able to get the idea of what to do from what I posted. 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...
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