String Arrays
-
How do I return an array of strings from a function? Just like the way String.Split does?
-
How do I return an array of strings from a function? Just like the way String.Split does?
Try returning the array as Variant (in VB6) or Object (in VB.NET)
-
Try returning the array as Variant (in VB6) or Object (in VB.NET)
I can't do that. My development environment is such that Option Strict is On. I have to explicitly convert my array to a array of strings. Any other way?
-
How do I return an array of strings from a function? Just like the way String.Split does?
Hi Beowulf! How do I return an array of strings from a function? Just like the way String.Split does? Take a close look at the VB.NET declaration of
Split
[^]. It's got brackets after its type. All you have to do in the function is to create an array of the appropriate type and size and finally use a reference to it as the function's return value. For example:Option Explicit On
Option Strict OnPublic Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
For Each str As String In TestFunction()
MessageBox.Show(str)
Next
End SubPrivate Function TestFunction() As String() Dim ReturnArray(1) As String ReturnArray(0) = "TestString" ReturnArray(1) = "Another String" TestFunction = ReturnArray End Function
End Class
Best regards Dennis