compile error: array or custom type expected

P

Pablo Cardellino

Hi,
I'm getting a compile error, array or custom type expected, at this sub:

---------------------------------------
Private Sub ignorarSempre_Click() ' this line appears highlighted and the
sub doesn't run
Dim arg(3) As Variant

arg(0) = termo.Text
arg(1) = "IGNORADO PERMANENTEMENTE"
arg(2) = "-1"
arg(3) = "1"

adDic (arg) ' this "arg" become selected when the error happens, so I
assume that here is the error
localizarTermo
completarForm
End Sub
---------------------------------------


This is the adDic function declaration, which is invoked at the error line:
---------------------------------------
Public Function adDic(args() As Variant) As Boolean
---------------------------------------

Note: the function IS working when invoked from another form. This is the
function (abbreviated, showing just the relevant lines):
---------------------------------------
Private Sub EditRegraProceder_Click()
Dim i As Integer
Dim regrasel As Boolean
Dim msg As VbMsgBoxResult
Dim gravacao As Boolean
Dim arg(3) As Variant
Dim regs() As Integer

' several lines supressed here

If regrasel = True Then
arg(0) = EditRegraAntiga
arg(1) = EditRegraNova


' lines supressed

If UBound(regs) = 0 Then
arg(2) = 0
ElseIf UBound(regs) = 1 Then
arg(2) = regs(0)
Else
arg(2) = ""
For i = 0 To UBound(regs)
If i < UBound(regs) Then arg(2) = arg(2) & regs(i)
If i < UBound(regs) - 1 Then arg(2) = arg(2) & "|"
Next i
End If

arg(3) = CInt(EditRegraExcecaoSim) * CInt(EditRegraExcecaoSim) '
isto tira o sinal de negativo


gravacao = nOrt.adDic(arg) ' this line is invoking the function, and
it runs OK

If gravacao Then Me.Hide Else MsgBox ("Houve um erro e não foi
possível gravar o termo no dicionário da aplicação")

End If

End Sub
 
J

Jay Freedman

Hi Pablo,

You've run into VBA's mostly nonsensical rules about when parentheses are
allowed and when they are forbidden. In the line where the error occurs, you can
either assign the result of the adDic function to a Boolean variable

Dim bDummy As Boolean
bDummy = adDic(arg)

or you can remove the parentheses and ignore the return value

adDic arg

Read http://www.word.mvps.org/FAQs/MacrosVBA/BracketsWithArgmnts.htm for more
description.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
P

Pablo Cardellino

Thanks, Jay,
I had already solved this by using your second suggestion, not with arg, but
with the arg elements separated by commas, and forgetting the arg array:

dDic termo.Text, novaForma.Text, reg, "1"

Thank you,

Pablo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top