cookiemonster Posted November 5, 2014 Share Posted November 5, 2014 Hey all, this must be a very silly question... Ive got a script below which I'm trying to return $sLine so it appears in the main results message box but it wont return it out of the function... Can anyone help me? Global $file = "C:\Users\James.Q\Desktop\MyFile.txt", $search = "the dog jumped" Global $iLine = 0, $sLine = '', $iValid = 0 Call ("colorfinder",$file,$search,$iLine,$sLine,$iValid) msgbox(4096,"Main result",$sLine) Func colorfinder($file,$search,$iLine,$sLine,$iValid) Global $hFile = FileOpen($file) While 1 $iLine += 1 $sLine = FileReadLine($hFile) If @error = -1 Then ExitLoop ; test the line for the $search string until the flag $iValid is set If StringInStr($sLine, $search) Then $iValid = 1 EndIf If $iValid Then $iValid = 1 msgbox(4096,"result1",$sLine) ExitLoop EndIf WEnd msgbox(4096,"result2",$sLine) Return $sLine FileClose($hFile) EndFunc ;colorfinder Link to comment Share on other sites More sharing options...
Solution cookiemonster Posted November 5, 2014 Author Solution Share Posted November 5, 2014 fixed it but just incase its any help to anyone...heres the fixed code: Global $file = "C:\Users\James.Q\Desktop\MyFile.txt", $search = "the dog jumped" Global $iLine = 0, $sLine = '', $iValid = 0 $ans = colorfinder($file,$search,$iLine,$sLine,$iValid) msgbox(4096,"Main result",$ans) Func colorfinder($file,$search,$iLine,$sLine,$iValid) Global $hFile = FileOpen($file) While 1 $iLine += 1 $sLine = FileReadLine($hFile) If @error = -1 Then ExitLoop ; test the line for the $search string until the flag $iValid is set If StringInStr($sLine, $search) Then $iValid = 1 EndIf If $iValid Then $iValid = 1 msgbox(4096,"result1",$sLine) ExitLoop EndIf WEnd msgbox(4096,"result2",$sLine) FileClose($hFile) Return $sLine EndFunc ;colorfinder 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