Lee Evans Posted April 27, 2004 Share Posted April 27, 2004 Hope some one can help. I am reading a file line by line looking for a string that contains a certain token. As I will be looking for different tokens in the same file I decided to make my own function that returns the second part of the line containing a required path as a variable. Trouble is I can't seem to get the function to return the variable. What am I doing wrong? expandcollapse popup AutoItSetOption("TrayIconDebug", 1) Local $spath="dfdf" Local $userdir="C:\test\" _FilePathFromSysParams ($userdir, "SYSDATAPATH", $spath ) Func _FilePathFromSysParams ($userdir, $token, ByRef $spath) Local $line = 1 Local $read = 0 Local $stringpresent = 0 For $stringpresent = 0 to 1 $read = FileReadLine ($userdir&"file.txt",$line) MsgBox(4096, "Data directory", ""& $read) $stringpresent = StringInStr( $read, $token );This will return 1 if $token is present $line = $line +1 If $stringpresent <> 1 Then ContinueLoop Next $linesplit = StringSplit($read, ","); in the file each line is "token,path" $linesplit[2] = $spath Return $spath EndFunc; _FilePathFromSysParams $datadir = $spath MsgBox(4096, "Data directory", ""& $datadir) Link to comment Share on other sites More sharing options... trids Posted April 27, 2004 trids Active Members 936 Hmmm .. and what have we here? Share Posted April 27, 2004 Looks like you're ignoring the return value . See the following illustration: $nValue1 = 100 $nValue2 = 10 ;This just causes the code in the UDF to be executed ;.. but ignores any return value _AddThem($nValue1, $nValue2) ;This executes the code in the UDF ;.. and does something with the return value.. $nReturnValue = _AddThem($nValue1, $nValue2) MsgBox(4096 + 32, "", $nReturnValue) Func _AddThem ($pnV1, $pnV2) ;This function adds two numbers, and returns the result $nSum = $pnV1 + $pnV2 Return $nSum EndFunc Hope this helps Link to comment Share on other sites More sharing options...
Marc Posted April 27, 2004 Share Posted April 27, 2004 Since your function has definded $spath as BYREF, the value can be changed from the function itself, so there is no RETURN necessary. I'd suggest changing $linesplit[2] = $spath Return $spath into $spath = $linesplit[2] which should do the job. And I'd move the commands below the EndFunction above the whole Function block to make it more readable Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
Lee Evans Posted April 28, 2004 Author Share Posted April 28, 2004 (edited) They both worked. Thanx a lot. Edited April 28, 2004 by Lee Evans 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