Archived

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

Best way to read variables from a file?

This topic is 5149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

this is in VB ok - so i've pretty much always used text files to store variables in but i'm making something that would be much easier to use an Excel spreadsheet file with the only problem is that i don't know the best way to open the excel file and read the variables from the columns lets say i have a simple excel file... wigh just 2 columns and 2 rows First Name | Last Name Chris | Johnson Mike | Marks now - what would be the simplest way to open the excel file and read these values (just the names) into variables? if it's too much - i may just use text files like i have been. but it would be nice to have a clean excel file with easy to read headers so i can enter values a lot easier. [edited by - Wizzy on November 10, 2003 3:46:54 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You could use a comma-separated values (.csv) file, which would allow you to open it in both Excel and read it like a normal .txt file. Basically, each column is separated by a comma, and each row is separated by a carriage return. So, you would have something like:

First Name, Last Name
Chris, Johnson
Mike, Marks

The only thing you really lose doing this is the formatting in Excel, but it isn''t really that big of a deal.

I don''t really know anything about the Excel file format, but I have a feeling its proprietary, and you might have some difficulty getting your hands on it.

Share this post


Link to post
Share on other sites
It''s been years since I''ve messed with VB, but as I recall you create an excel object within your VB application, then make calls through that object.

This link has some snippets that may get you started, but you''ll probably have more luck doing a google search (or MSDN search if you prefer) for the ''Excel Application Object''.

HTH

Share this post


Link to post
Share on other sites
get a free XML parser for VB off the web, and use that.
you can also get the new version of excel to save to xml,
so you should be able to write your stuff using that.

i would keep away from VB though......

Share this post


Link to post
Share on other sites
read/write them in binary mode: no more text to number conversions no more formatting! yay!

use fread / fwrite (or write a OOP wrapper for them) - EDIT: uh forgot that you are in VB

in VB use "line input"

then take the string and do your operations on it.

[edited by - Ilici on November 12, 2003 1:39:26 PM]

Share this post


Link to post
Share on other sites