Novice Question: csv file parsing 
Author Message
 Novice Question: csv file parsing

Hey.  Any help or code examples would be greatly appreciated.

I'm using LINE INPUT to read in a single line from a *.csv file.  The number
of fields vary by line; all fields are separated by a comma; the end of the
line is noted with a forward slash.

What I'd like to do is:

1.    Grab the first line
2.    Evaluate the first two characters of the string (the first field, a
2-digit number describing a transaction)
3.    CASE that field
4.    After CASE, grab the NEXT line until EOF.

Example:

*.csv file, line 1:    01,991030,991029,123456

After parsing line one, display in new textbox:

Type:        01
Date:        991030
Effective:  991029
Amount:   123456

I can do the formatting for dates and currency, and write the output file.
I just am uncertain how to break apart each csv value for evaluation.  Any
and all assistance would again be appreciated.  Email:

Thanks!
R



Wed, 17 Apr 2002 03:00:00 GMT  
 Novice Question: csv file parsing
Not sure if this is what you're after but...

Dim strText, MyVar As String
Open "D:\myfile.ini" For Input As #1
While Not EOF(1)
Line Input #1, strText
   MyVar = Mid(strText, 1, 2)
   Select Case MyVar
      Case Is = "blah"
         PerformAction ' do something if this condition is true
      Case Is = "boo"
         PerformAnother
    End Select
Wend

Use mid to evaluate a group of characters and if you insist on using the
comma try this;

...
Line Input #1, strText
  MyVar = Mid(strText,1,(instr(strText,",")-1))
...

I DID NOT compile this code, but I thought it looked syntactically correct.

Hope this helps or at least sparks a few other ideas.

Good Luck,

Steve

Quote:

>Hey.  Any help or code examples would be greatly appreciated.

>I'm using LINE INPUT to read in a single line from a *.csv file.  The
number
>of fields vary by line; all fields are separated by a comma; the end of the
>line is noted with a forward slash.

>What I'd like to do is:

>1.    Grab the first line
>2.    Evaluate the first two characters of the string (the first field, a
>2-digit number describing a transaction)
>3.    CASE that field
>4.    After CASE, grab the NEXT line until EOF.

>Example:

>*.csv file, line 1:    01,991030,991029,123456

>After parsing line one, display in new textbox:

>Type:        01
>Date:        991030
>Effective:  991029
>Amount:   123456

>I can do the formatting for dates and currency, and write the output file.
>I just am uncertain how to break apart each csv value for evaluation.  Any
>and all assistance would again be appreciated.  Email:

>Thanks!
>R



Wed, 17 Apr 2002 03:00:00 GMT  
 Novice Question: csv file parsing
I do this with a function like this:

Function NextCSVParam(s as string)as string

    Dim i as Integer
    Dim strParam as String

    i = Instr(s, ",")
    If i > 0 then

        strParam = Left(s, i-1)
        s = Mid(s, i+1)
        NextCSVParam = strParam

    Else

        NextCSVParam=""

    End If

End Function

In your case the returned parameter is the forward slash when the line is
done.


Quote:
> Hey.  Any help or code examples would be greatly appreciated.

> I'm using LINE INPUT to read in a single line from a *.csv file.  The
number
> of fields vary by line; all fields are separated by a comma; the end of
the
> line is noted with a forward slash.

> What I'd like to do is:

> 1.    Grab the first line
> 2.    Evaluate the first two characters of the string (the first field, a
> 2-digit number describing a transaction)
> 3.    CASE that field
> 4.    After CASE, grab the NEXT line until EOF.

> Example:

> *.csv file, line 1:    01,991030,991029,123456

> After parsing line one, display in new textbox:

> Type:        01
> Date:        991030
> Effective:  991029
> Amount:   123456

> I can do the formatting for dates and currency, and write the output file.
> I just am uncertain how to break apart each csv value for evaluation.  Any
> and all assistance would again be appreciated.  Email:

> Thanks!
> R



Thu, 18 Apr 2002 02:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. help needed parsing csv file

2. newbie needs help parsing csv file

3. Parsing a csv file

4. Parsing CSV file

5. Script to parse Outlook survey results to a .CSV file

6. help for novice please - parsing a string

7. Need Regexp pattern to parse csv

8. Parsing a csv record - What is the quickest method

9. Question: Populate a treeview with paths from a CSV file

10. basic question about parsing text files

11. PARSING question -delimiting files with something other than a comma

12. Newbie File Parsing Question

 

 
Powered by phpBB® Forum Software