Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 30th, 2004, 12:15 AM
dev77's Avatar
dev77 dev77 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: On d Earth ofcourse..!!
Posts: 439 dev77 User rank is Major (30000 - 40000 Reputation Level)dev77 User rank is Major (30000 - 40000 Reputation Level)dev77 User rank is Major (30000 - 40000 Reputation Level)dev77 User rank is Major (30000 - 40000 Reputation Level)dev77 User rank is Major (30000 - 40000 Reputation Level)dev77 User rank is Major (30000 - 40000 Reputation Level)dev77 User rank is Major (30000 - 40000 Reputation Level)dev77 User rank is Major (30000 - 40000 Reputation Level)dev77 User rank is Major (30000 - 40000 Reputation Level)dev77 User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 15 h 59 m 40 sec
Reputation Power: 309
Arrow problem reading csv file

Hi,

I am trying to read data from csv file. Code is given below.

My problem is I could not read values in zip code if it is in format 99999-999.
Although it could read the values like 99999 in the same column.
Also, I am surprised that it could read value in this format 99999-999 if all values are in that format.
Only mix of formats it can't read.

If you try this code try it with mix data. I mean 99999 in some cells of ZipCode and 99999-999 in some other cells of
ZipCode.

Code:
	Set fso = New Scripting.FileSystemObject
	
	'################## CHANGE THE NAME OF THE FILE..........
	strFileName = App.Path & "\MyFile.csv"
	'##################
	
	CSVFile = strFileName
	
	Const ForReading = 1, ForWriting = 2, ForAppending = 3
	Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

	'
	'Define File System object for reading the CSV file
	'
	Set FileCSV = fso.GetFile(CSVFile)

	Set tsmax = FileCSV.OpenAsTextStream(ForReading, TristateFalse)
	While Not tsmax.AtEndOfStream
		no_line = no_line + 1
		Text = tsmax.ReadLine
	Wend
	If no_line = 1 Then
		MsgBox "No line found in csv"
	End If
	
	Set tsmax = Nothing
	'
	'Create connection string for reading CSV datacontent
	'
	Dim objConn As ADODB.Connection
	Dim objRs As ADODB.Recordset
	
	Set objConn = New ADODB.Connection
	objConn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
	  "Dbq=" & FileCSV.ParentFolder & ";" & _
	  "Extensions=asc,csv,tab,txt;" & _
	  "Persist Security Info=False"
	'
	'Create Record Set for reading CSV file content
	'
	 Set objRs = New ADODB.Recordset
	objRs.Open "Select * From " & FileCSV.Name, objConn, adOpenStatic, adLockReadOnly, adCmdText

	'
	'Transfer Records from from CSV file to Tem database
	'
	
	Dim objAccessRs As ADODB.Recordset
	Dim llngCounter As Long
	
	Set objAccessRs = New ADODB.Recordset
	
	llngCounter = 2
	
	Do While Not objRs.EOF
		If Trim(objRs("PersonID")) <> "" And IsNumeric(objRs("PersonID")) Then
			
			objAccessRs.Open "Select * from tblPerson Where PersonID = " & objRs("PersonID"), _
			mobjConn, 3, 3
			
			If Not objAccessRs.EOF Then
				'objAccessRs("PersonID") = Trim(objRs("PersonID"))
				objAccessRs("Prefix") = Trim(objRs("Prefix"))
				objAccessRs("LName") = Trim(objRs("LName"))
				objAccessRs("FName") = Trim(objRs("FName"))
				objAccessRs("MI") = Trim(objRs("MI"))
				objAccessRs("Title1") = Trim(objRs("Title1"))
				objAccessRs("Zip") = Trim(objRs("Zip"))
		   End If
		   objAccessRs.Close
		End If

		objRs.MoveNext
		llngCounter = llngCounter + 1
	Loop


Any help/suggestion is appreciated.

Thanks,
Dev

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > problem reading csv file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway