10-17-2018 02:35 PM - edited 10-17-2018 02:41 PM
Hello,
I am creating a DataPlugin for a .txt file, and I'm having issues with some text at the very end of the files.
DO UNTIL sCheckData = "[DATA START]" OR File.Position = File.Size sCheckData = File.GetNextStringValue(eString) File.SkipLine() LOOP '---- Get Data ---------------------------------' File.Formatter.LineFeeds = vbNewLine File.Formatter.Delimiters = vbTab saChanNames = Split(File.GetNextLine,File.Formatter.Delimiters) saChanUnits = Split(File.GetNextLine,File.Formatter.Delimiters) CurrPos = File.Position saChanDataType = Split(File.GetNextLine,File.Formatter.Delimiters) File.Position = CurrPos SET Block = File.GetStringBlock() '---- Add Data ---------------------------------' FOR i = 0 to UBound(saChanNames) 'Based off of the string in the saChanDataType, this loop will set the datatype of the channel added to the Data Portal. IF IsNumeric(saChanDataType(i)) THEN sChanDataType = "Float" Select Case sChanDataType Case "Float" sChanDataType = eR64 Case Else sChanDataType = eString End Select Set DirectAccessChannel = Block.Channels.Add(Replace(saChanNames(i),Chr(34),""),sChanDataType) oChannelGroup.Channels.AddDirectAccessChannel(DirectAccessChannel) Call DirectAccessChannel.Properties.Add("unit_string", saChanUnits(i)) NEXT
Example:
[DATA START]
Channel 1, Channel 2, Channel 3
1,2,3
4,5,6
7,8,9
[DATA END]
So, my DataPlugin ignores the text before, grabs the channels, then gets the data as a block. But since there is text after the data, I have a row of NoValue at the end of each of my numeric channels.
Is there a clean way to get rid of/ignore the last row of data inside of the dataplugin, or do I have to grab the data row by row instead of as a block.
Thanks.
Solved! Go to Solution.
10-17-2018 03:35 PM
Hi Kevin,
Just a thought!
How about Reading in the file using the VBS file object, then replacing the [DATA END] text with "". Then saving back out as a temporary file.
You then can read in the temporary file, and the block read will work just fine.
Paul
ps. Maybe Brad will have a better idea, he is rather good at Data plugins!
10-18-2018 02:35 AM
Hi,
you can determine the number of lines between [DATA START] and [DATA END], similar to how you determine the start of the data.
Afterwards, set the block length to number of lines:
SET Block = File.GetStringBlock()
Dim blockLength blockLength = 0 DO UNTIL sCheckData = "[DATA END]" OR File.Position = File.Size sCheckData = File.GetNextStringValue(eString) blockLength = blockLength + 1 File.SkipLine() LOOP Block.BlockLength = blockLength
You don't need to reset file position, because the StringBlock stores the file position at the time he gets created.
One additional note, you should set file formatter before using GetNextStringValue() and SkipLine(), because LineFeeds and Demilimiters are used by these functions.
10-18-2018 07:27 AM
I was not aware you could set the length of the block, thanks usac.
Also, due to how these files are pieced together, I need different delimiters for the header than I do for the data. So I have the header delimiters called out earlier in the code, which I didn't post. Thank you for calling it out though, I should have just posted the entire thing.