1

i have this vb.net code that connects to our U2 database and gets data with a subroutine, when i display the data it's just one long string delimited by "|". I'm am trying to get each value and assign it variables so i can place them in textboxes but every time i try to split() or use a for loop statement i either get "string() cannot be converted to string" or just the last letter in the entire string.

this is the first way i tried pulling the string to see if splitting it would be easier:

Dim args As String = PKG_FUNCTION + "|" + PKG_SERVICE + "|" + PKG_NUMBER
        Dim Subr As UniSubroutine
        Dim value As String

        Subr = Sess.CreateUniSubroutine("SHIP_INFO_FROM_MACH", 5)
        With Subr
            .SetArg(0, args)
            .Call()

            value = (.GetArg(3))
            txtOutput.Text = value

        End With
        txtOutput.Text = value

    End Sub

this was the original way i tried it, using UniDynArray:

Dim args As String = PKG_FUNCTION + "|" + PKG_SERVICE + "|" + PKG_NUMBER
        Dim Subr As UniSubroutine
        Dim outArray As UniDynArray
        Dim inArray As UniDynArray
        Dim errorArray As UniDynArray

        Subr = Sess.CreateUniSubroutine("SHIP_INFO_FROM_MACH", 5)
        Subr.SetArg(0, args)

        Try
            Subr.Call()
        Catch Ex As Exception
            MsgBox("Error")
        End Try

        inArray = Subr.GetArgDynArray(0) 'Mach Input
        txtInput.Text = inArray.ToString()

        outArray = Subr.GetArgDynArray(3) 'Mach Output
        txtOutput.Text = outArray.ToString()

        errorArray = Subr.GetArgDynArray(4) 'Mach Error Output
        txtError.Text = errorArray.ToString()
        txtPackageID.SelectAll()

this is a for each function i tried that returns "string cannot be converted to string()" or "char() cannot be converted to integer"

Subr = Sess.CreateUniSubroutine("SHIP_INFO_FROM_MACH", 5)
        With Subr
            .SetArg(0, args)
            .Call()

            value = (.GetArg(3))
            Dim test As String() = value.Split(New Char)({"|"c})
            Dim word As String
            For Each word In test
                txtOutput.Text = word
            Next

        End With
        txtOutput.Text = value

    End Sub

with this i can pull any letter from the string by selecting it's space, for example: value(20) pulls the 20th letter but i still don't know how to separate by it's delimiter and pull each element.

Subr = Sess.CreateUniSubroutine("SHIP_INFO_FROM_MACH", 5)
With Subr
    .SetArg(0, args)
    .Call()

    value = (.GetArg(3))
    Dim first As New List(Of String) From {value(20)}
    For Each item As String In first
        txtOutput.Text = UCase(item)
    Next

End With
chris bahr
  • 155
  • 3
  • 15
  • It is a pity that you have an error on a piece of code that you haven't show us. Where is the loop that's failing? – Steve Aug 07 '15 at 16:06
  • these 2 are the snippets that return the full string. I have tried way to many methods that result in error so basically i'm just looking for other tips or answers for me to try again. Every method i have tried are not supported by UniDynArray or the string cannot be converted, which just means i'm doing it wrong completely – chris bahr Aug 07 '15 at 16:09
  • `string() cannot be converted to string` means that in that case you have a string array – Ňɏssa Pøngjǣrdenlarp Aug 07 '15 at 16:12
  • according to documentation it is a byte array but i have no idea how to "split" that. – chris bahr Aug 07 '15 at 16:14
  • It sounds like you're storing delimited data in a single database colulmn. That's pretty much _never_ a good idea. – Joel Coehoorn Aug 07 '15 at 19:51
  • I'm not storing it in the database, the subroutine pulls "name, address, zip code, etc." when you search by order number but it pulls all the information by default as a "|" delimited unidynarray (byte array). Now i just need to separate it. – chris bahr Aug 07 '15 at 20:00

1 Answers1

0

split with i = target value in the string

    outArray = Subr.GetArgDynArray(3)
    value = outArray.ToString()
    dim strSplit as String() = value.split("|")
    txtOutput.text = split(i).Trim()
chris bahr
  • 155
  • 3
  • 15