Forum Discussion

soda's avatar
soda
Contributor
15 years ago

Unable to read double-byte characters from txt file using JScript and TC

Hello,




Is there any way to read double-byte characters from a csv or text file using JScript and TestComplete?  Both the csv and txt file I have experimented with are UTF-8.  My Project character encoding properties are also set to UTF-8.









If I hardcode some Japanese characters into the test script, I am able to use the Keys() method to enter text into an edit box.  If the same Japanese characters are placed into a csv or text file, they are converted into completely different characters.  It seems that TC can handle the double-byte characters if they are already in the script, but something is not working correctly when reading from a file.  Is this simply something that is not possible?  Is there a standard way of reading UTF-8 files with double-byte characters?







Thanks,




Mark




7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I'm assuming your file is saved as a UTF-8 formatted file?  



    What method are you using for reading the information from the file (DDT objects, Keyword test data driven loops, aqFile functions/methods)?



    These answers may help to determine what it is you're dealing with so a better answer can be given.
  • soda's avatar
    soda
    Contributor
    Hello,




    You are correct.  Both the csv and text files were UTF-8.  I zipped up some samples of what the code looks like and the txt file.




    At this point, I was just using the FileSystemObject to read from the file and was about to take a peak at the builtin file system functions of TestComplete.  If it helps, this  is intended to be a start on some double-byte data driven tests.




    Thanks,




    Mark




  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    If you use aqFile to open the CSV files, you can specify the format as ANSI, UTF-8, etc.  Using DDT drivers, though, I think it is dependent upon your environment.  I think you need to create a schema.ini in the folder with your CSV file and specifiy the CharacterSet as OEM but I'm not certain.  I haven't had to read double-byte CSV files on an English operating system before so I can't say necessarily what your best bet is.
  • soda's avatar
    soda
    Contributor
    Thanks for the reply Robert.  Sadly, using the aqFile methods,the Japanese characters are read and displayed in the debugger as ??????.  I had selected  ctUTF8 as the parameter for OpenTextFile.  Is this a bug in TestComplete?
  • Hi Mark,



    You need to use the OpenTextFile methods like this:




    F = fso.OpenTextFile(fileToReadFrom, ForReading, false, -1);






    or




    F = aqFile.OpenTextFile(fileToReadFrom, aqFile.faRead, aqFile.ctUTF8);






    For more information, refer to the aqFile Object help topic and this MSDN Library article.



    Do these approaches work for you?
  • soda's avatar
    soda
    Contributor
    Hi Allen,

    Thanks for the help.  Both approches worked however, they reported different results.  Using the statement:

    F = fso.OpenTextFile(fileToReadFrom, ForReading, false, -1);




    The characters were read in and when reported to the log, seemed to have changed to different characters.



    Using the statement:

    F = aqFile.OpenTextFile(fileToReadFrom, aqFile.faRead, aqFile.ctUTF8);



    The characters were read in and reported in the log as expected.



    That is very strange.  Any clue as to why the FileSystemObject method would be different?  The text file is UTF-8 and my project character encoding is set to UTF-8.



    That was the first strange thing.  The other item is that the debugger displays double-byte characters as ?????? when inspecting the variable.  Any chance that can be fixed?



    Thanks again for the help.  I have been using the FileSystemObject because I was hoping to port some of my generic functions over to the Mac(to be used with a different tool), and therefore have avoided using aqFile.  I'll keep poking around with the FileSystemObject to see if I can figure out why it is different, but hopefully you or someone can offer some insight.



    I've attached a screen shot of the text file, code and Test Log.



    Thanks again!

    Mark

  • soda's avatar
    soda
    Contributor
    Digging around further, the FileSystemObject does not support UTF-8 so I'll be using the aqFile methods which work just fine.  Once I go to Mac with the same script, I'll be looking for a different solution for reading the double byte text, obviously.

    Thanks for the help.