vb.netu2

Selecting values from a string to assign variables in vb.net


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

Solution

  • 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()