;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfItemListToFile (strFilename, strItemList, strDelimiter) ; The FilePut version. If strItemList == "" Then Return 0 Return FilePut (strFilename, StrReplace (strItemList, strDelimiter, @CRLF)) ;.......................................................................................................................................... ; This UDF udfItemListToFile writes an itemlist to a textfile with EOL=CRLF and returns the number of bytes written. ; Example: intResult = udfItemListToFile (strMyFile, @TAB, strMyList) ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfItemListFromFile (strFilename, strDelimiter) ; The FileGet version. If !FileSize (strFilename) Then Return "" If strDelimiter == "" Then strDelimiter = @TAB strItemList = StrReplace (StrReplace (FileGet (strFilename), @CRLF, @LF), @CR, "") ; @CR has no meaning. If strDelimiter != @LF Then strItemList = StrReplace (strItemList, @LF, strDelimiter) Return strItemList ;.......................................................................................................................................... ; This UDF udfItemListFromFile reads a textfile line by line with EOL=LF or EOL=CRLF and creates an itemlist accordingly. ; Example: strMyList = udfItemListFromFile (strMyFile, @TAB) ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfItemListToFileV2 (strFilename, strItemList, strDelimiter) ; The Binary Buffer version. If strItemList == "" Then Return 0 strItemList = StrReplace (strItemList, strDelimiter, @CRLF) hdlBB = BinaryAlloc (StrLen (strItemList)) BinaryPokeStr (hdlBB, 0, strItemList) intResult = BinaryWrite (hdlBB, strFilename) hdlBB = BinaryFree (hdlBB) Return intResult ;.......................................................................................................................................... ; This UDF udfItemListToFile writes an itemlist to a textfile with EOL=CRLF and returns the number of bytes written. ; Example: intResult = udfItemListToFile (strMyFile, @TAB, strMyList) ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfItemListFromFileV2 (strFilename, strDelimiter) ; The Binary Buffer version. intBBSize = FileSize (strFilename) If !intBBSize Then Return "" hdlBB = BinaryAlloc (intBBSize) BinaryRead (hdlBB, strFilename) strItemList = BinaryPeekStr (hdlBB, 0, intBBSize) hdlBB = BinaryFree (hdlBB) If strDelimiter == "" Then strDelimiter = @TAB strItemList = StrReplace (StrReplace (strItemList, @CRLF, @LF), @CR, "") ; @CR has no meaning. If strDelimiter != @LF Then strItemList = StrReplace (strItemList, @LF, strDelimiter) Return strItemList ;.......................................................................................................................................... ; This UDF udfItemListFromFile reads a textfile line by line with EOL=LF or EOL=CRLF and creates an itemlist accordingly. ; Example: strMyList = udfItemListFromFile (strMyFile, @TAB) ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. :Test1 strItemList = udfItemListFromFile (IntControl (1004, 0, 0, 0, 0), @TAB) ; We use this file as test input. strAskList = AskItemlist ("Choose lines to copy into temp file", strItemList, @TAB, @UNSORTED, @EXTENDED) strFileTemp = FileCreateTemp ("TMP") intResult = udfItemListToFile (strFileTemp ,strAskList, @TAB) strItemList = udfItemListFromFile (strFileTemp, @TAB) blnResult = FileDelete (strFileTemp) strAskList = AskItemlist ("Check/Review: the lines read from file", strItemList, @TAB, @UNSORTED, @EXTENDED) :Test2 strItemList = udfItemListFromFileV2 (IntControl (1004, 0, 0, 0, 0), @TAB) ; We use this file as test input. strAskList = AskItemlist ("Choose lines to copy into temp file", strItemList, @TAB, @UNSORTED, @EXTENDED) strFileTemp = FileCreateTemp ("TMP") intResult = udfItemListToFileV2 (strFileTemp ,strAskList, @TAB) strItemList = udfItemListFromFileV2 (strFileTemp, @TAB) blnResult = FileDelete (strFileTemp) strAskList = AskItemlist ("Check/Review: the lines read from file", strItemList, @TAB, @UNSORTED, @EXTENDED) Exit