only get certain variables from sequential file
only get certain variables from sequential file
only get certain variables from sequential file
only get certain variables from sequential file
only get certain variables from sequential file
only get certain variables from sequential file only get certain variables from sequential file only get certain variables from sequential file only get certain variables from sequential file only get certain variables from sequential file only get certain variables from sequential file only get certain variables from sequential file only get certain variables from sequential file
only get certain variables from sequential file only get certain variables from sequential file
only get certain variables from sequential file
Go Back  Xtreme Visual Basic Talk > > > only get certain variables from sequential file


Reply
 
Thread Tools Display Modes
  #1  
Old 04-04-2015, 01:53 PM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 287
Default only get certain variables from sequential file


Hi,
Is it possible to only get selected variables from a comma-separated file? For instance (say) 'myfile.dat' contains var1, var2, var3, var4, var5. This is because one part of the app needs all these 5 variables. No problem of course. However, another part of the app only needs (say) var2 and var5. Is it possible to get just these two variables? Or do I have to get them all (and simply not use var1, var3 and var4)?
Reply With Quote
  #2  
Old 04-04-2015, 10:18 PM
hDC_0only get certain variables from sequential file hDC_0 is offline
Contributor

* Expert *
 
Join Date: Feb 2004
Posts: 559
Default Searching, evaluating, finding field values in a csv file

Quote:
Originally Posted by starmanMike
..Or do I have to get them all (and simply not use var1, var3 and var4)?
Sorry, starmanMike, but if you don't (at least) read all the csv file values,
then how is any code going to be able to evaluate (pick out) whether
the delimited fields match your searching criteria?

You shouldn't necessarily have to load all the contents files into memory, though (if that is what you are asking).


Just off the top of my head the code to read/parse a line at a time would be something like:
Use a Do While Not EOF,
read each line (using Line Input),
use Split with "," as your second field for the delimiter,
then based on an If..then evaluation testing statement,
only load the values you are seeking (into an array, ADO recordset, whatever..).
Reply With Quote
  #3  
Old 04-05-2015, 04:52 AM
Gruff's Avatar
Gruffonly get certain variables from sequential file Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Mike, Context is everything. You are not saying what the conditions are for the file.

1) Is it a configuration file for your program?
2) Is it a data file your program consumes?
3) Is your program creating the file?
4) Are you creating the file manually?
5) Is someone else creating the file and your program only consumes it.
6) Are the variables all the same size?

These are just a few of the many questions that come to mind.

Unless your file is really huge then the read time is not worth worrying about.
If the variable positons within the file do not change then you could put the sub set of variables first and only read that number of lines. If you need the whole set read all the lines.

If memory is not an issue or the file is relatively small then HDC's suggestion of reading the whole thing into memory in one gulp is a good choice. (Generally speaking.)
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 04-05-2015 at 04:58 AM.
Reply With Quote
  #4  
Old 04-05-2015, 07:30 AM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 287
Default

Thanks, everything you've both said makes a lot of sense. The file (it's a little configuration file, just half a dozen variables) is very small, so I have decided that the issue is not worth the bother, as you say. It was more a matter of 'the issue has come up; can I do so-and-so?' So I just read the variables in anyway! Cheers.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
only get certain variables from sequential file
only get certain variables from sequential file
only get certain variables from sequential file only get certain variables from sequential file
only get certain variables from sequential file
only get certain variables from sequential file
only get certain variables from sequential file only get certain variables from sequential file only get certain variables from sequential file only get certain variables from sequential file only get certain variables from sequential file only get certain variables from sequential file only get certain variables from sequential file
only get certain variables from sequential file
only get certain variables from sequential file
 
only get certain variables from sequential file
only get certain variables from sequential file
 
-->