# Use the array • ### Question

• Hi,

The Sub Tombmuvelet() I want to use the elements of the tomb() array.
I would like to specify the value of the elements of the array Function Tombfeltolt() in the procedure.

Sub Tombmuvelet()
Dim tomb(7)
Dim sz As Integer
Call Tombfeltolt
sz = tomb(1)
sz1=tomb(2)
sz2=tomb(3)
Range("A1").Select
End Sub
Function Tombfeltolt()
Dim i As Integer
For i = 0 To 6
tomb(i) = i + 2
Next i

End Function

Best regards,

Józsi

Saturday, December 7, 2019 5:42 AM

• Instead of using a function, you can pass the array to Tombfeltolt:

```Sub Tombmuvelet()
Dim tomb(6)
Dim sz As Integer, sz1 As Integer, sz2 As Integer
Call Tombfeltolt(tomb)
sz = tomb(1)
sz1 = tomb(2)
sz2 = tomb(3)
End Sub

Sub Tombfeltolt(tomb)
Dim i As Integer
For i = 0 To 6
tomb(i) = i + 2
Next i
End Sub```

Regards, Hans Vogelaar (http://www.eileenslounge.com)

• Marked as answer by Saturday, December 7, 2019 11:20 AM
Saturday, December 7, 2019 10:25 AM
• Hi,

I suppose you need to define tomb in Function Tombfeltolt, otherwise you need to
1) pass over tomb as an argument of Function Tombfeltolt or
2) define tomb(7) outside of Sub Tombmuvelet

1) argument or parameter
```Option ExplicitSub Tombmuvelet()
Dim tomb(7) As Integer
Dim sz As Integer
Call Tombfeltolt(tomb)
sz = tomb(1)
sz1 = tomb(2)
sz2 = tomb(3)
Range("A1").Select
End Sub

Function Tombfeltolt(ByRef tomb() As Integer)
Dim i As Integer
For i = 0 To 6
tomb(i) = i + 2
Next i
End Function```
2) variable outside of sub
```Option Explicit

Dim tomb(7) As Integer    ' --<< outside of sub

Sub Tombmuvelet()
Dim sz As Integer
Call Tombfeltolt(tomb)
sz = tomb(1)
sz1 = tomb(2)
sz2 = tomb(3)
Range("A1").Select
End Sub

Function Tombfeltolt()
Dim i As Integer
For i = 0 To 6
tomb(i) = i + 2
Next i
End Function```
Regards,

Ashidacchi -- http://hokusosha.com

• Edited by Saturday, December 7, 2019 10:31 AM
• Marked as answer by Saturday, December 7, 2019 11:20 AM
Saturday, December 7, 2019 10:30 AM

### All replies

• Instead of using a function, you can pass the array to Tombfeltolt:

```Sub Tombmuvelet()
Dim tomb(6)
Dim sz As Integer, sz1 As Integer, sz2 As Integer
Call Tombfeltolt(tomb)
sz = tomb(1)
sz1 = tomb(2)
sz2 = tomb(3)
End Sub

Sub Tombfeltolt(tomb)
Dim i As Integer
For i = 0 To 6
tomb(i) = i + 2
Next i
End Sub```

Regards, Hans Vogelaar (http://www.eileenslounge.com)

• Marked as answer by Saturday, December 7, 2019 11:20 AM
Saturday, December 7, 2019 10:25 AM
• Hi,

I suppose you need to define tomb in Function Tombfeltolt, otherwise you need to
1) pass over tomb as an argument of Function Tombfeltolt or
2) define tomb(7) outside of Sub Tombmuvelet

1) argument or parameter
```Option ExplicitSub Tombmuvelet()
Dim tomb(7) As Integer
Dim sz As Integer
Call Tombfeltolt(tomb)
sz = tomb(1)
sz1 = tomb(2)
sz2 = tomb(3)
Range("A1").Select
End Sub

Function Tombfeltolt(ByRef tomb() As Integer)
Dim i As Integer
For i = 0 To 6
tomb(i) = i + 2
Next i
End Function```
2) variable outside of sub
```Option Explicit

Dim tomb(7) As Integer    ' --<< outside of sub

Sub Tombmuvelet()
Dim sz As Integer
Call Tombfeltolt(tomb)
sz = tomb(1)
sz1 = tomb(2)
sz2 = tomb(3)
Range("A1").Select
End Sub

Function Tombfeltolt()
Dim i As Integer
For i = 0 To 6
tomb(i) = i + 2
Next i
End Function```
Regards,

Ashidacchi -- http://hokusosha.com

• Edited by Saturday, December 7, 2019 10:31 AM
• Marked as answer by Saturday, December 7, 2019 11:20 AM
Saturday, December 7, 2019 10:30 AM
• Hi,

The second varieble prints an error message.

Best regards,

Józsi

Saturday, December 7, 2019 11:29 AM
• Hi Józsi,

Sorry, I provide both code without executing it (only an idea on paper).
How about the first code? Did it work with no errors?

Regards,

Ashidacchi -- http://hokusosha.com

Saturday, December 7, 2019 11:35 AM