RagsRevenge Posted April 15, 2010 Share Posted April 15, 2010 Hello, I'm writing a program which depends heavily on functions like _fileReadToArray, _fileCreate, etc. This program is for use in translating between languages, including Unicode languages. I noticed that a lot of the Open mode parameters of the functions in file.au3 are hardcoded to 0 or 2, ie: not allowing you to pass the Unicode open modes. I was working through file.au3 to create file_ex.au3 which allowed an optional parameter to specify the open mode to these functions. The read functions seem to work with unicode already, even when an open mode of 0 is used, which is confusing me. _fileCreate needed to be changed to Func _FileCreate_Ex($sFilePath, $i_OpenMode = 2) ;============================================== ; Local Constant/Variable Declaration Section ;============================================== Local $hOpenFile Local $hWriteFile $hOpenFile = FileOpen($sFilePath, $i_OpenMode) If $hOpenFile = -1 Then SetError(1) Return 0 EndIf $hWriteFile = FileWrite($hOpenFile, "") If $hWriteFile = -1 Then SetError(2) Return 0 EndIf FileClose($hOpenFile) Return 1 EndFunc ;==>_FileCreate_Ex to allow me to create Unicode files. Then I noticed that Jos has remarked "To use other write modes, like append or Unicode formats, open the file with FileOpen() first and pass the file handle instead. ; If a file handle is passed, the file will still be open after writing." in _FileWriteFromArray. Am I wasting my time converting these functions to Unicode functions, ie: am I missing something fundamental? Secondly, is it not better to simply pass the open mode to _FileWriteFromArray, to allow you to append/use unicode? As Jos is a far better coder than I, I expect I'm missing a valid reason to pass the file handle as opposed to the open mode parameter. Thanks, D Link to comment Share on other sites More sharing options...
BrettF Posted April 15, 2010 Share Posted April 15, 2010 There is no reason why you cannot write to the file using your own code rather than the UDFs? For example writing a file line from an array element is as simple as using a loop and writing the line. Nothing much more than that? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
RagsRevenge Posted April 16, 2010 Author Share Posted April 16, 2010 There is no reason why you cannot write to the file using your own code rather than the UDFs? For example writing a file line from an array element is as simple as using a loop and writing the line. Nothing much more than that?I understand this.I'm used to using the _file.au3 functions, and it's very simple to recode them to make them Unicode compatible.I guess I'm just curious why the decision was made to hardcode ANSI mode into the functions, and the one reference to Unicode in the UDF, Jos suggests a different process to what I think should be done (pass filehandle as opposed to passing open mode). In deference to the UDF authors' superior skills, I thought I might have been missing out on very valid reasons not to do what I'm doing, hence the question.D 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