Using Input # to read CSV files

I am using the Input #filenum statement to read lines from a CSV file and assign them to variable names.

The line in LotusScript is as follows:

Input #filenum% var1, var2, …var22

This works OK if the line I am reading has values for all the variables, but if the line has a blank field (ie text1,text2,text4) then the statement seems to skip the blank entry and put “text4” into the feild that should be blank.

For example, if my CSV was two lines as below:

donald,duck,12345,dduck@gmail.com

mickey,mouse,,mmouse@gmail.com

and the code is:

Input #filenum% firstname, surname, phone, email

then the results would be…

Line 1

firstname = donald

surname = duck

phone = 12345

email = dduck@gmail.com

Line 2

firstname = mickey

surname = mouse

phone = mmouse@gmail.com

email = CRASH!!!

Anyone know a way round this?

Subject: Try this

Dim v(1 to 40) as string

In you loop use this code

lineinput #filenum%, in_hold

c1 =0

in_hold = in_hold & ", "



Do While in_hold<>" "

	c = InStr(in_hold,",")

	c1 = c1+1

	v(c1)= ""



	If c >1 Then

		v(c1) = Mid(in_hold,1,c-1)

	End If



	in_hold= Mid(in_hold,c+1)



	loop

if c1 <> 22 then 'cleanup array of not correct number of data on input line

for i1 = c1 + 1 to 22

v(i1)= “”

next i1

end if

End Sub

’ what you will now have in the array v is all of the parsed values and if one had a null it will be null

all of the values will be strings so when if you need to value its to a number just do as an example num = cint(v(what ever position in array))