Do not use on any
shared computer
August 29, 2008 06:27pm pdt
 
[x]
Attachment Details

CSV import going haywire

Tags: Lotus, Lotus Notes, R7, LotusScript
I have a script that has been running fine for a while importing a CSV file into a NotesDB.  When it gets to the value in the 3rd line of the file it throws off the rest of the import.  
I have included records before and after the problem one that import correctly.  I know notes is really picky about the delimiters, and I know the issue is related to the fact that unlike all the other rows formated like
$15.00
This row has a comma in the value and the then neccessary quotes around it.
"$1,936.00 "
There are 2 placeholders that the file needs after the the amount column, which I am not sure why, but when it hits the 3rd line the " end up in one placeholder, and the 2nd placeholder is not needed which throws off the rest of the import by one column.

I would rather not force the users to manually check for this issue and I cannot change how the file arrives as it comes from a vendor. (Can I just say how frustrating it is that vendors dont use Quote-comma as the standard!)

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
Dim session As New NotesSession
	Dim db As NotesDatabase
	Set db = session.CurrentDatabase
	'Set view = db.GetView("Process")
	'Dim dc As NotesDocumentCollection
	'Set dc = view.Getalldocumentsbykey("New")
	'Call dc.StampAll("Status", "Output")
	Dim uiws As New NotesUIWorkspace
	Dim fileCSV As Variant
	'Declare variables to hold data
	
	Dim counter As Integer
	Dim doc As NotesDocument
	counter =0
	'setup file number
	filenum% = Freefile()
	'Ask user for file location	
	fileCSV =  uiws.OpenFileDialog(False, "Choose the CSV file","*.txt" ,"c:\pub")
	'If the user chose a file then process
	If Not Isempty(fileCSV ) Then
		Open fileCSV(0) For Input As filenum%
		Do Until Eof(filenum%)
			'Read a line of data
			Input #filenum%, REF_NUM ,CUSTOMER_REF , CARD_TYPE , STATUS , AUTH_NO , REGISTER_DATE , REGISTER_TIME , EXPIRY_DATE ,  GATEWAY , MERCHANT_CODE , TAG  ,  AMOUNT , PLACEHOLDER, PLACEHOLDER2, CARD_NUM , TRANSACTION_NAME 
			
			
			
			'Check to see if there is still a header row
			If STATUS= "STATUS" Then 
				
			Else
				'Create Notes document and write values to it
				Set doc = db.CreateDocument
				
				
				With doc
					.form = "Person"
					
					.MERCHANT_CODE = MERCHANT_CODE
					.GATEWAY = GATEWAY
					OrderDate = Cdat(REGISTER_DATE+ " " +REGISTER_TIME)		
					
					Msgbox "You imported " & counter & " records."
					.OrderDate = OrderDate
					.TAG = TAG
					.AUTH_NO = 	AUTH_NO
					.STATUS = STATUS
					.TRANSACTION_NAME = TRANSACTION_NAME
					If Trim(TRANSACTION_NAME) = "Refund" Then
						.AMOUNTDUE = 0 - Cstr(Strright ( AMOUNT, "$"))
					Else						
						.AMOUNTDUE = Cstr(Strright ( AMOUNT, "$"))
					End If
					
					.CreditCardType = CARD_TYPE
					.CreditCard = CARD_NUM
					.ExpDate = EXPIRY_DATE
					.CreditCardComments = REF_NUM
					.Status = "New"
				End With
			'save document
				Call doc.save(False, False)
          'The next two lines of code call up the document again and force a refresh of all computed fields as well as any validations.  
          'Not quite how it is documented in help ...but it works.
				Call doc.computewithform(True,False)
				Call doc.save(True,False)
				counter = counter +1
			End If
		Loop
		Msgbox "You imported " & counter & " records."
Attachments:
 
Import csv file (change .txt to .csv on saving
 
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Software
Question Asked By: sreeser
Solution Provided By: Bill-Hanson
Participating Experts: 2
Solution Grade: A
Views: 44
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by fgrushevsky

Rank: Master

Expert Comment by fgrushevsky:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by sreeser
Author Comment by sreeser:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by fgrushevsky

Rank: Master

Expert Comment by fgrushevsky:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by Bill-Hanson

Rank: Wizard

Accepted Solution by Bill-Hanson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by sreeser
Author Comment by sreeser:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by sreeser
Author Comment by sreeser:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Bill-Hanson

Rank: Wizard

Expert Comment by Bill-Hanson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by sreeser
Author Comment by sreeser:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Bill-Hanson

Rank: Wizard

Expert Comment by Bill-Hanson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Bill-Hanson

Rank: Wizard

Expert Comment by Bill-Hanson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by sreeser
Author Comment by sreeser:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by sreeser
Author Comment by sreeser:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Bill-Hanson

Rank: Wizard

Expert Comment by Bill-Hanson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Bill-Hanson

Rank: Wizard

Expert Comment by Bill-Hanson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Bill-Hanson

Rank: Wizard

Expert Comment by Bill-Hanson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by sreeser
Author Comment by sreeser:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by sreeser
Author Comment by sreeser:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628