1
votes

I am new to vba7 on ms word 2010 on w8-32 bit.

I am trying to pass an integer var arrIndexMax to a subroutine. The subroutine reads from a file and stores in an array, so this arrIndexMax var is supposed to hold the maximum value of the index of the array so that I can later restrict array execution to this value. I want arrIndexMax to get modified to the last read value index by the subroutine, so I am passing it byref.

When I am passing like this, (relevant code is boldened)

Dim arrMaatraasCode
arrMaatraasCode = Array(2366, 2367, 2368, 2369, 2370, 2371, 2372, 2375, 2376, 2377, 2379, 2380, 2307, 2381)

Dim arrMaatraas(13) As String
strMaatraasAll = " "
For arrIndex = 0 To UBound(arrMaatraasCode)
    arrMaatraas(arrIndex) = ChrW(arrMaatraasCode(arrIndex))
    strMaatraasAll = strMaatraasAll & arrMaatraas(arrIndex) & " "
Next arrIndex

'four unused letters stored to separate actual letters that get combined, these are a of four languages
strFiller = ChrW(2437) & ChrW(2565) & ChrW(2693) & ChrW(2821)

Dim arrInCode(512) As Integer
Dim arrFromChar(512) As String
Dim arrToChar(512) As String
**arrIndexMax = -1**

ReadConversionTable arrInCode, arrFromChar, arrToChar, strMaatraasAll, strFiller, **arrIndexMax**

then there is other code.

and, the called subroutine declaration later on is

Sub ReadConversionTable(arrInCode() As Integer, arrFromChar() As String, arrToChar() As String, ByVal strMaatraasAll As String, ByVal strFiller As String, **ByRef arrIndexMax As Integer**)

--

however, it just gives "Type mismatch", or byref error, or other kinds of errors at the same place, for various values.

changing Integer to Long in called subroutine also doesn't help.

Whereas all sites are saying that this is correct method.

When I try to define arrIndexMax As Integer, it doesn't allow.

What I am missing?

1
those stars (* *) are put by the site when I try to "bolden" that part for easier understanding. Those are not in the code. Thanks. - VSRawat
"When I try to define arrIndexMax As Integer, it doesn't allow." can you be more specific about what happens when you try to do "Dim arrINdexMax As Integer" ? - user1379931
No, it is not an array, it is a single variable so I was not putting "Dim" there. That was it, causing error. - VSRawat

1 Answers

3
votes

The reason is that you have not declared variable arrIndexMax and it gets the default data type - Variant. And you cannot pass a variable of Variant type when Integer type is required.

All you have to do is to add this declaration at the top of your function:

Dim arrIndexMax As Integer