Guest bhartness Posted January 28, 2005 Share Posted January 28, 2005 I have a file that I want to _FileReadToArray... then I want to search the array for a string. I cannot figure how to search the array. This can't be that hard... but I am a newbie . If there is a better way to do this, I am open for suggestions. Thanks for any help. Link to comment Share on other sites More sharing options...
ioliver Posted January 28, 2005 Share Posted January 28, 2005 For $x = 1 to $aRecords[0] $location = StringInStr($aRecord[$x], "SEARCHSTRING" Next - SEARCHSTRING would be what you are searching for in the Array. - In the 'For $x = 1 to $aRecords[0]' the $aRecords[0] = the number of elements in the array. I hope this helps, Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF Link to comment Share on other sites More sharing options...
Blue_Drache Posted January 28, 2005 Share Posted January 28, 2005 (edited) For $x = 1 to $aRecords[0] $location = StringInStr($aRecord[$x], "SEARCHSTRING" Next- SEARCHSTRING would be what you are searching for in the Array.- In the 'For $x = 1 to $aRecords[0]' the $aRecords[0] = the number of elements in the array.I hope this helps,Ian<{POST_SNAPBACK}>StringInStr() returns the POSITION of the "SEARCHSTRING"StringMid($aRecord[$x],$location,$number) will return the acutal text.where $number is the number of characters after the starting position ($location) that you want.[edit='Blue Drache'] Ok, a better way would be to use it like this...Func _ReadArray(ByRef $arecords) Local $x, $location For $x = 1 to $aRecords[0] $location = StringInStr($aRecord[$x], "SEARCHSTRING" If not $location = "" then Return $aRecords[$x] ExitLoop Else Return 0 EndIf Next EndFunc[/edit] Edited January 28, 2005 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
Guest bhartness Posted January 28, 2005 Share Posted January 28, 2005 ... and I will just humbly say "Thank you"! Link to comment Share on other sites More sharing options...
trids Posted January 31, 2005 Share Posted January 31, 2005 The answers above all tell you exactly where the string is, if it's found. But if you're just interested to know whether or not it's in the file .. then there are a few other alternatives that may be quicker, at the expense of knowing the address of the string: This may be useful to check a logfile for error-codes, say, where you don't need to interpret the results other than to flag that there was an error.Also, depending on the size of the file, the sample in the Wiki may in fact prove to be faster. Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted April 1, 2005 Share Posted April 1, 2005 I have a similar problem. I'm creating a program that will give me an alert several minutes before the end of the class period. I have the bell schedule in a separate au3 file that will be included, but i need to search the array for the element that is closest to the current time, but greater than (i.e. if its 8:10 i want 9:15 or 8:50) Here's the bell schedule: expandcollapse popupSelect Case @WDAY = 2 OR @WDAY = 3 Dim $bells[6][3] $bells[0][0] = "1st/2nd Period" $bells[0][1] = 8 $bells[0][2] = 50 $bells[1][0] = "Advisor" $bells[1][1] = 9 $bells[1][2] = 15 $bells[2][0] = "3rd/4th Period" $bells[2][1] = 10 $bells[2][2] = 50 $bells[3][0] = "5th Period" $bells[3][1] = 12 $bells[3][2] = 05 $bells[4][0] = "2nd Lunch" $bells[4][1] = 12 $bells[4][2] = 40 $bells[5][0] = "6th/7th Period" $bells[5][1] = 2 $bells[5][2] = 15 Case @WDAY = 4 Dim $bells[7][3] $bells[0][0] = "1st Period" $bells[0][1] = 8 $bells[0][2] = 09 $bells[1][0] = "2nd Period" $bells[1][1] = 9 $bells[1][2] = 03 $bells[2][0] = "3rd Period" $bells[2][1] = 9 $bells[2][2] = 57 $bells[3][0] = "4th Period" $bells[3][1] = 10 $bells[3][2] = 51 $bells[4][0] = "6th Period" $bells[4][1] = 11 $bells[4][2] = 45 $bells[5][0] = "2nd Lunch" $bells[5][1] = 12 $bells[5][2] = 20 $bells[6][0] = "7th Period" $bells[6][1] = 1 $bells[6][2] = 15 Case @WDAY = 5 OR @WDAY = 6 Dim $bells[8][3] $bells[0][0] = "1st Period" $bells[0][1] = 8 $bells[0][2] = 10 $bells[1][0] = "2nd Period" $bells[1][1] = 9 $bells[1][2] = 05 $bells[2][0] = "3rd Period" $bells[2][1] = 10 $bells[2][2] = 00 $bells[3][0] = "4th Period" $bells[3][1] = 10 $bells[3][2] = 55 $bells[4][0] = "5th Period" $bells[4][1] = 11 $bells[4][2] = 55 $bells[5][0] = "2nd Lunch" $bells[5][1] = 12 $bells[5][2] = 25 $bells[6][0] = "6th Period" $bells[6][1] = 1 $bells[6][2] = 20 $bells[7][0] = "7th Period" $bells[7][1] = 2 $bells[7][2] = 15 EndSelect Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) Link to comment Share on other sites More sharing options...
Blue_Drache Posted April 1, 2005 Share Posted April 1, 2005 (edited) I have a similar problem. I'm creating a program that will give me an alert several minutes before the end of the class period. I have the bell schedule in a separate au3 file that will be included, but i need to search the array for the element that is closest to the current time, but greater than (i.e. if its 8:10 i want 9:15 or 8:50)Here's the bell schedule: <snip><{POST_SNAPBACK}>Ok, in this case you'll want to match up the current hour (@hour) with your second array element, and then add one to the array counter, unless it's lunch. We'll take the first select/case example and loop it. Good job on keeping the format consistant. With the Hour being in the same location in the array makes for a simple two dimensional loop.$hour = @hour If $hour = 0 then $hour = 12 If $hour > 12 then $hour = $hour - 12 ;;; @hour is always returned in a 24 hour format, numbered from 0 to 23. For $x = 0 to 5 step 1 If $hour = 12 then ContinueLoop For $y = 0 to 2 step 1 If $hour = $bells[$x][$y] then Msgbox(0,"test",$bells[($x+1)][$y] & ":" & $bells[($x+1)][($y+1)]) Next NextHope that puts you on the right track.Edit: Added the skip for lunch. If you want to show the lunch times, just remove or remark out the continueloop line. Edited April 1, 2005 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted April 1, 2005 Share Posted April 1, 2005 (edited) Thanks, that nearly gets it, but I just ran it, and instead of spitting out the one for the end of 5th period (which comes up soon ), it gave lunch, so I'll have to factor in minutes as well, looking for one where it is the same hour, and then check to see if the current minutes is less than the one in the array.Much better than I was thinking, I was complicating the hell out of it Oh, can you explain this line to me, I don't see the purpose (oh, I'm stuck in the most boring class right now, $brain function = 0). Nevermind, I missed that comment about the skipping lunch, I was just going crazy when I couldn't get it to work with set numbers instead of the @hour/@min functions...If $hour = 12 then ContinueLoopOh, also, $bells[x][0] is the period [x][1] is the hour, and [x][2] is the minute. I just realized that boo-boo by not giving syntax to it....sorry Edited April 1, 2005 by MSLx Fanboy Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted April 1, 2005 Share Posted April 1, 2005 Yea! I think I got it now! Here's the main file code: #NoTrayIcon #Include <belltimes.au3> $hour = @hour $minute = @min If $hour = 0 then $hour = 12 If $hour > 12 then $hour = $hour - 12 ;;; @hour is always returned in a 24 hour format, numbered from 0 to 23. $max = UBound($bells, 2) For $x = 0 to $max step 1 If $hour = 12 then ContinueLoop If $hour = $bells[$x][1] then If $minute < $bells[$x][2] Then Msgbox(0,"test",$bells[$x][1] & ":" & $bells[$x][2]) EndIf ElseIf $hour = $bells[($x+1)][1] Then MsgBox(0,"test",$bells[($x+1)][1] & ":" & $bells[($x+1)][2]) EndIf Next Thanks for the help, I'll have to keep doing a little testing today to make sure it works (and to see when I get out of my next classes ) I attached the two source files if anyone wants themalert.au3belltimes.au3 Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) Link to comment Share on other sites More sharing options...
Blue_Drache Posted April 1, 2005 Share Posted April 1, 2005 Yea! I think I got it now!<snip>Thanks for the help, I'll have to keep doing a little testing today to make sure it works (and to see when I get out of my next classes ) I attached the two source files if anyone wants them<{POST_SNAPBACK}>Glad you got a push in the right direction. I'm all for the K.I.S.S. concept. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted April 1, 2005 Share Posted April 1, 2005 Thanks. Hehe, great minds think a like...found a somewhat simpler way to do it, by combining the hour and minute together, and switching everything to a 24 hour format, and then just pull stringleft and right functions to separate the parts at the end included it again. It's a function now, and it outputs an array with the comment, the hour, and the time. yeaalert.au3belltimes.au3 Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) 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