Check length for each record for a delimited file

I

Ixtreme

I need a code to check each record's length. My file is a ~ delimited file.My database has 60 fields. I need something that steps to each record and counts the fields for each record. If the record is less or more than 60 fields, I need them to be listed in a text file or msgbox.
 
J

John W. Vinson

I need a code to check each record's length. My file is a ~ delimited file. My database has 60 fields. I need something that steps to each record and counts the fields for each record. If the record is less or more than 60 fields, I need them to be listed in a text file or msgbox.

If you read the record into a String variable strRecord you can count the
delimiters with an expression like:

FieldCount = Len(strRecord) - Len(Replace(strRecord, "~", ""))
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
D

Douglas J Steele

Or you could use UBound(Split(strRecord, "~")) + 1.

"John W. Vinson" wrote in message

I need a code to check each record's length. My file is a ~ delimited file.
My database has 60 fields. I need something that steps to each record and
counts the fields for each record. If the record is less or more than 60
fields, I need them to be listed in a text file or msgbox.

If you read the record into a String variable strRecord you can count the
delimiters with an expression like:

FieldCount = Len(strRecord) - Len(Replace(strRecord, "~", ""))
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
G

Gloops

Ixtreme wrote, on Oct. 01st 2012 14:47 :
I need a code to check each record's length. My file is a ~ delimited file. My database has 60 fields. I need something that steps to each record and counts the fields for each record. If the record is less or more than 60 fields, I need them to be listed in a text file or msgbox.

Hello,

Here is another solution to count the fields :

Set S = Split(strRecord, "~")
'not sure about needing Set

FieldCount = UBound(S)

For N = LBound(S) to UBound(S)
Debug.Print N & " : " & "«" & S(N) & "»"
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top