In answer to your question:
I modified your code a little:
Code:
Sub tesst1()
Dim tglButtons As Variant
Dim fieldNames As Variant
Dim searchValue As Variant
Dim intI As Integer
tglButtons = Array("tglGermany", "tglFrance", "tglSRep")
fieldNames = Array("Country", "Country", "Occupation")
searchValue = Array("Germany", "France", "Sales Representative")
Dim ctl As Control
Debug.Print LBound(tglButtons)
Debug.Print UBound(tglButtons)
For intI = 1 To UBound(tglButtons)
If tglButtons(intI) = -1 Then ' I get the error on this line
Debug.Print (tglButtons(intI) & ", " & fieldNames(intI) & ", " & searchValue(intI))
End If
Next intI
End Sub
It executes, BUT.....
In your post, there is a missing double quote after tglSRep in the array tglButtons.
I added the blue lines:
the variable "intI" was not declared
The debug lines are to show the lower and upper limits of the array.
For the error (the IF statement), you cannot/should not use the brackets or the .Value property.
The debug statement within the IF() statement will never execute because the array has predefined text values and you are trying to compare the text value to -1 (True?).
Try running this code:
Code:
Sub ArrayTest1()
Dim tglButtons As Variant
Dim fieldNames As Variant
Dim searchValue As Variant
Dim intI As Integer
tglButtons = Array("tglGermany", "tglFrance", "tglSRep")
fieldNames = Array("Country", "Country", "Occupation")
searchValue = Array("Germany", "France", "Sales Representative")
Dim ctl As Control
Debug.Print "Lower bound = " & LBound(tglButtons)
Debug.Print "Upper bound = " & UBound(tglButtons)
For intI = 1 To UBound(tglButtons)
Debug.Print "Counter = " & intI
Debug.Print "tglButtons Array value " & intI & " = " & tglButtons(intI)
If tglButtons(intI) = -1 Then ' I get the error on this line
Debug.Print (tglButtons(intI) & ", " & fieldNames(intI) & ", " & searchValue(intI))
End If
Next intI
End Sub
Edit: Our posts crossed. Perhaps you can explain what you are trying to do.