Important alert: (current site time 7/16/2013 12:59:35 AM EDT)
 

VB icon

Convert text to csv

Email
Submitted on: 2/22/1999
By: Adam Abas 
Level: Not Given
User Rating: By 5 Users
Compatibility: VB 5.0, VB 6.0
Views: 57622
 
     The porpose of this code is, how you convert delimited with tab or spaces text file to Comma delimited,as you know when import a delimited with tab or spaces to Accesss you will get one field only ( from vb application ) without doning any changes.This code help you convert and Import to access in one step only.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Convert text to csv
' Description:The porpose of this code is, how you convert delimited with tab or spaces text
file to Comma delimited,as you know when import a delimited with tab or spaces 
to Accesss you will get one field only ( from vb application ) without doning any changes.This code help you convert and Import to access in one step only.
' By: Adam Abas
'
' Inputs:delimited with tab or spaces text File
'
' Returns:Comma delimited text file as csv or excel
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1425&lngWId=1'for details.'**************************************

Private Function ConverToCommax()
'ConvertedName the file you will convert to comma
'sSourceFile the source file you convert from
Dim x
Dim MyString As String
Dim Newstring As String
Dim Oneletter
ConvertedName = "C:\Converted.csv"
sSourceFile = "C:\Yourtabedfile.txt"
If ConvertedName <> "" Then
Screen.MousePointer = vbHourglass
Open ConvertedName For Output As #2
Open sSourceFile For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
 Input #1, MyString ' Read data into one variable.
 For x = 1 To Len(MyString)
 Oneletter = Mid(MyString, x, 1)
 If Asc(Oneletter) = 9 Then
 Oneletter = ","
 End If
 DoEvents
 Newstring = Newstring & Oneletter
Next x
Print #2, Newstring
Newstring = ""
DoEvents ' it is important to unlock the screen
Loop
Close #1 ' Close file.
Close #2
Screen.MousePointer = vbDefault
Else
MsgBox " Destination File Read Erorr.. "
End If
End Function


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/14/1999 12:59:00 PMme

It's close...

This code will skip the begining quote on the first field and the ending quote on the last field.

Also it only seperates fields from a TAB delimited source file NOT fixed width.
(If this comment was disrespectful, please report it.)

 
5/20/1999 10:58:00 PMchris

This is almost what I've been looking for, for days.
I have a excel spreadsheet which I need to save as text with tab delimiter.
And that is all great.
But how can I read it into visual basic
variables.
Any help would be greatly appreciated.
chris
(If this comment was disrespectful, please report it.)

 
5/20/1999 10:59:00 PMchris

This is almost what I've been looking for, for days.
I have a excel spreadsheet which I need to save as text with tab delimiter.
And that is all great.
But how can I read it into visual basic
variables.
Any help would be greatly appreciated.
chris
palsecamntsc@hotmail.com
(If this comment was disrespectful, please report it.)

 
5/26/1999 5:31:00 AMDISEASE_2000

---------------------------
(If this comment was disrespectful, please report it.)

 
12/11/1999 11:51:00 PMHalf-Dead

I use this to strip Quotation marks out of pipe delimited txt files that access creates

Dim InFile As Integer
Dim Outfile As Integer
Dim OutString As String

InFile = FreeFile
Open App.Path & "ToConvert.txt" For Input As InFile
OutString = Replace(Input(LOF(1), 1), vbTab, ",")
Close InFile

Outfile = FreeFile
Open App.Path & "Converted.txt" For Binary As Outfile
Put #Outfile, , OutString
Close Outfile
OutString = ""

Might help
(If this comment was disrespectful, please report it.)

 
12/12/1999 12:00:50 AMHalf-Dead

Oops, change that replace statement
Replace(Input(LOF(InFile), InFile)
i had left 1 instead
and dont foget the back slash for the
Open App.Path & "\ToConvert.txt"
(If this comment was disrespectful, please report it.)

 
12/7/2000 10:03:47 AMRobert MacKay

Why don't you use instr to locate the tab? That would be much faster than examining the string one character at a time! And, unlike replace, it wouldn't be limited to vb6.
(If this comment was disrespectful, please report it.)

 
6/3/2001 9:24:02 AMTroy Mac

you need to change to this in the code so it will do tabs and spaces

If Asc(Oneletter) = 9 Or Asc(Oneletter) = 32 Then
Oneletter =
(If this comment was disrespectful, please report it.)

 
8/14/2006 9:56:26 AMaz1d

Poor code.

Half-Dead's suggestion is what I would use myself.
-az1d
(If this comment was disrespectful, please report it.)

 
6/4/2013 8:35:01 AMRobert

I am out of touch with VB6, but this is exactly what I wanted. End result is to read TAB delimited .TXT file into .CSV with this code and then read this .csv and from there populate a table in MS Access from the VB-app.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.