0

I want to declare a dynamic string array, then make calls to each of the other procedures. This is what I have, I thought it would work but I keep getting errors.

Option Explicit

Sub Main()

   Public ListArr() As String

   Application.Run "Get_Input_List"

End Sub

Function Get_Input_List(ByRef ListArr() As String) As String

   Dim list As String
   Dim MesBox As String

  list = InputBox("Please enters word to sort using a comma with no space to separate", "Words")

  ListArr = Split(list, ",")

  MsgBox ListArr(1)

End Function

1 Answer 1

1

A couple issues here. First, Public can only be used as an access modifier for Module level variables - not local ones, so it should be Dim ListArr() As String. Second, you don't need to use Application.Run to call procedures in the same project. If you did, you aren't passing the required parameter (which can't be passed ByRef via Application.Run anyway). Third, Get_Input_List is a function, so you should probably return the result of the Split. Right now it always returns vbNullString. I'm guessing that you're looking for something more like this:

Option Explicit

Sub Main()
   Dim ListArr() As String
   ListArr = Get_Input_List

   Dim inputWord As Variant
   For Each inputWord In ListArr
        MsgBox inputWord
   Next
End Sub

Function Get_Input_List() As String()
    Dim list As String

    list = InputBox("Please enter words to sort separated with a comma and no spaces", "Words")
    Get_Input_List = Split(list, ",")
End Function
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.