I've got a strange problem with a loop in VBA, as it seems to be losing the value of my variable. Any ideas why? If i delete the loop, debug.print shows "test", otherwise it's empty (unless I print the value of "dupa" inside the loop)... Seems very strange.
Function carbon_copy(indeks As String) As String
Dim emails(1 To 3) As String
Dim i As Integer
Dim dupa As String
emails(1) = "[email protected]"
emails(2) = "[email protected]"
emails(3) = "[email protected]"
i = 1
dupa = "test"
Do While emails(i) <> ""
If i = indeks Then
GoTo NextIteration
End If
dupa = dupa & ";" & emails(i)
NextIteration:
i = i + 1
Loop
Debug.Print dupa
carbon_copy = dupa
End Function
emails(4)with a value of""(and change toDim emails(1 To 4) As String)?On Error Resume Nextsomewhere in the code? Ignoring an error with that (such as trying to access an array element which doesn't exist) could give unexpected results.