How To Display Content Of Some Txt File


Recommended Posts

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

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

  • 3 weeks later...

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

post-8996-0-26676100-1381583387_thumb.jp

post-8996-0-10240400-1381583390_thumb.jp

post-8996-0-04251000-1381583392_thumb.jp

post-8996-0-12459200-1381583396_thumb.jp

Link to comment
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.