从字符串中选择值以在vb.net中分配变量

时间:2015-08-07 15:56:05

标签: vb.net u2

我有这个vb.net代码连接到我们的U2数据库并使用子程序获取数据,当我显示数据时,它只是一个由“|”分隔的长字符串。我正在尝试获取每个值并为其分配变量,因此我可以将它们放在文本框中,但每次我尝试split()或使用for循环语句时,我或者得到“string()不能转换为字符串”或者只是整个字符串中的最后一个字母。

这是我尝试拉弦的第一种方式,看看是否更容易拆分:

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

这是我尝试使用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()

这是我试过的每个函数返回“字符串无法转换为字符串()”或“char()无法转换为整数”

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

有了这个,我可以通过选择它的空格来拉取字符串中的任何字母,例如:value(20)拉出第20个字母,但我仍然不知道如何用它的分隔符分隔并拉出每个元素。

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

1 个答案:

答案 0 :(得分:0)

在字符串

中使用i =目标值进行拆分
    outArray = Subr.GetArgDynArray(3)
    value = outArray.ToString()
    dim strSplit as String() = value.split("|")
    txtOutput.text = split(i).Trim()