M melliott Member Licensed User Longtime User Apr 21, 2015 #1 Hello, Can someone please post a snippet of a user defined Sub with a parameter as a List or an Array of string values. I want to pass something like this: MySub("A,B,C") Then loop through the values in the Sub. Thanks for your help, Michael
Hello, Can someone please post a snippet of a user defined Sub with a parameter as a List or an Array of string values. I want to pass something like this: MySub("A,B,C") Then loop through the values in the Sub. Thanks for your help, Michael
M melliott Member Licensed User Longtime User Apr 21, 2015 #2 I think I answered my own question. Pass it as a string then convert the string to an array in your sub. DoThis("A,B,C") Code: Copy Sub DoThis(sMyStringList as String) Dim aNames() As String = Regex.Split(",", sMyStringList) for i = 0 to aNames.Length-1 log(aNames(i)) next End Sub Upvote 0
I think I answered my own question. Pass it as a string then convert the string to an array in your sub. DoThis("A,B,C") Code: Copy Sub DoThis(sMyStringList as String) Dim aNames() As String = Regex.Split(",", sMyStringList) for i = 0 to aNames.Length-1 log(aNames(i)) next End Sub
rwblinn Well-Known Member Licensed User Longtime User Apr 21, 2015 #3 Hi, two solutions --- might be other as well Option 1 Code: Copy Sub AppStart (Form1 As Form, Args() As String) ... MySub("A,B,C") Sub MySub(s As String) Dim sl() As String = Regex.Split(",", s) For i = 0 To sl.Length - 1 Log(sl(i)) Next End Sub Option 2 Code: Copy Sub Process_Globals Private MyList As List .. Sub AppStart (Form1 As Form, Args() As String) ... MyList.Initialize MyList.AddAll(Array As String("A", "B", "C")) MySub(MyList) ... Sub MySub(l As List) For i = 0 To l.Size - 1 Log(l.Get(i)) Next End Sub Upvote 0
Hi, two solutions --- might be other as well Option 1 Code: Copy Sub AppStart (Form1 As Form, Args() As String) ... MySub("A,B,C") Sub MySub(s As String) Dim sl() As String = Regex.Split(",", s) For i = 0 To sl.Length - 1 Log(sl(i)) Next End Sub Option 2 Code: Copy Sub Process_Globals Private MyList As List .. Sub AppStart (Form1 As Form, Args() As String) ... MyList.Initialize MyList.AddAll(Array As String("A", "B", "C")) MySub(MyList) ... Sub MySub(l As List) For i = 0 To l.Size - 1 Log(l.Get(i)) Next End Sub
M melliott Member Licensed User Longtime User Apr 21, 2015 #4 Rob thanks for posting. The List option looks very useful. Maybe even simpler. Upvote 0
Daestrum Expert Licensed User Longtime User Apr 22, 2015 #5 Minor improvement to list sub can be written as Code: Copy Sub MySub(l as List) For Each s as String In l log(s) Next End Sub Upvote 0
Minor improvement to list sub can be written as Code: Copy Sub MySub(l as List) For Each s as String In l log(s) Next End Sub