raining010 Posted September 26, 2013 Share Posted September 26, 2013 Hi, Admin I want to read from some txt files(use select button), then display the content in page of DAQ. It should use text component to display this, but how to read whole content from file in one time is a question to me. And if the content is out of range, should use up/down buttons to control. Gould you please give some suggestions Thanks Link to comment Share on other sites More sharing options...
AzeoTech Posted September 26, 2013 Share Posted September 26, 2013 Here's a sample. It requires 5.87a. I use a multiline edit box to display the contents so that it can scroll (with page up/page down, no scroll bars). It is set to read only. The button triggers a sequence function to request the file and update the component. Its a pretty straightforward script: private string filename = file.FileOpenDialog() if (!isempty(filename)) private handle = file.Open(filename,1,0,0,0) private size = file.GetLength(handle) private string in = file.Read(handle, size) component.viewer.strContents = in endif The first line requests the file from the user. The second checks to see if they hit cancel. The third line opens the file for reading (note Text mode is turned off, even though this is a text file. This is because text mode causes Read() to only read one line at a time). The fourth line gets the size of the file in bytes. The fifth reads all those bytes in a single go. The sixth then updates the contents of the edit box with the file. Link to comment Share on other sites More sharing options...
SteveMyres Posted September 26, 2013 Share Posted September 26, 2013 Nice example - slick! Never thought of using a text box as a display. Link to comment Share on other sites More sharing options...
raining010 Posted October 12, 2013 Author Share Posted October 12, 2013 Hi, Mr Guru I used your example to read log.csv and alarms.dat(read all text in one time), displayed. Then I used another way to read log.csv and alarms.dat by line(use loop to read one line each time), displayed also. The results of these two ways are all same: While I click the Editbox, the format of characters inside Editbox will change(the delimiter for each line seems disappear, many lines combine together), and they flash less than 1 second, after I click other area to move the focus outside, the format changes back and with no flash. See attached photos. First word of each line is 0, it's time, I've posted it in another topics Thanks Link to comment Share on other sites More sharing options...
raining010 Posted October 12, 2013 Author Share Posted October 12, 2013 I have to click the box, because if content is more than one screen, I have to move inside the focus and use page down to read Link to comment Share on other sites More sharing options...
AzeoTech Posted October 14, 2013 Share Posted October 14, 2013 Edit boxes in DAQFactory are done a little unusually. When you don't have focus, they are painted by our native code. When they have focus, we display a standard windows edit box on top of your component to allow for editing. The problem appears to be that DAQFactory and the standard windows edit box are interpretting your file differently. My guess is that it has to do with the carriage return / line feed combination. Either your file has only line feeds and the windows edit box wants both, or the opposite. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.