Just trying to reinforce what I'm learning here about a Function returning an array. I still think I need some advice. What I want to do is to pass a string to the function which will parse it into it's parts and assemble it into an array. If I can get this to work it will be one less temporary text file I need to write.
Here is what I have so far but I don't understand the error I'm getting shown in red.
Code:Option Strict On Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim vWord() As String Dim Message As String = "id=7-1234567890&" & _ "field1=40&" & _ "field2=43&" & _ "field3=0&" & _ "field4=0&" & _ "field5=0&" & _ "field6=0&" & _ "field7=0&" & _ "field8=0&" & _ "field9=300&" & _ "field10=0&" & _ "field11=0&" & _ "field12=1&" & _ "field13=1&" & _ "field14=1&" & _ "field15=0" Message = Mid(Message, InStr(Message, "id=")) vWord = CType(Doit(Message), String()) For i As Integer = 0 To vWord.Length - 1 TextBox1.Text = TextBox1.Text & vWord(i) & vbCrLf Next End Sub Private Function Doit(ByVal Message As String) As Array Dim words As String() = Message.Split(CChar("&")) Dim word As String Dim vWord() As String = Nothing Dim count As Integer For Each word In words vWord(count) = (word.Substring(InStr(word, "="))) <<--Object reference not set to an instance of an object. count = count + 1 Next Return vWord End Function End Class




Reply With Quote