Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I'm using the new TextFieldParser class and want to find out how to use the "Find" method of the Array object after I parse multiple fields of a line into a string array.

Here is the code:

Private Sub ParseData2()

       Dim fields As String()
       Dim parser As New TextFieldParser("c:\epp\test.txt")

       Try
           parser.SetDelimiters(";")
           parser.TrimWhiteSpace = True
           While Not parser.EndOfData
               ' Read in the fields for the current line
               fields = parser.ReadFields()
               Dim str As String = Array.Find(fields, AddressOf ProductGT11)
           End While
       Catch ex As Exception
           Throw ex
       End Try

   End Sub

   Private Shared Function ProductGT11(ByVal p As String()) As Boolean
      'code here will do the find
   End Function

 

The "AddressOf ProductGT11" inside the ParseData2 sub is giving me a compile time error:

Method 'Private Shared Function ProductGT11(p() as string) as Boolean does not have the same signature as delegate 'Delegate Function Predicate(Of T)(obj as String) As Boolean

 

How can I correct his?

Edited by PlausiblyDamp

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

  • *Experts*
Posted

The function ProductGT11 should take a single parameter that matches the type of the array - in your case a string. So the definition should be:

Private Shared Function ProductGT11(ByVal p As String) As Boolean

 

I just removed the parens from the parameter "p".

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
Thanks, that was it!

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...