Results 1 to 7 of 7

Thread: Save as .csv files

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2009
    Posts
    24

    Save as .csv files

    Hi..

    When I save a string into .csv using:

    Code:
    My.Computer.FileSystem.WriteAllText("c:test.csv", "Hallo,Word", False)
    a test.csv is created.

    I tried to open test.csv with excell and it is opened just fine.
    but when I tried to save it again, it seems like excell didn't recognize it as a valid .csv file. it will show save as type as a unicode text (*.txt) file instead of a *.csv file.

    why this is happened?
    how to make a real .csv file from vb.net?

    thanks for all your help..

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Save as .csv files

    I just tested with Excel 2010 and it worked fine for me. I can't speak for earlier versions though. How EXACTLY are you trying to save?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2009
    Posts
    24

    Re: Save as .csv files

    Thanks jmcilhinney..

    I use a software (ADP6.xx) that can import .csv file.

    When I make .csv file from vb.net, ADP6 can not import my .csv until I open .csv and save it again from excel.
    I compare .csv before and after save from excel with notpad, both contain exactly the same.

    I use excel 2007..

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Save as .csv files

    There are only two things I can think of, although neither seem likely.

    1. That program expects text fields to be enclosed in quotes.
    2. That program expects a line break at the end of every record.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2009
    Posts
    24

    Re: Save as .csv files

    So what do you think is missing?

    This .csv file is created from vb.net:
    {Group Name,Name,Address,Refresh Rate,Comment
    ,Input0_01,I0.01,Normal,Reset item counter
    ,Input0_00,I0.00,Normal,Reset item counter
    ,Flagword0,FW0,Normal,Reset item counter
    ,Flag1_00,F1.00,Normal,Reset item counter
    ,Output0_00,O0.00,Normal,Reset item counter
    ,Output0_01,O0.01,Normal,Reset item counter
    ,Output0_02,O0.02,Normal,Reset item counter
    }

    This one is saved from excel:
    {Group Name,Name,Address,Refresh Rate,Comment
    ,Input0_01,I0.01,Normal,Reset item counter
    ,Input0_00,I0.00,Normal,Reset item counter
    ,Flagword0,FW0,Normal,Reset item counter
    ,Flag1_00,F1.00,Normal,Reset item counter
    ,Output0_00,O0.00,Normal,Reset item counter
    ,Output0_01,O0.01,Normal,Reset item counter
    ,Output0_02,O0.02,Normal,Reset item counter
    }

    {} is not in .csv

    thanks..

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2009
    Posts
    24

    Re: Save as .csv files

    sorry, nevermind.. i tried again both.. and both work just fine..

    still if .csv created from vb.net, that program cannot open..
    if i create a .csv file (from notepad), and copy all (ctrl-a) .csv from vb into .csv from notepad.. then, that program can open.

    why can this be happened?? what am i missing here??? please help..

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Save as .csv files

    I suggest that you check the ASCII value of every character in the files. There must be something different between the two that you cannot see.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width