0

I have created and array which will store the value of the inputbox, it is saying i have a syntax error and i am unsure how to fix it.

I have used parameter passing which i will display below also

Dim name() As String

For counter = 1 To 5
Call enter_questionnaire_data(name())    '2.0
Next
End sub

2nd sub-routine

Private Sub enter_questionnaire_data(ByRef name())

name() = InputBox("Enter the party name")

3 Answers 3

4

why do you have name as a String array?

you just need to declare

Dim name As String

for allowing name to store a String

also you cannot assign values to array members like this

name() = InputBox("Enter the party name")

you need to specify the index also

EDIT: if you want string array to store the names, then

declare a static array of sufficient length

Dim name(10) As String

and use:

name(index) = InputBox("Enter the party name")
index = index+1;

where the index is incremented after every input till 10

(using dynamic array would be a bit complicated for you right now , so i am omitting dynamic array from discussion)

Sign up to request clarification or add additional context in comments.

3 Comments

I need to use an array because the party name will be entered multiple times so i need an array to store the data for 'name'. How can i do this?
i have edited my answer to include your requirement. also you might like to check this link out for arrays patorjk.com/programming/tutorials/vbarrays.htm
The EDIT portion of your answer is a good solution. He should remember to call the sub with this line Call enter_questionnaire_data(name), noting the lack of parentheses on name.
2

Use name without brackets

Dim name As String

and in other method

Private Sub enter_questionnaire_data(ByRef name)
name = InputBox("Enter the party name")

1 Comment

He is calling enter_questionnaire_data inside a for loop. You can see that the functionality of the code is to input multiple names, hence the use of an array.
0

About your program:

Dim name As String <---Without () you can use this for array 

For counter = 1 To 5
Call enter_questionnaire_data(name as string)<--- can you insert  variable/tipe
Next

End sub


Private Sub enter_questionnaire_data(name as string)

name = InputBox("Enter the party name") 

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.