Reading .dat file (input) into MSFlexGrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MiziaQ
    New Member
    • Nov 2007
    • 63

    Reading .dat file (input) into MSFlexGrid

    Hey. How can I input data into an MSFlexGrid table from a .dat file ?

    I have the following data in the data file:

    "Mike", "20", "Boston"

    I would like to read "Mike" in row 1, column 1
    read "20" in row 1, column 2
    and "Boston" in row 1, column 3

    Please Help

    Thanks in advance ;)
  • VBWheaties
    New Member
    • Feb 2008
    • 145

    #2
    Originally posted by MiziaQ
    Hey. How can I input data into an MSFlexGrid table from a .dat file ?

    I have the following data in the data file:

    "Mike", "20", "Boston"

    I would like to read "Mike" in row 1, column 1
    read "20" in row 1, column 2
    and "Boston" in row 1, column 3

    Please Help

    Thanks in advance ;)
    Open the file, loop through its contents, parse out the values and set them to the grid using TextMatrix.
    if you want something more sophisticated, use the Text driver to open your dat file as a datasource.
    That way, you can bind a recordset to the grid. However,you are at the mercy of the underlying provider who has a bad habit of changing certain data (like string columns to numbers if the first few rows have numeric values).

    Suggestion: if the file is relatively small, read it in using a loop.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      I concur with VBWheaties. However, you need to take care.

      For one thing, CSV format allows for the field delimiters (and string delimiters such as ") to appear within the data. For instance, let's say we had this record...
      "Mike", "20", "Boston, Mass"
      If imported into Excel, this would produce three items:
      • Mike
      • 20
      • Boston, Mass

      If you read this same record into a string and use the Split() function to chop it into fields, it doesn't know anything about fields or delimiters, except the one you tell it to watch for (comma, in this case). So you would end up with four items...
      • Mike
      • 20
      • Boston
      • Mass

      Comment

      Working...