split string error in a compiled VB.NET class

Posted by Andy Payne on Stack Overflow See other posts from Stack Overflow or by Andy Payne
Published on 2010-04-01T17:45:38Z Indexed on 2010/04/01 17:53 UTC
Read the original article Hit count: 380

Filed under:
|

I'm having some trouble compiling some VB code I wrote to split a string based on a set of predefined delimeters (comma, semicolon, colon, etc). I have successfully written some code that can be loaded inside a custom VB component (I place this code inside a VB.NET component in a plug-in called Grasshopper) and everything works fine. For instance, let's say my incoming string is "123,456". When I feed this string into the VB code I wrote, I get a new list where the first value is "123" and the second value is "456".
However, I have been trying to compile this code into it's own class so I can load it inside Grasshopper separately from the standard VB component. When I try to compile this code, it isn't separating the string into a new list with two values. Instead, I get a message that says "System.String []". Do you guys see anything wrong in my compile code? You can find an screenshot image of my problem at the following link: click to see image

This is the VB code for the compiled class:

Public Class SplitString
Inherits GH_Component
Public Sub New()
    MyBase.New("Split String", "Split", "Splits a string based on delimeters", "FireFly", "Serial")
End Sub
Public Overrides ReadOnly Property ComponentGuid() As System.Guid
    Get
        Return New Guid("3205caae-03a8-409d-8778-6b0f8971df52")
    End Get
End Property
Protected Overrides ReadOnly Property Internal_Icon_24x24() As System.Drawing.Bitmap
    Get
        Return My.Resources.icon_splitstring
    End Get
End Property
Protected Overrides Sub RegisterInputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_InputParamManager)
    pManager.Register_StringParam("String", "S", "Incoming string separated by a delimeter like a comma, semi-colon, colon, or forward slash", False)
End Sub
Protected Overrides Sub RegisterOutputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_OutputParamManager)
    pManager.Register_StringParam("Tokenized Output", "O", "Tokenized Output")
End Sub
Protected Overrides Sub SolveInstance(ByVal DA As Grasshopper.Kernel.IGH_DataAccess)
    Dim myString As String
    DA.GetData(0, myString)

    myString = myString.Replace(",", "|")
    myString = myString.Replace(":", "|")
    myString = myString.Replace(";", "|")
    myString = myString.Replace("/", "|")
    myString = myString.Replace(")(", "|")
    myString = myString.Replace("(", String.Empty)
    myString = myString.Replace(")", String.Empty)

    Dim parts As String() = myString.Split("|"c)
    DA.SetData(0, parts)

End Sub

End Class

This is the custom VB code I created inside Grasshopper:

Private Sub RunScript(ByVal myString As String, ByRef A As Object)
myString = myString.Replace(",", "|")
myString = myString.Replace(":", "|")
myString = myString.Replace(";", "|")
myString = myString.Replace("/", "|")
myString = myString.Replace(")(", "|")
myString = myString.Replace("(", String.Empty)
myString = myString.Replace(")", String.Empty)

Dim parts As String() = myString.Split("|"c)
A = parts

End Sub

'

'

End Class

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about strings