aa2zz6 Posted December 20, 2016 Posted December 20, 2016 (edited) How do I setup IniRead to search for Cat and write MsgBox($MB_SYSTEMMODAL, "Search", "The" & $animal & "was found at" & $number, 5) [Search Animals] IGNORE_ERRORS=0 01=Dog 02=Cat 03=Bird 04=Fish This displays each key and value but how do I stop it when it gets to 02=Cat? _read() Func _read() Local Const $hostfile = @ScriptDir & "\filepath\" & "Search.ini" $var = IniReadSection($hostfile, "Section Header") If @error Then MsgBox(4096, "Error", "Unable to read section.") Else For $i = 1 To $var[0][0] MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next ; How does it stop when Cat is found? EndIf EndFunc ;==>+read Edited December 20, 2016 by aa2zz6
jguinch Posted December 20, 2016 Posted December 20, 2016 Just add ExitLoop after the MsgBox Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Malkey Posted December 20, 2016 Posted December 20, 2016 Yes an ExitLoop with a working example. #include <MsgBoxConstants.au3> #include <Array.au3> ; -------- Create ini file ----------- FileWrite("Search.ini", _ "[Search Animals]" & @CRLF & _ "IGNORE_ERRORS=0" & @CRLF & _ "01=Dog" & @CRLF & _ "02=Cat" & @CRLF & _ "03=Bird" & @CRLF & _ "04=Fish") Sleep(1000) ; ------ End of Create ini file ------ _read() FileDelete("Search.ini") ; Tidy up Func _read() Local Const $hostfile = "Search.ini" $var = IniReadSection($hostfile, "Search Animals") If @error Then MsgBox(4096, "Error", "Unable to read section.") Else For $number = 1 To $var[0][0] ; MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$number][1]) If $var[$number][1] == "Cat" Then MsgBox($MB_SYSTEMMODAL, "Search", "The " & $var[$number][1] & " was found at " & $var[$number][0], 5) ExitLoop ; Exits For - Next loop (stops) when search value, "Cat", is found? EndIf Next EndIf _ArrayDisplay($var, "Search Animals") EndFunc ;==>_read aa2zz6 1
aa2zz6 Posted December 23, 2016 Author Posted December 23, 2016 (edited) Is there a way to store the array number it found "Cat" in a variable and call it elsewhere in another function? Edited December 23, 2016 by aa2zz6
Subz Posted December 23, 2016 Posted December 23, 2016 You could use _ArraySearch to receive the index or _ArrayFindall to find all indexes _ArraySearch example: #include <Array.au3> Global $aResult[0][2] Search('Cat') _ArrayDisplay($aResult) Func Search($sSearch) Local $hostfile = @ScriptDir & '\Search.ini' Local $aSection = IniReadSection($hostfile, "Search Animals") If @error Then MsgBox(4096, "Error", "Unable to read section.") Return EndIf Local $iSearch = _ArraySearch($aSection, $sSearch, 0, 0, 0, 0, 1, 1) If $iSearch = -1 Then MsgBox(4096, 'Error', 'Unable to find ' & $sSearch) Return EndIf _ArrayAdd($aResult, $sSearch & '|' & $iSearch) EndFunc aa2zz6 1
aa2zz6 Posted December 23, 2016 Author Posted December 23, 2016 Thanks for the help guys I was able to complete my project.
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