3 Replies - 314 Views - Last Post: 07 May 2019 - 07:49 PM Rate Topic: -----

#1 Schwarzenegger   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 20-February 07

Write string data to csv file

Posted 07 May 2019 - 03:18 AM

I have an array of data, all lifted from textbox texts and are therefore strings. The array shows these data accurately as strings but when I write them to a csv file using the Write # statement the csv file, when opened in Excel, drops any leading zeros from the data and changes long numerics to a shorter exponential format. I need to read these data exactly as they were presented in the orininal array.
Is This A Good Question/Topic? 0
  • +

Replies To: Write string data to csv file

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15228
  • View blog
  • Posts: 60,973
  • Joined: 12-June 08

Re: Write string data to csv file

Posted 07 May 2019 - 05:38 AM

Are you flanking the data being written with quotes?

Is the file extension .csv?
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6813
  • View blog
  • Posts: 28,190
  • Joined: 12-December 12

Re: Write string data to csv file

Posted 07 May 2019 - 05:46 AM

That is normal Excel behaviour. You could just format the columns in Excel (with custom format of # forcing the display of all digits).

Or I suppose you could precede the values with a single quote if you want Excel to treat them as text.
Was This Post Helpful? 0
  • +
  • -

#4 Schwarzenegger   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 20-February 07

Re: Write string data to csv file

Posted 07 May 2019 - 07:49 PM

All the elements in the VB array are in quotes as shown in the Locals window but the fact that each item has a string format doesn't seem to bother Excel.
Once the Data are on the csv file the project creating these data is no longer required. The csv data will be used in another VB project I am developing . Formatting errors I can fix manually by using a single quote before the item. The items are going to be used further down the line and before they can be used the leading quote has to be removed. I thought that there would be a more elegant way to do this.

This post has been edited by Schwarzenegger: 07 May 2019 - 07:52 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1