Share this post

Link to post

Share on other sites

Tvern 5

It would help if you explained what the problem is with your current script, but I assume it's that the variable doesn't contain the contents of the file after running the functions.

Have a look at these 3 solutions,

ps. I suggest naming your variables so that you can always see what type they are as per example. (s for string, h for handle, etc)

Local$somevariable;downside: variable needs to be declared beforehand_ReadFile("c:\somepath\somefile.txt",$somevariable)Func_ReadFile($sPath,ByRef$sContent);byref means that the passed variable is updated when the function returnsLocal$hFile=FileOpen($sPath,0)Local$sContent=FileRead($hFile)FileClose($hFile);this uses a handle, not a path!
setStatus("Loaded: "&$sPath)EndFunc;~ Or : Local$somevariable=_ReadFile2("c:\somepath\somefile.txt");variable can be declared and used on one lineFunc_ReadFile($sPath)Local$hFile=FileOpen($sPath,0)Local$sContent=FileRead($hFile)FileClose($hFile);this uses a handle, not a path!
setStatus("Loaded: "&$sPath)Return$sContentEndFunc;~ Or :Local$somevariable=FileRead("c:\somepath\somefile.txt");there is no reason for FileOpen->FileRead->FileClose if you are just reading once.