'VBA - How can i add value to a public array - compile Error
I add some values to my array and try to get it later in another method. Unfortunately i get an compline error for my array when i try to get the value.
The values for the array comes from my UserForm, where some checkboxes could be selected. While closing the UserForm a method runs and controlls which checkboxes are activated, if the checkbox value is true the name of the checkbox should be add to the array
'''ThisDocument Code
Public Processes As Variant 'This is the Array
Public numberOfProcesses As Integer
'''UserForm1 Code
public sub controllProcesses()
numberOfProcesses = 0
If cbLogin.Value = True Then
numberOfProcesses = numberOfProcesses + 1
ReDim Processes(numberOfProcesses)
Processes(numberOfProcesses - 1) = "Login"
End If
If cbRegistration.Value = True Then
numberOfProcesses = numberOfProcesses + 1
ReDim Processes(numberOfProcesses)
Processes(numberOfProcesses - 1) = "Registration"
End If
End Sub
'''Method to get value from array
Public Sub Examples()
Dim a As Integer
Dim b As Integer
b = 1
With Selection
For a = 0 To numberOfProcesses
.TypeText Text:=b & ". " & Processes(a) ' Here the compile error appears.
Next
End With
End Sub
From what I could find via my search, it should actually work like this, but I don't know what I'm doing wrong.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
